HassioHomeAssistant

nicolaw 22nd August 2021 at 11:37am
HA Hassio Home Automation HomeAssistant IoT TechnicalNotes

The problem: My android tv often goes unavailable because power saving mode etc. I have lights and sound automated to turn on/off according to TV state, so when it changes from 'unavailable' to 'off' or vice versa I get triggers I don't want

binary_sensor:
  - platform: template
    sensors:
      bravia_state:
        value_template: >-
          {% if states('sensor.bravia_tv_state') == 'active' %}
            on
          {% elif states('sensor.bravia_tv_state') == 'standby' %}
            off
          {% else %}
            {{ states('binary_sensor.bravia_state') }}
          {% endif %}

I've gone and created a template binary sensor (note there is new syntax for this I think - but the idea is the same). The tricky part here is that it turns on/off based on known-good values of the TV ('active' and 'standby'). and if the state changes to anything else, it doesn't take that state - it takes its own previous state (hence the

          {% else %}
            {{ states('binary_sensor.bravia_state') }}

which is a reference to itself!). So if the TV goes from standby to unavailable, the template binary sensor just stays in standby. The assumption is that it would report when moving to active.


Related