which errors to: Invalid config for [sensor]: offset {% if is_state('switch.nofood', 'off') %} 10 {% else %} 6000 {% endif %} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['scan_interval']. Got None. (See /config/configuration.yaml, line 317).
But I do not see the value updated in the configuration.yaml and it also does not seem to be updated. It must be because the scan_interval is not an attribute.
You can’t template or programmatically update the scan interval.
You are half way to the solution though.
Set a really long interval in the configuration (years). And use an automation to call the update entity service (without any data) when you want it to update. The trigger is the tricky part. Maybe something like this (untested):
Thank you you @tom_l for your prompt reply.
So I set scan_interval: 31556926 and tested with the first recommendation.
I switched the nofood to off and:
Triggered by the switch.nofood via template at April 3, 2023 at 10:14:40 PM
Home Assistant Core Integration: Update entity Contact sensor Dog
Finished at April 3, 2023 at 10:14:40 PM (runtime: 0.25 seconds)
What is this secs variable about? I renamed to scan_interval, but also no luck.
The value didnt change in the end. (my automation didnt trigger when opening the door)
It’s just a variable to store the scan interval in, the name does not matter. The timestamp in seconds is divided by this variable and if the remainder is zero the sensor is updated. The variable changes depending on the state of the door. Looks like the trigger template is only updated every minute (so use the second version I posted)…
Because the door state is in the template that will trigger the template to be evaluated too, but the timestamp still has to be evenly divisible by the scan interval for it to trigger.
I had also tested the second version but I had a time constraint mismatch in my automation trigger when the door openes. Now it works as expected. I was waiting for a value change in the configuration.yaml, but that doesnt happen, hence my confusion.
Now I can switch the nofood based on time which drastically limits my api calls
Still not clear though how actually the scan_interval is set since scan_interval is not mentioned anywhere in the automation. Either way thank you!
The scan interval is not changed. It stays the huge number you specified.
The homeassistant update entity service overrides this whenever it is called by the automaton and forces an update of the sensor. That’s all the service does, it does not update the configuration.
Yes, when all conditions are true the actions run. But…
It does not know or do any of those things.
This service: homeassistant.update_entity forces the entity (that you specify in the target) to evaluate its state. The entity ignores any of its usual polling or scan interval settings and does a state update.