Template binary_sensor based on word value

Hey there! :blush: I’m currently working on setting up a template binary sensor, and I could use a little guidance. My goal is to have this sensor switch on when a different sensor is showing “livingroom” for a continuous minute. While I’m comfortable with values, working with words is new to me. Any chance one of you wonderful folks could lend a hand? Your expertise would be greatly appreciated! :pray:

- binary_sensor:
    - name: "Livingroom Motionsensor"
      state: "{{ states(sensor.jeroen_iphone_ble')|float(0) > 7 }}"
      delay_on:
        seconds: 60

i copy pasted that from one of my other sensors, float needs to go and replaced with “livingroom” so it turns on when i’m 2 minutes downstairs (through bluetooth)

if anyone could help that would be amazing :smiley:


state: "{{ is_state('sensor.jeroen_iphone_ble', 'livingroom') }}"

Thank you very much!!

is it possible to add a “or” statement?


- binary_sensor:
    - name: "Jeroen Woonkamer"
      state: "{{ is_state('sensor.apple_watch_jeroen','woonkamer') }}"
OR
       state: "{{ is_state('sensor.iphone_jeroen','woonkamer') }}"
      delay_off:
        seconds: 20
- binary_sensor:
    - name: "Jeroen Woonkamer"
      state: |-
        {{ is_state('sensor.apple_watch_jeroen','woonkamer') or
        is_state('sensor.iphone_jeroen','woonkamer') }}
      delay_off:
        seconds: 20

oh wow i wasn’t far off haha

Here’s a concise way to do it without using a logical OR. It’s particularly useful when there are more than just two entities.

- binary_sensor:
    - name: "Jeroen Woonkamer"
      state: >
        {{ expand('sensor.apple_watch_jeroen', 'sensor.iphone_jeroen')
          | selectattr('state', 'eq', 'woonkamer') | list | count > 0 }}
      delay_off:
        seconds: 20

ah yeah even more awesome, cause indeed i have more sensors :smiley: