Sensor to show wether TV is on or off based on power usage

Hi, I’m trying to get a binary sensor to tell me if the TV is on or off basd on power usage.
Here’s the code:

binary_sensor:
  - platform: template
    name: TV
    sensors:
      tv_status:
        value_template: >-
          {{% if (states.sensor.fibaro_plug_tv_power | int) =< 2 %}off{% else %}on{% endif %}}

I wonder if I’m wrong by using a binary sensor here. Can I achieve this in another way?

Take a look in the docs. The first example (sun_up) is exactly what you need.

yes, have a look at Threshold - Home Assistant

i have many self created binary threshold template sensors, and the same sensors created as threshold sensors. (check your Hassio version, since going forward from 0.61.1 the Threshold sensors changed format)

previous:

- platform: threshold
  name: "Quooker on threshold"
  entity_id: sensor.quooker_keuken_actueel
  type: upper
  threshold: 0.5

current:

- platform: threshold
  name: "Quooker on threshold"
  entity_id: sensor.quooker_keuken_actueel
  upper: 0.5

regular binary sensor:

quooker_on:
  friendly_name: "Quooker:"
  delay_off:
    minutes: 1
  value_template: >-
    {{ states('sensor.quooker_keuken_actueel')|float > 0.5 }}

of course you could also use the Mqtt binary sensor to check the state of the plug:

- platform: mqtt
  name: "Quooker Keuken state bin"
  state_topic: 'macaddress/powerswitch-zwave/430ba8cf/state'
  payload_on: "on"
  payload_off: "off"
#  availability_topic: "home-assistant/window/availability"
#  payload_available: "online"
#  payload_not_available: "offline"
  qos: 0
  device_class: plug
#  value_template: '{{ value.x }}'

depending on the reliability of your system and your use case, ymmv (and you night need both to be sure, as have been forced to experience…).

2 Likes

Probably easier to either use device_tracker to sense it joining your network or media.player state, if yours is supported, which will go from off to on when sensed on your network.