I want to create a templated sensor that updates if there is a new value of “energie_productie_zon_watt” or if the templated sensor is not updated for 10 minutes.
some context:
My energy meter return each second the consumed and the returned power to/from the grid -sensor.energie_consumption_watt -sensor.energie_production_watt
My solar panels returns the produced power every x minutes: -sensor.energie_productie_zon_watt
So I calculate the “real consumption” whenever the slowest sensor (=energie_productie_zon_watt) is being updated. But at night that sensor is never updated that’s why I add the 2nd trigger as fallback.
I also tried value_template: {{(now() - states.sensor.energie_productie_zon_watt.last_updated).seconds}}
as trigger, but that also doesn’t trigger the calculation.
That would work if you use the template sensor, i.e. sensor.energie_real_consumption_watt
If you trigger on sensor.energie_productie_zon_watt, it will trigger only once, as the last_updated will never be updated before sunrise.
I don’t recall saying that. Do you have a link to it handy?
Given a Template Sensor, if it’s template employs now() and other entities, the template will be evaluated at least every minute (because of the use of now()) plus at whatever interval the other entities in the template change state.
If the template employs all domains or an entire domain (like states or states.light) it will be throttled to a per minute evaluation interval.
@koying
the following does actually work, but not always.
I think it has something to do with the fact you said it is only evaluated each minute. So it means that one evaluation the “last updated” should be under 20 seconds, and the next evaluation it should be above 20seconds.
Anyhow, I will change it to 120 this evening and do tests if the solar panels are off…
I believe the observation I made in that post also applies to this one. The template’s evaluation interval of one minute was too long for the other application (“time resolution is too coarse”). It missed events occurring during the 1-minute interval. That appears to be an issue here as well (the template is checking for a 20-second difference but the calculation is computed every minute).
I wasn’t aware of that because I never participated in this thread (because I have no interest in it) and only dropped in because you pinged me (and I don’t always respond to pings). Anyway, glad to hear it’s been sorted out.