Help with this binary sensor

- 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 :wink:

Try some extra brackets around the entirety of your first test.

      state: "{{ states('sensor.mi_note_10_sleep_confidence') | float(0) > 93 and is_state('person.tiago', 'home') }}"

1 Like

Thank you both! I 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')

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!