I have correctly configured a template sensor which shows me the setup temperature of my wall thermostat.
Since the temperature will change only a few times a date HA will record the temperature only a few times in the database. Therefore the resulting graph looks odd.
I want HA to write a record every 5 min.
Unfortunately I didn’t find a way to do it. Any Ideas ?
Update frequency doesn’t work either. The problem ist that if there is no change in the value no record will be written in the database.
I managed it with a small python script which i call via automation every 5 min.
With the api call hass.states.set you can set the parameter force_update = True and it will result in writing the value to the database.
Here is the script (named force_update_state.py):
#pass entity_id as argument from call
sensor = data.get('entity_id')
#read old state
oldstate = hass.states.get(sensor)
#write old state to entity and force update to record database
hass.states.set(sensor, oldstate.state , oldstate.attributes, force_update=True)
You can call the script via Automation with the following settings. Please adjust entity_id to your Sensor Template Entity:
- action:
- data:
entity_id: sensor.termo_ufficio_set_temp
service: python_script.force_update_state
alias: Alias name
condition: []
id: '1514845748581'
trigger:
- minutes: /5
seconds: 0
platform: time