Dumonster
(Tiago Dumont)
November 5, 2021, 4:32pm
1
- template
- binary_sensor:
- name: Tiago Sleep
unique_id: tiago_sleep
state: "{{ states('sensor.mi_note_10_sleep_confidence') | float(0) > 93 and (states('person.tiago'), 'home') }}"
delay_on:
minutes: 10
delay_off:
minutes: 5
icon: >
{% if is_state('binary_sensor.tiago_sleep', 'on') %}
mdi:sleep
{% else %}
mdi:sleep-off
{% endif %}
It’s not working and I suspect it has to do with the “and” or my syntax since it works if I remove the “and home” bits. I’ve read all I could find but can’t make it work for some reason.
What am I doing wrong?
Paste it into the Template tab under Developer Tools and you’ll quickly see what works and what doesn’t
Try some extra brackets around the entirety of your first test.
123
(Taras)
November 5, 2021, 5:07pm
3
state: "{{ states('sensor.mi_note_10_sleep_confidence') | float(0) > 93 and is_state('person.tiago', 'home') }}"
1 Like
Dumonster
(Tiago Dumont)
November 5, 2021, 5:12pm
4
Thank you both! I solved with with ==.
123
(Taras)
November 5, 2021, 5:17pm
5
Dumonster:
solved with with ==.
This:
is_state('person.tiago', 'home')
is equivalent to this:
states('person.tiago') == 'home'
However what you originally had was simply invalid:
(states('person.tiago'), 'home')
Dumonster
(Tiago Dumont)
November 6, 2021, 2:56pm
6
Yes, I understand the logic now. states(‘person.tiago’) just returns my current zone while is_state(‘person.tiago’, ‘home’) will return a boolean depending on whether I’m home or not.
Thanks everyone!