azerty9971 / xtend_tuya

eXtend Tuya's integration
GNU General Public License v3.0
30 stars 4 forks source link

Consumption, last value #9

Closed roccolord closed 3 months ago

roccolord commented 5 months ago

Hello thanks for a good xtention! Could you add so that consumption is retrieving the last known value at boot? would be nice so that graphs for consumption over time doesn't reset when you need to restart HA.

glendower commented 4 months ago

This is a great integration however it would be great if values persisted across restarts

azerty9971 commented 4 months ago

Hello, I agree but so far I wasn't able to find the way to do that :/.

roccolord commented 4 months ago

Found this regarding the states:

The RestoreEntity class is used by Home Assistant to restore an entities state when you restart home assistant. It saves periodically and when you shutdown home assistant, all the states of your entities in a file under config/.storage/core.restore_state. When you startup home assistant, integrations that extend RestoreEntity can call a method async_get_last_state(self) to retrieve the previous state and use it to setup the component.

The sensors created with xtend_tuya doesn't exist in core.restore_state.

roccolord commented 4 months ago

Sensors which restore the state after restart or reload should not extend RestoreEntity because that does not store the native_value, but instead the state which may have been modified by the sensor base entity. Sensors which restore the state should extend RestoreSensor and call await self.async_get_last_sensor_data from async_added_to_hass to get access to the stored native_value and native_unit_of_measurement.

https://developers.home-assistant.io/docs/core/entity/sensor/

azerty9971 commented 3 months ago

Hello, Thanks for the info, I've implemented this feature and now the values are being restored :).

Please update to the latest version.

Have a nice day, Azerty