I want to write automation something like this:
What I’m doing wrong?
Look at the documentation. Instead of state:
you probably want to:
Ignore that. I didn’t see this was a condition and not a trigger.
There should not be any issue with what you have entered. The error is simply telling you that what has been entered can’t be displayed or edited in the UI editor. The reason is because the UI editor doesn’t support multiple states in a state condition. There is nothing wrong with the code; you can leave it as-is and your automation will work properly.
The history shows the switch has not been in either state for 10 minutes. Try reducing the time in for:
down to a few seconds to see if the condition passes.
I need condition for set to 10 minutes. As showed at screen state was in 2 state: unavailable and off.
I suggested reducing the duration of the for:
down to a few seconds to ensure we understand the problem; not as a permanent solution. If the condition does not pass when the duration is small then there is some other problem that needs corrected.
The condition in your automation will evaluate to true
when the switch has been a single state for 10 minutes AND that state matches either off
or unavailable
.
Keep in mind that each entity has a last_changed
property that can be referred to in order to understand how long the state has been unchanged. This is how HA is able to determine if the for:
duration has been met.
In your case, you want to know if the state of an entity has been in either of two states for a combined duration of 10 minutes. There is no way for HA to know this unless you force it to start tracking that scenario. The way to do that is with a template sensor that holds a single state when your switch is in either of two states:
template:
- binary_sensor:
- name: "Switch unavailable or off"
unique_id: 49b9ff86-29eb-4131-8484-e2a6d0e5c2da
state: "{{ states('switch.kuchnia_glowne') in ['unavailable', 'off'] }}"
You can then use this new binary sensor in your automation condition with for:
10 minutes.
However, this seems like a kludge. What you probably want to do instead is to understand why your switch keeps becoming unavailable and fix that problem instead.