bisand / node-red-contrib-tibber-api

Node Red module for integrating with Tibber api
MIT License
20 stars 2 forks source link

Repeated timestamp on changed value from tibberfeed before restart of node-red #45

Closed Sungtroll closed 3 years ago

Sungtroll commented 3 years ago

I modified to include accumulatedConsumtionLastHour and it works fine except if ticking the check boxes on or off there is several duplicates until i restart node-red. Some messages comes with the new check boxed values, but repeated message without. Seems like two prosesses running at same time querying tibber backend but with different query one old and one new. See example below, note the timestamp is equal but message is with or without accumulatedConsumption that i ticked in the check box. I think this behavior was there before i did any changes so please investigate. I am running on Windows 10.

Steps to reproduce: log tibberfeed stright to text file. Tick check box value on or off, and deploy. Investigate the text file 10-20 seconds later for repeated messages with same timestamp but with or without value of the previously changed setting.

I modified these files, i included copies of the changes i made Modified files to include accumulatedConsumptionLastHour.zip .node-red\node_modules\tibber-api\lib\src\nodes\Tibberfeed.js .node-red\node_modules\node-red-contrib-tibber-api\nodes\tibber-feed.html

{"timestamp":"2021-03-17T18:54:52.5+01:00","power":565,"lastMeterConsumption":11908.22,"accumulatedConsumptionLastHour":0.537368,"minPower":474,"averagePower":846.3,"maxPower":5504,"powerFactor":null,"voltagePhase1":null,"voltagePhase2":null,"voltagePhase3":null,"currentL1":null,"currentL2":null,"currentL3":null} {"timestamp":"2021-03-17T18:54:55+01:00","power":566,"lastMeterConsumption":11908.22,"accumulatedConsumption":16.007761,"accumulatedConsumptionLastHour":0.537761,"minPower":474,"averagePower":846.3,"maxPower":5504,"powerFactor":null,"voltagePhase1":null,"voltagePhase2":null,"voltagePhase3":null,"currentL1":null,"currentL2":null,"currentL3":null} {"timestamp":"2021-03-17T18:54:55+01:00","power":566,"lastMeterConsumption":11908.22,"accumulatedConsumptionLastHour":0.537761,"minPower":474,"averagePower":846.3,"maxPower":5504,"powerFactor":null,"voltagePhase1":null,"voltagePhase2":null,"voltagePhase3":null,"currentL1":null,"currentL2":null,"currentL3":null}

image

Sungtroll commented 3 years ago

Playing with alternating the check box for power and lastmeterConsumption a couple of times and looking at the result in the saved file. Note that the timestamp is equal in all 4 messages.

{"timestamp":"2021-03-18T02:35:35+01:00","power":532,"lastMeterConsumption":11915.19} {"timestamp":"2021-03-18T02:35:35+01:00","lastMeterConsumption":11915.19} {"timestamp":"2021-03-18T02:35:35+01:00","power":532,"lastMeterConsumption":11915.19} {"timestamp":"2021-03-18T02:35:35+01:00","power":532}

I have several tibberfeed nodes in my flows, one in each flow connected to different user. In this example all the other flows are disabled before restart of node-red. All other tibberfeed nodes that are disabled is configured with a lot more queries checked so i think they are not interfering, but maybe the same is not happening in a clean system with only one flow.

When deploying after changing the setting tibberfeed disconnects for a very short time. Is it possible that the WS stream is not closed at tibber after the changes and tibber still carry on sending out the previous stream requested resulting in tibberfeed is receiving two or more different streams?

bisand commented 3 years ago

TibberFeed is now updated with the two new properties, accumulatedConsumptionLastHour and accumulatedProductionLastHour (v2.1.0). I am still researching the timestamp issue, so I will leave this issue open

bisand commented 3 years ago

The duplicate problem should be gone now. I discovered that I had some concurrency issues where event handler potentially could be called multiple times. @Sungtroll could you please test and see if you can confirm?

Sungtroll commented 3 years ago

The problem exists in the latest build 2.1.0.

bisand commented 3 years ago

I have just released 2.2.2 to node-red repository. Try to upgrade the module and try again.

Sungtroll commented 3 years ago

The duplicates are gone now, but for the changes in the tick box to be effective i have to restart node-red. I dont know if this is only in my system, i have multiple tibberfeed flows but all the other is disabled before restarting node-red to do the testing.

bisand commented 3 years ago

Ok. I think I found the problem, but will have to do some more testing before I am sure. I'll get back to you as soon as I can.

bisand commented 3 years ago

The "checkbox problem" should now be resolved. Install v2.3.0 to test.

Sungtroll commented 3 years ago

Installed 2.3.0 and tested changed selection with multiple flows running tibberfeed with 4 different users at the same time. Everything works wonderful perfect now. Thank you bisand for your dedication of making tibber-api, the best ever solution that collects tibber pulse realtime data easily available for everyone to use. Great work :-)

bisand commented 3 years ago

Thanks!