Yet another problem with inverting a binary_sensor

greets all. Obviously unclear on yet more concepts, even after repeated reading of the docs and everyone else’s problems in the Configuration section here.

hassio on an odroid-C2. More info at bottom.

Sensor is a zwave ecolink tilt sensor for a garage door. Zwave controller is an ISY994i-ZW with the community integration.

Diving right in, pertinent sections:

/config/configuration.yaml

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
sensor: !include sensors.yaml
# Configure binary sensors
binary_sensor: !include binary_sensors.yaml   <----

/config/binary_sensors.yaml

platform: template
sensors:
  test_garage_door_invert: 
    value_template: >
      {% if is_state('binary_sensor.test_garage_door_sensor', 'off') %}
         closed
       {% else %}
         open
       {% endif %}
    device_class: garage_door
    friendly_name: "Garage Door Test"
       
  garage_door_invert: 
    friendly_name: "Garage Door"
    device_class: garage_door
    value_template: >
      {% if is_state('binary_sensor.garage_door_sensor', 'off') %}
         closed
       {% elif  is_state('binary_sensor.garage_door_sensor', 'on') %}
         open
       {% else %}
         error
       {% endif %}

the ‘test_garage_door_sensor’ is the one I’m working with for these purposes.

‘off’ from the ISY is garage door closed.
‘on’ from the ISY is garage door opened.

Update: the garage_door device class is correct. I got confused. My embarrassed bad.
exactly backwards (of course) from the device_class: garage_door.

I can see the signal flip from off to on to off to on etc in both the ISY and in the hassio “Developer Tools -> States” binary_sensor.test_garage_door_sensor as I rock the sensor back and forth, so the signal is getting into hassio.

The “Developer Tools -> States” binary_sensor.test_garage_door_invert stays ‘off’

I don’t know how to debug the comm (sockets?) from the actual sensor to the ‘template’.

Can someone(s) more experienced have a look at my template (above) and maybe see what the error or omission is?

thanks in advance.

➜  /config hassio info                 
arch: aarch64
channel: stable
hassos: "2.12"
homeassistant: 0.101.2
hostname: hassio
logging: info
machine: odroid-c2
supervisor: "192"
supported_arch:
- aarch64
timezone: America/Anchorage

FWIW, I’ve added my +1 for an invert flag to the binary_sensor spec. But I am curious why it’s not there already? I’ve been a loooooonng time in industrial controls (long enough to be the designated Cranky Old Guy) and this is the first time I’ve ever seen a binary that didn’t have an ‘invert’ option.

A binary template sensor’s template must return True or False.

You can simplify yours a bit:

  garage_door_invert: 
    friendly_name: "Garage Door"
    device_class: garage_door
    value_template: "{{ is_state('binary_sensor.garage_door_sensor', 'off') }}"

Hold on: When using device_class: garage_door, the doco says:

garage_door : On means open, Off means closed

That is the same that your original sensor already provides, isn’t it? Are you sure you need to invert this sensor?

1 Like

Yah. Right after I posted it dawned on me that I maybe had gotten confused. And I did. The device_class: garage_door is correct for my application (I’ll go back and correct it).

The more fundamental issue of why isn’t the signal inverted remains though. I’m sure that’ll come up in the future.

Thanks!

Just make sure that your binary template sensors only return True or False. In your original attempt you returned closed/open/error which are all interpreted as False.

short answer, (as it turns out) no this particular sensor doesn’t need to be inverted, now that I’m straightened out on the device class.

A binary template sensor’s template must return True or False.

You can simplify yours a bit:

that does. The implications of ‘must return True or False’ simplifies things, thus the simpler code. My more complicated was me following old habits and trying to anticipate all outcomes (garage door is pretty important. Especially at night or when gone!)

Just make sure that your binary template sensors only return True or False. In your original attempt you returned closed/open/error which are all interpreted as False.

Understood now. Thanks for straightening my confusion on this one out.

1 Like