Hmm that is a tricky one. The event tracking appears to be working which would point to a problem around the DB query - either with the query itself or the var component.
You could try to enable debug logging for the var component. When the query runs you should see one of three messages:
Well that is strange. It seems that this might be a bug, but I’m having trouble identifying the cause.
The trigger is most likely still running, but the state changed event for sensor.time is either not being recorded in the database or not being found in the database.
The way the event triggers work with a query is the var component listens for the specified events (in this case the state change event for sensor.time). When a tracked event occurs, the var component polls the database until it sees that the event has been written to the database (it has to wait in case the query involves that event). Once it sees the event in the database, then it updates itself, running and evaluating the query.
So if the query is not running, that means that the event is either not being written or for whatever reason it is not being found.
Can you check the logbook and see if the updates to sensor.time are present there?
Thanks for your help. Checked Logbook and sensor.time was not updated every minute. Sometimes it wouldn’t be for several minutes, others several hours. The interesting thing is History was showing that it updated every minute. So there might be a bug with sensor.time or it wont work for this situation.
Changed to using an automation to run var.update every minute and it appears to be working. Below is what I ended up.
alias: var - run every minute
description: >-
Used by the home-assistant-variables component to update certain sensors every
minute
trigger:
- platform: time_pattern
minutes: /1
condition: []
action:
- service: var.update
data: {}
entity_id: var.front_patio_max_temp
mode: single
front_patio_max_temp:
friendly_name: "Front Patio Max Temp"
icon: mdi:temperature-fahrenheit
query: "SELECT MAX(state) AS value FROM states WHERE created > CURRENT_DATE + INTERVAL 8 HOUR AND entity_id = 'sensor.front_patio_thgr810_temperature' AND state REGEXP '^[0-9].+$';"
column: 'value'
I have question regarding how to calculate a custom variable value and sensor value.
Is this possible?
I have put following code in my configuration.yam;
This value is my last known value from my official energy flow meter.
The code above is working fine, i have now a new entity with this value!
I also use the IAMMETER pluggin.
My question, I would like to calculate (SUM) the total energy used coming from the AIMMETER with the variable entity above. After this I have almost a up to date energy flow meter value!
I have tried to build a template with following code;
But I guess this can not work because my custom variable is not a sensor, correct?
Because the result of this code is the value coming from the sensor.energy_total_used (IAMMETER).
I’m having trouble following the snippets of yaml you posted, but one suggestion would be to use tracked_entity_id to update a variable whenever your sensor updates.
Here you can see the value 16676,8 I wan’t to use for calculation.
Now I need to create a variable to get this value in has.
After that I would like to update (sum) this value (16678,8) with my existing sensor.energy_total_used to get a kind of up to date virtual energy meter like my picture above!
Maybe someone can help me with this and tell me how to fix this?