Netatmo Wetterstation (incl. CO2 Messung) einbinden

Problemlösungen und Hinweise von allgemeinem Interesse zur Haussteuerung mit HomeMatic

Moderator: Co-Administratoren

Benutzeravatar
ecky78
Beiträge: 87
Registriert: 03.06.2016, 21:55

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von ecky78 » 11.03.2019, 14:22

Hallo,

just wegen dieser Frage schau' ich auch grade rein ... weiß jemand, ob die Vorhersagewerte auch in der API-Antwort drin sind?
Grüße,
Ecky

Indigo
Beiträge: 355
Registriert: 10.02.2015, 20:32

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von Indigo » 12.03.2019, 08:34

Hallo,

Die API kann zwar mittlerweile mehr als in diesem Script genutzt wird, dafür müsste man aber fast alles umbauen und eine Vorhersage ist garnicht vorgesehen und möglich.

Benutzeravatar
ecky78
Beiträge: 87
Registriert: 03.06.2016, 21:55

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von ecky78 » 12.03.2019, 08:49

Hallo,

Die offizielle App von Netatmo und auch die MyNetatmo-Seite geben eine (wenn auch ziemlich knappe) Vorhersage raus, die Netatmo wahrscheinlich von irgendwo zukauft:
NA.jpg
Screenshot vom 12.3.2019
NA.jpg (17.02 KiB) 462 mal betrachtet

Ist halt die Frage, inwieweit diese Werte evtl. auch über die API rausgegeben werden.
Grüße,
Ecky

deifel
Beiträge: 155
Registriert: 27.05.2014, 11:10

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von deifel » 12.03.2019, 16:11

Hallo zusammen,

ich nutze seit einigen Wochen meine Netatmo Wetterstation mit dem Script von hier und es hat bis heute alles einwandfrei funktioniert.
Jetzt habe ich auf der CCU eine "Gerätekommunikation gestört"- Meldung - jeweils eine für den Innensensor als auch eine für den Außensensor.
Kann mir jemand sagen, woher das kommen kann bzw. wie ich dem Problem auf die Spur kommen kann?
Hat jemand ähnliche Probleme?
Das Script scheint problemlos zu laufen und liefert auch Werte zurück...

Danke im Voraus
Frank

blackbasket
Beiträge: 65
Registriert: 13.07.2018, 13:19

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von blackbasket » 19.03.2019, 14:33

Hallo Frank,

hast du noch andere Geräte in CUXD laufen? Funktionieren diese noch?

LG,
Marcel

Chrisrookie
Beiträge: 5
Registriert: 08.05.2019, 00:34

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von Chrisrookie » 08.05.2019, 01:13

Hallo liebe Homematic Gemeinde!

Als Neuling, im Forum, möcht ich mich natürlich vorab bedanken, für die zahlreichen Anleitungen, die mich erfolgreich durch das Thema, "Netatmo Daten auf CCU einspielen", geleitet haben. Und ein HALLO durch die Runde schicken :mrgreen:

Ich habe ein Aussenmodul, Regensensor und Windsensor, die die Daten verlässlich an die CCU(3) abliefern. Funktioniert bereits sein einigen Wochen.

Jetzt zu meinem Problem... Seit 2 Tagen spiele ich mich mit zwei zusätzlichen Innenmodulen. Habe das Script dazu in meinem leienhaften Verständnis
(und mit abschauen :mrgreen: ), um meine Daten ergänzt. Zusätzlich 2 Systemvariablen angelegt und natürlich 2 neue Module über CuX-Daemon.
Alles wie schon beim ersten Mal.

Aber die CCU holt die Messdaten einfach nicht ab. Bei den, vor Tagen angelegten Modulen (Aussen, Regen, Wind) klappt es allerdings noch immer.
Nur die 2 neuen stehen auf null.

Code: Alles auswählen

tclsh /usr/local/addons/netatmo/netatmo.tcl
Bei dieser Abfrage bekomme ich jedoch alle Werte korrekt angezeigt. Auch die 2 neuen Module.
Ich hab auch die 2 Sensoren von der CCU gelöscht und über Cux neu angelegt, mit der selben Seriennummer... dies blieb leider ebenfalls ohne Erfolg.

Was könnte ich denn noch versuchen? Das Programm für die Sync. wurde nicht abgeändert.

Besten Dank schon Mal für Eure Ideen.

BG Chris

Indigo
Beiträge: 355
Registriert: 10.02.2015, 20:32

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von Indigo » 08.05.2019, 07:36

Hallo,

poste doch mal dein Script. Ohne Benutzernamen und Passwort. Es scheint ja nur eine Kleinigkeit zu sein.
Wenn du es gestern (am 7.5.) probiert hast kann es auch an den mal wieder vorhandenen NetAtmo Serverproblemen gelegen haben.

Chrisrookie
Beiträge: 5
Registriert: 08.05.2019, 00:34

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von Chrisrookie » 08.05.2019, 08:26

Code: Alles auswählen

#!/bin/tclsh

    load tclrega.so

    #---------------------------------------------------------------------------------------------------------------#
    #                                                   CONFIG                                                      #
    #---------------------------------------------------------------------------------------------------------------#
    #  to obtain your own client ID and API key please register a new app here: http://dev.netatmo.com/dev/listapps
    set clientId "xxx"                     
    set clientSecret "xxx"
    #  the following are your normal netatmo credentials (the ones you used to setup your netatmo weather station)
    set username "xxx"
    set password "xxx"
    #  the following are MAC addresses of your indoor station and the outside module and rain module
    set deviceid "70:ee:50:xxx"
    set moduleid "02:00:00:xxx"
    set rainid "05:00:00:xxx"
    set windid "06:00:00:xxx"
    # Zusatz-Modul Innen 1
    set szid1 "03:00:00:xxx"
    # Zusatz-Modul Innen 2
    set szid2 "03:00:00:xxx"

     set ::env(LD_LIBRARY_PATH) "/usr/local/addons/cuxd"
    set cfgfile "/tmp/netatmo.dat"
    set logtag "netatmo.tcl"
    set logfacility "local1"
    # 0=panic, 1=alert 2=crit 3=err 4=warn 5=notice 6=info 7=debug
    set loglevel 7
    #---------------------------------------------------------------------------------------------------------------#

    #---------------------------------------------------------------------------------------------------------------#
    #                                              GLOBAL VARIABLES                                                 #
    #---------------------------------------------------------------------------------------------------------------#
    set accesstoken ""
    set refreshtoken ""
    set tokenexpires 0
    #---------------------------------------------------------------------------------------------------------------#


    set loglevels {panic alert crit err warn notice info debug}

    proc log {lvl msg} {
        global logtag
        global logfacility
        global loglevel
        global loglevels
       
        set lvlnum [lsearch $loglevels $lvl]
       
        if {$lvlnum <= $loglevel} {
            if {$lvlnum <= 3} {
                catch {exec logger -s -t $logtag -p $logfacility.$lvl $msg}
            } else {
                puts "$lvl: $msg"
                catch {exec logger -t $logtag -p $logfacility.$lvl $msg}
            }
           
        }
       
    }

    proc refreshToken {rt ci cs} {
        log debug "refreshing token"
        set url "https://api.netatmo.net/oauth2/token"
        set header "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
        set parameter "grant_type=refresh_token&refresh_token=$rt&client_id=$ci&client_secret=$cs"

        catch {exec /usr/local/addons/cuxd/curl -k -i -H $header -X POST -d $parameter $url} response
        log debug "response was $response"
       
        return $response

    }

    proc requestToken {ci cs un pw} {
        log "debug" "requesting new token"
        set url "https://api.netatmo.net/oauth2/token"
        set header "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
        set parameter "grant_type=password&client_id=$ci&client_secret=$cs&username=$un&password=$pw"

        catch {exec /usr/local/addons/cuxd/curl -k -i -H $header -X POST -d $parameter $url} response
        log debug "response was $response"
       
        return $response

    }

    proc parseOAuthResponse {input} {
        log debug "parsing authentication result"
        global accesstoken
        global refreshtoken
       
        regexp {HTTP/1.1\s(\d*)} $input dummy returncode
        regexp {\"access_token\":\"(.*?)\"} $input dummy accesstoken
        regexp {\"refresh_token\":\"(.*?)\"} $input dummy refreshtoken
        regexp {\"expires_in\":(.*?)\,} $input dummy expiresin

        log debug "returncode is $returncode"
        log debug "access token is $accesstoken"
        log debug "refresh token is $refreshtoken"
        log debug "expires in $expiresin"
       
        if {[expr $returncode]!=200} {
                log error "Authentication failed with code $returncode and response $input"
                exit 1
            }
       
        return $expiresin
    }

    proc saveAccessToken {expin} {
        global accesstoken
        global refreshtoken
        global tokenexpires
        global cfgfile
           
        log debug "saving new access token to $cfgfile"
       
        set fileId [open $cfgfile "w"]
       
        set now [clock seconds]
        set tokenexpires [expr $now + $expin]
       
        puts $fileId $accesstoken
        puts $fileId $refreshtoken
        puts $fileId $tokenexpires
        close $fileId
    }

    proc loadAccessToken {} {
        global accesstoken
        global refreshtoken
        global tokenexpires
        global cfgfile
       
        log debug "loading stored credentials from $cfgfile"
       
        set fp [open $cfgfile r]
        set file_data [read $fp]
        close $fp
       
        log debug "file data is: $file_data"
       
        set data [split $file_data "\n"]   
       
        set accesstoken [lindex $data 0]
        set refreshtoken [lindex $data 1]
        set tokenexpires [lindex $data 2]
    }

    log debug "script has started"

    if { [file exists $cfgfile] == 1} {
        log info "found stored credentials"
            loadAccessToken
            set now [clock seconds]
            log debug "current time is [clock format $now -format "%Y-%m-%dT%H:%M:%S"], token is valid until [clock format $tokenexpires -format "%Y-%m-%dT%H:%M:%S"]"
            if {[expr $now >= $tokenexpires] == 1} {
                log notice "token has already expired"
                saveAccessToken [parseOAuthResponse [refreshToken $refreshtoken $clientId $clientSecret]]
                log notice "oauth token successfully refreshed"
            } else {
                log info "token is still valid" ; log info ""
            }
        } else {
            log warn "no stored credentials found"
            saveAccessToken [parseOAuthResponse [requestToken $clientId $clientSecret $username $password]]
            log notice "oauth token successfully initialized"
        }


    log debug "polling outdoor module..."
    set url "https://api.netatmo.net/api/getmeasure?access_token=$accesstoken&device_id=$deviceid&module_id=$moduleid&scale=max&type=Temperature,Humidity&date_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"

    regexp {\"value\":\[\[(.*?),(.*?)\]} $response dummy otemp ohum

    log info "Outside temperature is $otemp"
    log info "Outside humidity is $ohum"

    log debug "polling main module..."
    set url "https://api.netatmo.net/api/getmeasure?access_token=$accesstoken&device_id=$deviceid&scale=max&type=Temperature,Humidity,CO2,Pressure,Noise&date_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"

    regexp {\"value\":\[\[(.*?),(.*?),(.*?),(.*?),(.*?)\]} $response dummy itemp ihum ico2 ipressure inoise
    
    log info "LogI is $response"              
    log info "Inside temperature is $itemp"
    log info "Inside humidity is $ihum"
    log info "Inside CO2 level $ico2"
    log info "Inside pressure is $ipressure"
    log info "Inside noise level is $inoise"

    log debug "polling regensensor module...1d"
    set url "https://api.netatmo.net/api/getmeasure?access_token=$accesstoken&device_id=$deviceid&module_id=$rainid&scale=1day&type=sum_rain&date_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"

    regexp {\"value\":\[\[(.*?)\]} $response dummy rain1d
    
    log info "LogR is $response"                
    log info "Outside Regen1d is $rain1d"

    log debug "polling regensensor module...30min"
    set url "https://api.netatmo.net/api/getmeasure?access_token=$accesstoken&device_id=$deviceid&module_id=$rainid&scale=30min&type=Rain,sum_rain&date_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"

    regexp {\"value\":\[\[(.*?),(.*?)\]} $response dummy rain2 rain30min
    
    log info "LogR is $response"                
    log info "Outside rain2 is $rain2"
    log info "Outside Regen30min is $rain30min"

    log debug "polling wind module..."
    set url "https://api.netatmo.net/api/getmeasure?access_token=$accesstoken&device_id=$deviceid&module_id=$windid&scale=max&type=WindAngle,WindStrength,GustAngle,GustStrength&date_end=last"
   log debug "quering $url"
   catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
   log debug "respnose is $response"

   regexp {\"value\":\[\[(.*?),(.*?),(.*?),(.*?)\]} $response dummy windangle windstrength gustangle guststrength
   log info "WindAngle is $windangle"
   log info "Windstrength is $windstrength"
   log info "GustAngle is $gustangle"
   log info "Guststrength is $guststrength"

     log debug "polling Inside module 1 ..."
    set url "https://api.netatmo.net/api/getmeasure?access_token=$accesstoken&device_id=$deviceid&module_id=$szid1&scale=max&type=Temperature,Humidity,CO2&date_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"
    regexp {\"value\":\[\[(.*?),(.*?),(.*?)\]} $response dummy ztemp1 zhum1 zco21
    log info "LogI is $response"             
    log info "Inside module 1 temperature is $ztemp1"
    log info "Inside module 1 humidity is $zhum1"
    log info "Inside module 1 CO2 level $zco21"
    log info ""
    
    
    log debug "polling Inside module 2 ..."
    set url "https://api.netatmo.net/api/getmeasure?access_token=$accesstoken&device_id=$deviceid&module_id=$szid2&scale=max&type=Temperature,Humidity,CO2&date_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"
    regexp {\"value\":\[\[(.*?),(.*?),(.*?)\]} $response dummy ztemp2 zhum2 zco22
    log info "LogI is $response"             
    log info "Inside module 2 temperature is $ztemp2"
    log info "Inside module 2 humidity is $zhum2"
    log info "Inside module 2 CO2 level $zco22"
    log info ""


    #
    # set ReGaHss variables
    #
    set rega_cmd ""
    append rega_cmd "var ITemp = dom.GetObject('CUxD.CUX9002001:1.SET_TEMPERATURE');"
    append rega_cmd "var IHumi = dom.GetObject('CUxD.CUX9002001:1.SET_HUMIDITY');"
    append rega_cmd "var OTemp = dom.GetObject('CUxD.CUX9002002:1.SET_TEMPERATURE');"
    append rega_cmd "var OHumi = dom.GetObject('CUxD.CUX9002002:1.SET_HUMIDITY');"
    append rega_cmd "var Rain1 = dom.GetObject('Regenmenge_30min');"
    append rega_cmd "var Rain2 = dom.GetObject('Regenmenge_1d');"
    append rega_cmd "var Rain3 = dom.GetObject('Regen_aktuell');"
    append rega_cmd "var IPress = dom.GetObject('Luftdruck');"
    append rega_cmd "var ICO2 = dom.GetObject('CO2');"
    append rega_cmd "var INoise = dom.GetObject('Sonometer');"
    append rega_cmd "var windA = dom.GetObject('Windrichtung');"
    append rega_cmd "var windS = dom.GetObject('Windstaerke');"
    append rega_cmd "var gustA = dom.GetObject('Gustangle');"
    append rega_cmd "var gustS = dom.GetObject('Guststaerke');"
    append rega_cmd "OTemp.State('$otemp');"
    append rega_cmd "OHumi.State('$ohum');"
    append rega_cmd "ITemp.State('$itemp');"
    append rega_cmd "IHumi.State('$ihum');"
    append rega_cmd "IPress.State('$ipressure');"
    append rega_cmd "ICO2.State('$ico2');"
    append rega_cmd "INoise.State('$inoise');"
    append rega_cmd "Rain1.State('$rain30min');"
    append rega_cmd "Rain2.State('$rain1d');"
    append rega_cmd "Rain3.State('$rain2');"
    append rega_cmd "windA.State('$windangle');"
    append rega_cmd "windS.State('$windstrength');"
    append rega_cmd "gustA.State('$gustangle');"
    append rega_cmd "gustS.State('$guststrength');"
    append rega_cmd "var ZTemp1 = dom.GetObject('CUxD.CUX9002003:1.SET_TEMPERATURE');"
    append rega_cmd "var ZHumi1 = dom.GetObject('CUxD.CUX9002003:1.SET_HUMIDITY');"
    append rega_cmd "var ZCO21 = dom.GetObject('CO2_SZ1');"
    append rega_cmd "ZTemp1.State('$ztemp1');"
    append rega_cmd "ZHumi1.State('$zhum1');"
    append rega_cmd "ZCO21.State('$zco21');"
    append rega_cmd "var ZTemp2 = dom.GetObject('CUxD.CUX9002004:1.SET_TEMPERATURE');"
    append rega_cmd "var ZHumi2 = dom.GetObject('CUxD.CUX9002004:1.SET_HUMIDITY');"
    append rega_cmd "var ZCO22 = dom.GetObject('CO2_SZ2');"
    append rega_cmd "ZTemp2.State('$ztemp2');"
    append rega_cmd "ZHumi2.State('$zhum2');"
    append rega_cmd "ZCO22.State('$zco22');"
    append rega_cmd "var sdatetime = system.Date('%d.%m.%Y %H:%M:%S');"
    append rega_cmd "var netatmosynctime = dom.GetObject('SyncTime');"
    append rega_cmd "netatmosynctime.Variable(sdatetime.ToString());"
    rega_script $rega_cmd
Die Abfrage per ssh lieferte allerdings gestern alle Daten.

Wird sicher irgendwo ein Denkfehler sein.

Gollum603
Beiträge: 2
Registriert: 08.05.2019, 15:55

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von Gollum603 » 08.05.2019, 15:58

Hi Leute,

ich hab hier alles durchgelesen und gemacht...glaube ich...aber es funzt immer noch nicht.

Bekomme folgenden Fehler wenn ich das Script ausführen möchte:

invalid command name "Â "
while executing
"Â Â #!/bin/tclsh"
(file "/usr/local/addons/netatmo/netatmo.tcl" line 1)

Das Script sie wie folgt aus:
#!/bin/tclsh

    load tclrega.so

    #---------------------------------------------------------------------------------------------------------------#
    #                                                   CONFIG                                                      #
    #---------------------------------------------------------------------------------------------------------------#
    #  to obtain your own client ID and API key please register a new app here: http://dev.netatmo.com/dev/listapps
    set clientId 5ccff840ad98dd4XXXXXXXXXXX                   
    set clientSecret Canu0dN90aQEgVrDWGgLXXXXXXXXXXXX
    #  the following are your normal netatmo credentials (the ones you used to setup your netatmo weather station)
    set username XXXXXXXX
    set password XXXXXXXX
    #  the following are MAC addresses of your indoor station and the outside module and rain module
    set deviceid "70:ee:50:XXXXXXX"
    set moduleid "02:00:00:XXXXXXXX"
    set windid "06:00:00:0XXXXXXXX"

    set ::env(LD_LIBRARY_PATH) "/usr/local/addons/cuxd"
    set cfgfile "/tmp/netatmo.dat"
    set logtag "netatmo.tcl"
    set logfacility "local1"
    # 0=panic, 1=alert 2=crit 3=err 4=warn 5=notice 6=info 7=debug
    set loglevel 6
    #---------------------------------------------------------------------------------------------------------------#

    #---------------------------------------------------------------------------------------------------------------#
    #                                              GLOBAL VARIABLES                                                                #
    #---------------------------------------------------------------------------------------------------------------#
    set accesstoken ""
    set refreshtoken ""
    set tokenexpires 0
    #---------------------------------------------------------------------------------------------------------------#


    set loglevels {panic alert crit err warn notice info debug}

    proc log {lvl msg} {
        global logtag
        global logfacility
        global loglevel
        global loglevels
       
        set lvlnum [lsearch $loglevels $lvl]
       
        if {$lvlnum <= $loglevel} {
            if {$lvlnum <= 3} {
                catch {exec logger -s -t $logtag -p $logfacility.$lvl $msg}
            } else {
                puts "$lvl: $msg"
                catch {exec logger -t $logtag -p $logfacility.$lvl $msg}
            }
           
        }
       
    }

    proc refreshToken {rt ci cs} {
        log debug "refreshing token"
        set url "https://api.netatmo.net/oauth2/token"
        set header "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
        set parameter "grant_type=refresh_token&refresh_token=$rt&client_id=$ci&client_secret=$cs"

        catch {exec /usr/local/addons/cuxd/curl -k -i -H $header -X POST -d $parameter $url} response
        log debug "response was $response"
       
        return $response

    }

    proc requestToken {ci cs un pw} {
        log "debug" "requesting new token"
        set url "https://api.netatmo.net/oauth2/token"
        set header "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
        set parameter "grant_type=password&client_id=$ci&client_secret=$cs&username=$un&password=$pw"

        catch {exec /usr/local/addons/cuxd/curl -k -i -H $header -X POST -d $parameter $url} response
        log debug "response was $response"
       
        return $response

    }

    proc parseOAuthResponse {input} {
        log debug "parsing authentication result"
        global accesstoken
        global refreshtoken
       
        regexp {HTTP/1.1\s(\d*)} $input dummy returncode
        regexp {\"access_token\":\"(.*?)\"} $input dummy accesstoken
        regexp {\"refresh_token\":\"(.*?)\"} $input dummy refreshtoken
        regexp {\"expires_in\":(.*?)\,} $input dummy expiresin

        log debug "returncode is $returncode"
        log debug "access token is $accesstoken"
        log debug "refresh token is $refreshtoken"
        log debug "expires in $expiresin"
       
        if {[expr $returncode]!=200} {
                log error "Authentication failed with code $returncode and response $input"
                exit 1
            }
       
        return $expiresin
    }

    proc saveAccessToken {expin} {
        global accesstoken
        global refreshtoken
        global tokenexpires
        global cfgfile
           
        log debug "saving new access token to $cfgfile"
       
        set fileId [open $cfgfile "w"]
       
        set now [clock seconds]
        set tokenexpires [expr $now + $expin]
       
        puts $fileId $accesstoken
        puts $fileId $refreshtoken
        puts $fileId $tokenexpires
        close $fileId
    }

    proc loadAccessToken {} {
        global accesstoken
        global refreshtoken
        global tokenexpires
        global cfgfile
       
        log debug "loading stored credentials from $cfgfile"
       
        set fp [open $cfgfile r]
        set file_data [read $fp]
        close $fp
       
        log debug "file data is: $file_data"
       
        set data [split $file_data "\n"]   
       
        set accesstoken [lindex $data 0]
        set refreshtoken [lindex $data 1]
        set tokenexpires [lindex $data 2]
    }

    log debug "script has started"

    if { [file exists $cfgfile] == 1} {
        log info "found stored credentials"
            loadAccessToken
            set now [clock seconds]
            log debug "current time is [clock format $now -format "%Y-%m-%dT%H:%M:%S"], token is valid until [clock format $tokenexpires -format "%Y-%m-%dT%H:%M:%S"]"
            if {[expr $now >= $tokenexpires] == 1} {
                log notice "token has already expired"
                saveAccessToken [parseOAuthResponse [refreshToken $refreshtoken $clientId $clientSecret]]
                log notice "oauth token successfully refreshed"
            } else {
                log info "token is still valid"
            }
        } else {
            log warn "no stored credentials found"
            saveAccessToken [parseOAuthResponse [requestToken $clientId $clientSecret $username $password]]
            log notice "oauth token successfully initialized"
        }

    log debug "polling outdoor module..."
    set url "https://api.netatmo.net/api/getmeasure? ... e_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"

    regexp {\"value\":\[\[(.*?),(.*?)\]} $response dummy otemp ohum

    log info "Outside temperature is $otemp"
    log info "Outside humidity is $ohum"

    log debug "polling main module..."
    set url "https://api.netatmo.net/api/getmeasure? ... e_end=last"
    log debug "querying $url"
    catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
    log debug "response is: $response"

    regexp {\"value\":\[\[(.*?),(.*?),(.*?),(.*?),(.*?)\]} $response dummy itemp ihum ico2 ipressure inoise
   
    log info "LogI is $response"             
    log info "Inside temperature is $itemp"
    log info "Inside humidity is $ihum"
    log info "Inside CO2 level $ico2"
    log info "Inside pressure is $ipressure"
    log info "Inside noise level is $inoise"

    log debug "polling wind module..."
    set url "https://api.netatmo.net/api/getmeasure? ... e_end=last"
   log debug "quering $url"
   catch {exec /usr/local/addons/cuxd/curl -k -# $url} response
   log debug "respnose is $response"

   regexp {\"value\":\[\[(.*?),(.*?),(.*?),(.*?)\]} $response dummy windangle windstrength gustangle guststrength
   log info "WindAngle is $windangle"
   log info "Windstrength is $windstrength"
   log info "GustAngle is $gustangle"
   log info "Guststrength is $guststrength"


    #
    # set ReGaHss variables
    #
    set rega_cmd ""
    append rega_cmd "var ITemp = dom.GetObject('CUxD.CUX9002001:1.SET_TEMPERATURE');"
    append rega_cmd "var IHumi = dom.GetObject('CUxD.CUX9002001:1.SET_HUMIDITY');"
    append rega_cmd "var OTemp = dom.GetObject('CUxD.CUX9002002:1.SET_TEMPERATURE');"
    append rega_cmd "var OHumi = dom.GetObject('CUxD.CUX9002002:1.SET_HUMIDITY');"
    append rega_cmd "var IPress = dom.GetObject('Luftdruck');"
    append rega_cmd "var ICO2 = dom.GetObject('CO2');"
    append rega_cmd "var INoise = dom.GetObject('Sonometer');"
    append rega_cmd "var windA = dom.GetObject('Windrichtung');"
    append rega_cmd "var windS = dom.GetObject('Windstaerke');"
    append rega_cmd "var gustA = dom.GetObject('Gustangle');"
    append rega_cmd "var gustS = dom.GetObject('Guststaerke');"
    append rega_cmd "OTemp.State('$otemp');"
    append rega_cmd "OHumi.State('$ohum');"
    append rega_cmd "ITemp.State('$itemp');"
    append rega_cmd "IHumi.State('$ihum');"
    append rega_cmd "IPress.State('$ipressure');"
    append rega_cmd "ICO2.State('$ico2');"
    append rega_cmd "INoise.State('$inoise');"
  append rega_cmd "windA.State('$windangle');"
    append rega_cmd "windS.State('$windstrength');"
    append rega_cmd "gustA.State('$gustangle');"
    append rega_cmd "gustS.State('$guststrength');"
    append rega_cmd "var sdatetime = system.Date('%d.%m.%Y %H:%M:%S');"
    append rega_cmd "var netatmosynctime = dom.GetObject('SyncTime');"
    append rega_cmd "netatmosynctime.Variable(sdatetime.ToString());"
    rega_script $rega_cmd


Ich hoffe ihr habt noch Tipss für mich...Danke

Indigo
Beiträge: 355
Registriert: 10.02.2015, 20:32

Re: Netatmo Wetterstation (incl. CO2 Messung) einbinden

Beitrag von Indigo » 09.05.2019, 11:40

@Chrisrookie
Bist du schon weitergekommen? Ich finde auf Anhieb auch keinen Fehler in deinem Script.
Die Synctime wird wahrscheinlich auch nicht mehr aktualisiert, oder?
Vielleicht ist ein Tipfehler in einer deiner neu angelegten Variablen ( Null statt O) oder diese wurden nicht als Zahl angelegt.

Antworten

Zurück zu „HomeMatic Tipps & Tricks - keine Fragen!“