Closed Hellowlol closed 4 years ago
@turbokongen Do you got a list of the hourly sensors (without the meter_id)
@turbokongen Do you got a list of the hourly sensors (without the meter_id)
ams_active_energy_import ams_active_energy_export ams_reactive_energy_import ams_reactive_energy_export
What type of behavior do we want here (?)
I rather have unknown values then incorrect one. So my plan was just to only restore hourly sensors if they where still valid. (less then 1 hour since last update). This will allow for hourly sensors be available together with the rest of sensors when a user restart ha
Thoughts? @turbokongen @jnrksv
I agree with you @Hellowlol No need to restore 10sec sensors as they quickly gets populated. I think 1 hour sensors should be restored no matter how long ago they last got updated. Say by accident the 1hour package fail any of the checks and are discarded as a failed package it will be 2hours between last and next update. Maybe use 2hours since last and not 1 hour?
So this seems to work now. (Only for kamstrup atm) I have used way to much time to tracking time a bug relating to parser. the parser seems mutate self.sensor_data but it dont seems to use it the way i expected.
This is ready for a spin now, still got some minor clean up to do, but everthing works (on my computer atleast 🤞 )
@turbokongen @jnrksv
Since this also includes some small changes to the parser: @jorgen666 - Kaifa meter @jgallis - Aidon meter
Would anybody mind testing it?
Delete the __pycache__
folder in both the parser and ams folder and just copy the content.
Verify that all the sensors works as it should.
The hourly sensors might still be unknown, (depending on some conditions), however the sensors should have values after the first hour is passed. Restart home assistant and verify that the hourly sensors is not unknown.
Have done some testing this morning. It seems that restore state works for ams_active_energy_import_57065672xxxxxxxx and ams_reactive_energy_export_57065672xxxxxxxx whenever HA is restarted. While ams_active_energy_export_570656728xxxxxxxx and ams_reactive_energy_import_57065672xxxxxxxx are stated as "unknown" until the next hourly readout.
@jnrksv thanks. Can you try to restart ha after the next hourly read and see if all sensors comes back? Also enable debug incase it don’t work, so I can have that as well.
@Hellowlol It works perfect at my end.
@Hellowlol - same findings as in my previous post. Attched debug log from restarting HA a few minutes ago. hass-ams-patch3-restart-log.txt
@jnrksv Did you remove the integration, and deleted pycache before you Installed this Version?
Yes, infact I deleted the ams folder and did a new installation. I'll try once more in twenty minutes. And to be completely sure I'm deleting pycache right now.
Remember the the pycache inside the parser folder.
Both pycache deleted. For me, this is starting to get interesting. This is the state after last houly readout: And this is the state after restarting HA a few minutes later: When pycache is deleted, where does the restored states come from? hass-ams-patch3-restart-log-1204.txt
EDIT: It works for Aidon, but it dos not take the latest hour value, it is taking the previous hour value. I tok a restart 13:05, and the sensor has this timestamp: meter_timestamp: 2020-4-10 12:00:00
@jgallis internaly ha uses utc so the time stamp is correct (Norway is one ~two hour ahead of utc)
@jnrksv _pycache__ is a just a folder where the python interpreter stores bytecode (helps programs start faster)
All the states are stored in the home assistant database.
I suspects the code is working as it should. The state might not be written to the state machine/ db so when we try to restore the state is unknown. (Not really sure but that the only reasonable I can think of) Can you test again? But this time let ha run for 10 minutes after the new hours values are in before you restart.
Can you test again? But this time let ha run for 10 minutes after the new hours values are in before you restart
I let HA run for 15 minutes after hourly readout, restarted and now every state restores as expected. Why wait 10-15 minutes? @Hellowlol - I reckon you have an explanation for this too?
It was just to to test a theory. I suspected you restarted ha right after the state changed. We schedule the update to the state machine. So if somebody restarts really quick, it might not be written to db/state machine before ha is shutdown.
@turbokongen Think this should do it.
Untested, at work so i cant test now, but in theory, restarting ha should restore tha latest state of the sensor. Just need a list off all the hours sensor names and check if last update was less one hour ago