Hello… Got a weird one that I’ve been fighting for the past few days. I have a garage door monitor/controller that I built using a Wemos D1 Mini (irrelevant, but background info) and it’s working great, except for the fact that the reed-switch sensors I’m using are NC (normally-closed), rather than NO (normally-open). So, the switch status from the mqtt sensor comes back as “on” when the door is closed, and “off” when it is NOT closed (open). My problem is that in my hass Glance Card, it highlights the switch when it is “on” (door is closed), rather than when it is “off” (open)–see “Garage Open” entry in example (the garage door is currently closed).
Obviously, I want it to highlight the door (and change the icon) when it is open, instead of when it is closed. So I’ve created binary_sensor.garage_door_status
(on the far right, in the example), which correctly shows the door closed. But for the life of me, I cannot get it to change to a highlighted door-open icon. Here is my configuration for this sensor
:
binary_sensor:
## platform for monitoring garage door open status...
- platform: template
sensors:
garage_door_status:
friendly_name: Garage Door Status
device_class: garage_door
value_template: >-
{% if is_state("switch.tasmota2", "on") %} "Closed"
{% else %} "Open"
{% endif %}
icon_template: >-
{% if is_state('binary_sensor.garage_door_status', 'open') %}
mdi:garage-alert-variant
{% else %}
mdi:garage-variant
{% endif %}
From the rather sparse binary_sensor
documentation, I’m lead to believe that with the above template implemented, every time the switch.tasmota2
sensor changes state the binary sensor should change, as well as the icon. However, that is not working. Can someone see anything in the code that I’ve missed? I’ve scoured the forums looking for examples, but everything seems to fit. It’s just not working…
I’ve even tried setting automations to take care of the issue as well, and used notifications to help track the flow, as you can see here:
# ***************** Garage Door Status ****************
automation garage_closed:
alias: Garage door closed state
trigger:
- platform: state
entity_id: switch.tasmota2
to: "on"
action:
- service: notify.notify
data:
message: "Garage door is closed. Current bs state: {{ states('binary_sensor.garage_door_status') }}"
- service: switch.turn_off
data:
entity_id: binary_sensor.garage_door_status
# set: "Closed"
icon: mdi:garage-alert-variant
automation garage_open:
alias: Garage door open state
trigger:
- platform: state
entity_id: switch.tasmota2
to: "off"
action:
- service: notify.notify
data:
message: "Garage door is open. Current bs state: {{ states('binary_sensor.garage_door_status') }}"
- service: switch.turn_on
data:
entity_id: binary_sensor.garage_door_status
# set: "Open"
icon: mdi:garage-alert-variant
But I only ever receive the closed notifications.
I even tried setting the automation to use the binary sensor, rather than the mqtt switch, but then I get nothing at all. The state of the binary sensor never changes, and that’s the problem. Have tried everything I can think of, including Home Assistant reboot. Would greatly appreciate some help here. I’m guessing that I’m either not understanding binary sensors correctly, or I’ve completely missed something in the documentation and forums.
Thanks in advance for any help…