1v0dev
(Ivo)
September 25, 2021, 6:50am
1
Hi, I have the following automation to sleep my computer at night if all the lights are off:
trigger:
- platform: time
at:
- '01:30'
- '02:00'
- '02:30'
condition:
- condition: and
conditions:
- condition: state
entity_id: light.office
state: оff
- condition: state
entity_id: light.living_room_2
state: оff
action:
- service: script.computer_sleep
mode: single
But the conditions seem to fail even if the state is off. This is what I get from the execution log:
conditions/0/entity_id/0
Executed: September 25, 2021, 02:30:00
Result:
result: false
state: ‘off’
wanted_state: оff
Does anyone have any advice what I am doing wrong?
tom_l
September 25, 2021, 8:34am
2
This is a classic mistake.
off
and on
are booleans.
'off'
and 'on'
are strings.
States are always strings. So put some quotes around your wanted states.
Have a read of this to avoid the other common pitfalls:
https://www.home-assistant.io/docs/configuration/yaml/#common-issues
1v0dev
(Ivo)
September 25, 2021, 11:43am
3
I thought this may be a problem. But how to put that in the visual editor? If I put quotes around the values, it will double them:
- condition: state
entity_id: light.office
state: '''оff'''
If I manually edit the YAML and remove one set of the quotes and save it, it will automatically remove the other and fall back to no quotes at all. Same with double quotes.
koying
(Chris B)
September 25, 2021, 12:45pm
4
The automation GUI automatically insert quotes, so not sure how you ended up not having them unless you edited the automation YAML
condition:
- condition: state
entity_id: binary_sensor.nc_test
state: 'off'