Hi Team,
Im just moving over from OpenHAB to HomeAssistant with ~95% success rate.
One thing I wasnt still able to hammer out was the thing with virtual components.
In OH there is a very handy way to create an Item and set status based on rule aka automation. Thats really an OOTB way of managing multiple stati.
In HA it seems a bit more manual and not really straight forward - but thats okay.
Whats my issue here:
I have two zigbee contact sensors to indicate the garage door position. The combination of both sensors values tells me whether the door is open,moving or closed. Based on history Im even able to tell if its opening or closing.
I’ve created a virtual component (GarageDoorStatus) in virtual.yaml
If you are using a third party integration it is best to say so (and link to it) when asking your question. There are a lot and we do not know them all.
So from the integration description you should note this:
Virtual components for testing Home Assistant systems.
All right, I’ve played around with templates but it seems there is a missing piece I dont understand.
That is the snippet I’ve put into configuation.yaml to get both sensors state
sensor:
- platform: template
sensors:
garage_contact_group:
value_template: >-
{% if is_state('binary_sensor.garage_open_contact_sensor', 'Closed') and is_state('binary_sensor.garage_closed_contact_sensor', 'Closed') %}
Closed
{% elif is_state('binary_sensor.garage_open_contact_sensor', 'Open') and is_state('binary_sensor.garage_closed_contact_sensor', 'Open') %}
Open
{% else %}
Doing something
{% endif %}
No matter what state combination (Open/Open, Closed/Closed) thows “Doing Something”
Home Assistant uses device classes to translate states into “pretty” versions for your dashboards and editors. However despite what is shown in the frontend, binary sensor states are always on or off (look in Developer Tools → States to see the untranslated state), which you must use in templates in the backend:
value_template: >
{% if is_state('binary_sensor.garage_open_contact_sensor', 'off') and is_state('binary_sensor.garage_closed_contact_sensor', 'off') %}
Closed
{% elif is_state('binary_sensor.garage_open_contact_sensor', 'on') and is_state('binary_sensor.garage_closed_contact_sensor', 'on') %}
Open
{% else %}
Doing something
{% endif %}