Hi
I have a garage door (Cover), which gets it’s data from an MQTT sensor. It has two inputs, which indicates the Open, or Closed state. The MQTT sensor data toggles when the garage door opens or closes (it has two sensors on the garage door), as example:
Door Open: sensor.garage_door_open = 0, and sensor.garage_door_closed = 1
Door Closed: sensor.garage_door_open= 1 and sensor.garage_door_closed = 0
Door Interim: sensor.garage_door_open = 1 and Csensor.garage_door_closed = 1
I have config in my sensors.yaml file which describes this and provides me with an Open or Closed status for sensor.garage_door_status. All good.
My issues is have a “Opening” and “Closing” state, to be used in the Cover. In other words, when sensor.garage_door_status was Closed, and the door is an an Interim state (see above), sensor.garage_door_status should be “Opening”. Reverse for “Closing”.
So my thought was to look at the previous state of sensor.garage_door_status, and then on the basis of the MQTT sensors, change the value of sensor.garage_door_status, with an “Opening” and “Closing” status, in addition “Open” and “Close” of the code below.
I have tried template trigger code in configuration.yaml. It doesn’t really work, and I want to determine whether that is actually the approach I should take.
Please assist?
Note: I’m not concerned about MQTT Retain, as that is not the issue here.
- platform: template
sensors:
garage_door_status:
friendly_name: "Garage Door"
value_template: >-
{% if states('sensor.garage_door_open')=="1" and states('sensor.garage_door_closed')=="0" %} Closed
{% elif states('sensor.garage_door_open')=="0" and states('sensor.garage_door_closed')=="1" %} Open
{%
elif
(states('sensor.garage_door_open')=="1" and states('sensor.garage_door_closed')=="1")
or
(states('sensor.garage_door_open')=="0" and states('sensor.garage_door_closed')=="0")
%} Interim
{% else %} Unknown
{% endif %}
icon_template: >-
{% if states('sensor.garage_door_open')=="1" and states('sensor.garage_door_closed')=="0" %} mdi:garage
{% elif states('sensor.garage_door_open')=="0" and states('sensor.garage_door_closed')=="1" %} mdi:garage-open
{%
elif
(states('sensor.garage_door_open')=="1" and states('sensor.garage_door_closed')=="1")
or
(states('sensor.garage_door_open')=="0" and states('sensor.garage_door_closed')=="0")
%} mdi:error
{% else %} mdi:unknown
{% endif %}