UPDATE as of 0.88.0 the Sensor is now a Binary Sensor, I have Updated the Post to Reflect the Changes

For a long time I have been trying to get my Dumb (Samsung DLNA) TV into Home Assistant. First I got a Broadlink RM Mini and added it to Home Assistant. I was not happy with this since Home Assistant would not be able to tell the state of the TV. This would make it impossible to do automation’s based on weather the TV is turned on or off or run a going to bed script to turn everything off at the end of the day. Luckily I came up with a solution.

I realized that the TV has a network port used to connect to DLNA servers on the network. I was unable to get any of the Home Assistant components to work with the TV so instead I created a ping sensor and set my TV’s IP to static in pfSense:

  - platform: command_line
    scan_interval: 1
    name: TV
    command: ping -W 1 -c 1 192.168.0.104 > /dev/null 2>&1 && echo on || echo off
    device_class: connectivity
    payload_on: "On"
    payload_off: "Off"

I created an Input Boolean for the TV and it’s states:

  tv_off:
    name: 'TV Off'
    initial: off
  tv_on:
    name: 'TV On'
    initial: off
  tv:
    name: 'TV'
    initial: off

These are the automatons used to automate the input Boolean’s to turn the TV on and off and make sure the main Boolean is in sync with the state of the TV the on and off automatons will only run when the TV is in the opposite state:

  - alias: 'TV Off'
    trigger:
        platform: state
        entity_id: input_boolean.tv_off
        from: 'off'
        to: 'on'
    condition:
      condition: state
      entity_id: binary_sensor.tv
      state: 'on'
    action:
      service: switch.turn_off
      data:
        entity_id: switch.tv
  - alias: 'TV On'
    trigger:
        platform: state
        entity_id: input_boolean.tv_on
        from: 'off'
        to: 'on'
    condition:
      condition: state
      entity_id: binary_sensor.tv
      state: 'off'
    action:
      service: switch.turn_on
      data:
        entity_id: switch.tv
  - alias: 'TV On Boolean Set'
    trigger:
        platform: state
        entity_id: binary_sensor.tv
        from: 'off'
        to: 'on'
    action:
      service: input_boolean.turn_on
      data:
        entity_id: input_boolean.tv
  - alias: 'TV Off Boolean Set'
    trigger:
        platform: state
        entity_id: binary_sensor.tv
        from: 'on'
        to: 'off'
    action:
      service: input_boolean.turn_off
      data:
        entity_id: input_boolean.tv
  - alias: 'TV Off Boolean Trigger'
    trigger:
        platform: state
        entity_id: input_boolean.tv
        from: 'on'
        to: 'off'
    action:
      service: input_boolean.turn_on
      data:
        entity_id: input_boolean.tv_off
  - alias: 'TV On Boolean Trigger'
    trigger:
        platform: state
        entity_id: input_boolean.tv
        from: 'off'
        to: 'on'
    action:
      service: input_boolean.turn_on
      data:
        entity_id: input_boolean.tv_on

Finally to reset the Boolean to display the correct state I use:

  - alias: 'TV Off Input Reset'
    trigger:
        platform: state
        entity_id: input_boolean.tv_off
        from: 'off'
        to: 'on'
    action:
      - delay: '00:00:03'
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.tv_off
  - alias: 'TV On Input Reset'
    trigger:
        platform: state
        entity_id: input_boolean.tv_on
        from: 'off'
        to: 'on'
    action:
      - delay: '00:00:03'
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.tv_on

This is my finished result in the Home Assistant UI:

It is possible to detect the status of your TV using any device that connects to Wi-Fi and can be powered by a USB port on your TV because it will turn on and off with the TV. For example you could ping a Chromecast or for an even faster response a NodeMCU

Leave a Reply

Your email address will not be published. Required fields are marked *