id
obj
envoy_username
envoy_password
envoy_serial_no
log_flag
envoy_ip
envoy_path
bearer_token
log_msg
err_cnt
result
http_resp_json
ENPHASE ENVOY/IQ GATEWAY LOADER
Requires >=v7 of Envoy API (i.e. current token authentication method)
*** INIT ***
err_cnt
0
http_resp_json
Toggle logging of "info events" (debugging). Errors will always be logged.
*** USER INPUT ***
log_flag
TRUE
Add your Enphase Enlighten Cloud credentials below
(not needed if bearer token is provided below)
*** USER INPUT ***
envoy_username
envoy_password
Add serial no (12 digit) and IP of local Envoy (mandatory)
*** USER INPUT ***
envoy_serial_no
envoy_ip
OPTIONAL: Add your existing Envoy token below (e.g. for testing purposes)
(Note: If you fill in your token here then automatic token renewal with envoy username/password is disabled)
*** USER INPUT ***
bearer_token
Check if initial Envoy bearer token needs to be requested from Enphase server
(Info logging of token renewal is always enabled)
EQ
bearer_token
result
envoy_username
envoy_password
envoy_serial_no
TRUE
*** CYCLIC PROGRAM LOOP ***
Set timer (default every minute) for cyclic fetching of PV data from local Envoy
prüfen, ob sc_stream "enabled" ist
* * * * *
EQ
val
0_userdata.0.enphase.livedata.connection.sc_stream
disabled
log
test
envoy_ip
/ivp/livedata/stream
bearer_token
POST sc_stream. data:
log_flag
EQ
val
0_userdata.0.enphase.livedata.connection.sc_stream
disabled
0_userdata.0.Enphase-Werte_durch_1000.sc_stream_disabled
FALSE
10
0_userdata.0.Enphase-Werte_durch_1000.sc_stream_disabled
FALSE
0
EQ
val
0_userdata.0.enphase.livedata.connection.sc_stream
enabled
0_userdata.0.Enphase-Werte_durch_1000.sc_stream_enabled
FALSE
10
0_userdata.0.Enphase-Werte_durch_1000.sc_stream_enabled
FALSE
0
Periodic token renewal
Default: Daily
{"time":{"start":"00:00","end":"24:00","mode":"hours","interval":24},"period":{"days":1},"valid":{"from":"05.06.2023","to":""}}
result
envoy_username
envoy_password
envoy_serial_no
TRUE
Support functions
IObSetState
Zm9yKGxldCBpIGluIG9iaikgew0KICAgaWYodHlwZW9mIG9ialtpXSA9PSAnb2JqZWN0JykgSU9iU2V0U3RhdGUoaWQgKyAnLicgKyBpLCBvYmpbaV0pOw0KICAgZWxzZSB7DQogICAgICBpZihleGlzdHNTdGF0ZShpZCArICcuJyArIGkpKSAvLyBFeGlzdGluZyBvYmplY3QvIFVwZGF0ZQ0KICAgICAgICAgeyAgICAgICAgIA0KICAgICAgICAgaWYodHlwZW9mIG9ialtpXSA9PT0gJ3N0cmluZycgfHwgb2JqW2ldIGluc3RhbmNlb2YgU3RyaW5nKQ0KICAgICAgICAgICAgey8vIFN0cmluZw0KICAgICAgICAgICAgc2V0U3RhdGUoaWQgKyAnLicgKyBpLCBvYmpbaV0sIHRydWUpOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgZWxzZQ0KICAgICAgICAgICAgey8vIEl0IGlzIGEgbnVtYmVyIG9yIGRhdGUNCiAgICAgICAgICAgIC8vaWYoKG5ldyBEYXRlKG9ialtpXSkpLmdldFRpbWUoKSA+IDAgJiYgb2JqW2ldLnRvU3RyaW5nKCkubGVuZ3RoID09IDEwICYmIG9ialtpXS50b1N0cmluZygpLmNoYXJBdCgwKSA9PSAnMScpDQogICAgICAgICAgICBpZigobmV3IERhdGUob2JqW2ldKSkuZ2V0VGltZSgpID4gMCAmJiBOdW1iZXIob2JqW2ldKSA+IDE2ODUwMDAwMDAgJiYgTnVtYmVyKG9ialtpXSkgPCA0MTAwMDAwMDAwKQ0KICAgICAgICAgICAgICAgey8vIERhdGUNCiAgICAgICAgICAgICAgIHNldFN0YXRlKGlkICsgJy4nICsgaSwgb2JqW2ldLCB0cnVlKTsNCiAgICAgICAgICAgICAgIHNldFN0YXRlKGlkICsgJy4nICsgaSArICdfc3RyJywgZm9ybWF0RGF0ZShvYmpbaV0sICJUVC5NTS5KSkpKIFNTOm1tOnNzIiksIHRydWUpOyANCiAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIGVsc2UNCiAgICAgICAgICAgICAgIHsvLyBOdW1iZXINCiAgICAgICAgICAgICAgIHNldF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iKSwgZmFsc2UsIHt0eXBlOiAic3RyaW5nIiwgcmVhZDogdHJ1ZSwgd3JpdGU6IHRydWV9KTsgDQogICAgICAgICAgICAgICB9DQogICAgICAgICAgICBlbHNlDQogICAgICAgICAgICAgICB7Ly8gTnVtYmVyDQogICAgICAgICAgICAgICBjcmVhdGVTdGF0ZShpZCArICcuJyArIGksIG9ialtpXSwgZmFsc2UsIHt0eXBlOiAibnVtYmVyIiwgcmVhZDogdHJ1ZSwgd3JpdGU6IHRydWV9KTsgLy8gb3IgdHlwZTogIm1peGVkIj8NCiAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgfQ0KICAgICAgICAvL2NvbnNvbGUubG9nKGlkICsgJy4nICsgaSArICc6ICcgKyBvYmpbaV0pOw0KICAgfQ0KfQ==
Create new or update existing states in IOBroker according to the JSON structure received from local Envoy URL (function 'GetEnvoyData).In case of a unix timestamp field this function will create an additional IOBroker state to show the unix time in human readable format. The field name of this additional field is built from 'fieldname' followed by '_str' (e.g. 'fieldname_str').The 'id' parameter specifies the tree hierarchy in IOBroker e.g. '0_userdata.0.enphase.consumption' in which PV data will be populated.
renew_EnvoyToken
Y29uc3QgZmV0Y2ggPSByZXF1aXJlKCdub2RlLWZldGNoJyk7DQpjb25zdCBxdWVyeXN0cmluZyA9IHJlcXVpcmUoJ3F1ZXJ5c3RyaW5nJyk7DQoNCi8vIExvZ2luLUFuZnJhZ2UNCmNvbnN0IGxvZ2luRGF0YSA9IHF1ZXJ5c3RyaW5nLnN0cmluZ2lmeSh7DQogICd1c2VyW2VtYWlsXSc6IGVudm95X3VzZXJuYW1lLA0KICAndXNlcltwYXNzd29yZF0nOiBlbnZveV9wYXNzd29yZA0KfSk7DQoNCmlmKGxvZ19mbGFnKXtjb25zb2xlLmxvZygnUmVuZXcgdG9rZW4uIDEuIExvZ2luIHRvIGVubGlnaHRlbi5lbnBoYXNlZW5lcmd5LmNvbSB0byBnZXQgc2Vzc2lvbl9pZC4uLicp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nNlID0+IHJlc3BvbnNlLnRleHQoKSkNCiAgLnRoZW4odG9rZW5SYXcgPT4gew0KICAgIGlmKGxvZ19mbGFnKXtjb25zb2xlLmxvZygnTmV3IHRva2VuOiAnICsgdG9rZW5SYXcpO30NCiAgICBiZWFyZXJfdG9rZW4gPSB0b2tlblJhdzsNCiAgfSkNCiAgLmNhdGNoKGVycm9yID0+IHsNCiAgICBjb25zb2xlLmxvZygnRXJyb3IgdG9rZW4gcmVuZXdhbDogJyArIGVycm9yLm1lc3NhZ2UpOw0KICB9KTs=
Function to request a new Enphase bearer token.Your Enphase cloud username, password and serial number of your local Envoy are needed.
PostEnvoyData
Y29uc3QgaHR0cHMgPSByZXF1aXJlKCdodHRwcycpOw0KDQphc3luYyBmdW5jdGlvbiBwb3N0UFZEYXRhKCkgew0KICBjb25zdCBvcHRpb25zID0gew0KICAgIGhvc3RuYW1lOiBlbnZveV9pcCwNCiAgICBwb3J0OiA0NDMsDQogICAgcGF0aDogZW52b3lfcGF0aCwNCiAgICBtZXRob2Q6ICdQT1NUJywNCiAgICByZWplY3RVbmF1dGhvcml6ZWQ6IGZhbHNlLCAvLyBJZ25vcmUgaW52YWxpZCBjZXJ0aWZpY2F0ZQ0KICAgIGhlYWRlcnM6IHsnQXV0aG9yaXphdGlvbic6ICdCZWFyZXIgJysgYmVhcmVyX3Rva2VuICsgJyd9DQogIH07DQoNCiAgdHJ5IHsNCiAgICBjb25zdCByZXNwb25zZSA9IGF3YWl0IG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHsNCiAgICAgIGNvbnN0IHJlcSA9IGh0dHBzLnJlcXVlc3Qob3B0aW9ucywgKHJlcykgPT4gew0KICAgICAgICBsZXQgZGF0YSA9ICcnOw0KDQogICAgICAgIHJlcy5vbignZGF0YScsIChjaHVuaykgPT4gew0KICAgICAgICAgIGRhdGEgKz0gY2h1bms7DQogICAgICAgIH0pOw0KDQogICAgICAgIHJlcy5vbignZW5kJywgKCkgPT4gew0KIC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GZhbHNlKTsNCn0=
Function to fetch PV data from your local Envoy. The JSON response of the given URL will then update (or create if nor existing) the corresponding states in IOBroker (via function IObSetState)