Hi,
I have a Template Helper sensor that calculate the price of the energy in my country.
I noticed that the History data for this sensor is only 7 days, is there a way to extend history data?
Thanks
Marco
Hi,
I have a Template Helper sensor that calculate the price of the energy in my country.
I noticed that the History data for this sensor is only 7 days, is there a way to extend history data?
Thanks
Marco
Set its state_class
to measurement
.
The moment you specify a value for state_class
, the sensor’s values will be stored in long-term statistics which has no time limit.
You may also consider setting unit_of_measurement
to your country’s currency symbol.
It will start recording from today.
The values the sensor had 7+ days ago have been discarded. Setting state_class
simply instructs Home Assistant to stop discarding the sensor’s old values, starting from now.
Just keep in mind that LTS has a granularity of one hour.
Hi @123
sensor is set like this from months ago, but only last days are kept
Have you excluded any sensors in your recorder settings?
No. Recorder settings are as default
for LTS to work, you need to add a device class, as it needs both device class and measurement type.
Hi @andyblac,
it is energy price, wich class you suggest to use?
Marco
I do not think so.
going of the list available here Sensor - Home Assistant
I would use monetary
edit:
Entities not representing a total amount
Home Assistant tracks the min, max and mean value during the statistics period. The
state_class
property must be set toSensorStateClass.MEASUREMENT
, and thedevice_class
must not be either ofSensorDeviceClass.DATE
,SensorDeviceClass.ENUM
,SensorDeviceClass.ENERGY
,SensorDeviceClass.GAS
,SensorDeviceClass.MONETARY
,SensorDeviceClass.TIMESTAMP
,SensorDeviceClass.VOLUME
orSensorDeviceClass.WATER
.
any other suggestion on how to check?
thanks
looks like monetary can not be used in LTS, as LTS take the average of the hour
on further looking into this try a state class of Total
.
If your values are numerical, have UoM and a valid state_class - check Logs and Dev tools - statistics for any related issues.
I have just quickly looked that the code for the integration that I use for my energy supplier, and this is what their using
@property
def state_class(self):
"""The state class of sensor"""
return SensorStateClass.TOTAL
@property
def device_class(self):
"""The type of sensor"""
return SensorDeviceClass.MONETARY
so try setting your template sensor to the same.
Hi @andyblac
I checked my config. Moved state class to total, but in device class I have not monetary:
It’s called Balance in the UI, at least, that’s what the english translation is set to.
Go to Developer Tools → Statistics. Is the Template Sensor shown in the list? Does it indicate it has a problem?