[SOLVED - user error] Observation between dev-template and template logic in binary sensor

I have a binary sensor that combines a few entities to determine if the house is occupied. This binary_sensor is on my main home assistant installation. One of the entities is a zwave motion sensor that is associated to an rpi instance running hassio which uses eventstream to send events to the main home assistant. My original plan of using the off/away state as true for all entities did not work correctly because the remote entity disapears from the main home assistant after a period of no activity. This is a known behavior and I’m not aware of a fix that still uses eventstream.

To get around this I reversed my logic for the zwave entity to be not is_state on, assuming even if the entity was not available it would pass as true. Despite this working in dev-template the binary sensor does not correctly show the house as empty presumably because the zwave motion sensor is not a listed entity.

I’m not completely surprised by this, this post is more to see see if others have seen the same behavior between config and dev-template.

binary_sensor:
  - platform: template
    sensors:
      everyone_gone:
        device_class: presence
        value_template: >-
           {{ is_state('cover.garage_door_opener', 'closed')
             and is_state('device_tracker.person1', 'not_home')
             and is_state('device_tracker.person2', 'not_home')
             and not is_state('binary_sensor.dome_motion_detector_sensor', 'on') }}

I can also completely flip the logic and use OR’s and if any are true to get around this - I just wanted to scratch the itch of why the above logic doesn’t work despite the logic testing ok in dev.

This should work. An invalid entity_id where you check it’s state will always resolve false.

Also, you can just use this instead to actually grab the states you care about:

states('binary_sensor.dome_motion_detector_sensor') in ['unknown', 'off', 'away']

Thanks for replying petro. That is another cool way to parse states, I will be filing that one away. I think it was indeed working all along. The negative logic and sensor state were confusing me. The 3 negatives evaluate to true as expected which means the icon would show ‘home’. Home is correct based on the boolean value but I was getting my wires crossed and expected away.

I think all is good now. appreciate the help.