steps39 / Domoticz_Smappee

A Lua program to link Smappee into Domoticz
3 stars 0 forks source link

Error writing on Domoticz #3

Closed dragoshenron closed 6 years ago

dragoshenron commented 6 years ago

Hello @steps39. Thanks for the great script.

I have an issue though, which does't seems related with the new roll-out of MQTT protocol for the plugs.

I have followed all the steps required for the installation of such script and everything went well up to december last year. Since then I (=Domoticz) don't get anymore updates.

This is a piece of the log file

2018-04-11 14:45:01 - ------------------------------------------- 2018-04-11 14:45:01 - Starting Smappee to Domoticz Energy Handler 2018-04-11 14:45:01 - ------------------------------------------- 2018-04-11 14:45:01 - SmappeeClientSecret: REDACTED 2018-04-11 14:45:01 - SmappeeClientID: dragoshenron 2018-04-11 14:45:01 - SmappeeUsername: dragoshenron 2018-04-11 14:45:01 - SmappeePassword: REDACTED 2018-04-11 14:45:01 - DomoticzUsername: 2018-04-11 14:45:01 - DomoticzPassword: 2018-04-11 14:45:01 - DomoticzIP: 127.0.0.1 2018-04-11 14:45:01 - DomoticzPort: 8080 2018-04-11 14:45:01 - SmappeeHousehold: CasettaConsumo 2018-04-11 14:45:01 - SmappeeSolar: CasettaSolare 2018-04-11 14:45:01 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariables 2018-04-11 14:45:01 - Domoticz returned getuservariables after 1 attempts 2018-04-11 14:45:01 - 1 2018-04-11 14:45:01 - SmappeeAccessToken idx 1 2018-04-11 14:45:01 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariable&idx=1 2018-04-11 14:45:01 - Decoded db0ea081-2db0-36c6-917a-743c59970b8a 2018-04-11 14:45:01 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariables 2018-04-11 14:45:01 - Domoticz returned getuservariables after 1 attempts 2018-04-11 14:45:01 - 2 2018-04-11 14:45:01 - SmappeeRefreshToken idx 2 2018-04-11 14:45:01 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariable&idx=2 2018-04-11 14:45:01 - Decoded 872b2c6b-49b5-3465-ba5a-a73b5fef60c0 2018-04-11 14:45:01 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariables 2018-04-11 14:45:01 - Domoticz returned getuservariables after 1 attempts 2018-04-11 14:45:01 - 3 2018-04-11 14:45:01 - SmappeeExpiresAt idx 3 2018-04-11 14:45:01 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariable&idx=3 2018-04-11 14:45:01 - Decoded 1523460301 200 2018-04-11 14:45:02 - Smappee Service Location: REDACTED 2018-04-11 14:45:02 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariables 2018-04-11 14:45:02 - Domoticz returned getuservariables after 1 attempts 2018-04-11 14:45:02 - 4 2018-04-11 14:45:02 - SmappeeTimeStamp idx 4 2018-04-11 14:45:02 - JSON request http://:@127.0.0.1:8080/json.htm?type=command&param=getuservariable&idx=4 2018-04-11 14:45:02 - Decoded 1523373902 2018-04-11 14:45:02 - Previous Time Stamp 1523373903 2018-04-11 14:45:02 - Current Time Stamp: 1523457902 2018-04-11 14:45:02 - https://app1pub.smappee.net/dev/v1/servicelocation/19395/consumption?aggregation=1&from=1523373903000&to=1523457902000 2018-04-11 14:45:02 - 200

While the log.errors is:

lua: /usr/local/share/lua/5.2/JSON.lua:676: /usr/local/share/lua/5.2/JSON.lua:383: unclosed string at char 8105 of: { "serviceLocationId": REDACTED, "consumptions": [ { "timestamp": 1523374200000, "consumption": 24.2, "solar": 31.5, "alwaysOn": 85.0 }, [MANY OTHER FIELDS]
{ "timestamp": 1523394000000, "consumption": 8.9, "solar": 0.0, "alwaysOn": 85.0 }, { "timestamp": 1523394300000, "consumption": 7.6, "solar": 0.0, "alwaysOn": 85.0 }, { "timestamp": 1523394600000, "consumption": 7.6, "sol stack traceback: [C]: in function 'assert' /usr/local/share/lua/5.2/JSON.lua:676: in function 'decode' /home/pi/domoticz_smappee/smappee.lua:323: in main chunk [C]: in ?

It looks like the JSON is truncated so becomes invalid. I thought something was wrong with 'SmappeeTimestamp' user variable which was indeed not update since the fault (decembre 2017). I updated manually to the current time but still, I get the same issue.

Any idea?

Cheers, Alex

steps39 commented 6 years ago

You are correct the JSON is truncated because Smappee is trying to supply too much information.

Looking at your log: 2018-04-11 14:45:02 - Previous Time Stamp 1523373903 2018-04-11 14:45:02 - Current Time Stamp: 1523457902 So Smappee is trying to supply information between 1523373903 and 1523457902.

The error should be fixed by setting SmappeeTimestamp to value closer to current time stamp - so if look at the end of the current log and set it to 400 less than that value, so with data above set it to 1523457502, then after 5 - 10 minutes it should collect a value. It should also recover if you set SmappeeTimestamp to 1, then it will work out latest time itself.

dragoshenron commented 6 years ago

Thank you @steps39 I follow your advice (SmappeeTimestamp = CurrentTimestamp - 400) and now I have regular updates.

You can close the issue. Cheers :)