Help with an automation

# turn tv light on when tv goes on
  - alias: Auto tvlight on
    trigger:
      platform: numeric_state
      entity_id: switch.red_room_switch
      value_template: '{{ states.switch.red_room_switch.current_power_mwh }}'
      above: 30000
    action:
      service: light.turn_on
      entity_id: light.tvlight
  - alias: Auto tvlight off
    trigger:
      platform: numeric_state
      entity_id: switch.red_room_switch
      value_template: '{{ states.switch.red_room_switch.current_power_mwh }}'
      below: 30000
    action:
      service: light.turn_off
      entity_id: light.tvlight

The idea is to detect when my TV is not asleep by the current power draw (itā€™s plugged into a wemo insight switch) and use that to switch on/off a light.

Iā€™m getting the error ā€œValue cannot be processed as a numberā€. Iā€™m guessing that this is because I chose numeric_state as a platform and the state of switch.red_room_switch is on/off. The value I want to use to control the light is actually a state attribute of the switch.

How should I configure this to make it work?

You could create a template sensor to determine whether the value is above 30000 mwh. That sensor will return a true or false state. Then use state instead of numeric state and the value of ā€˜Trueā€™ or ā€˜Falseā€™ as the trigger. Just remember that the case has to be ā€˜Trueā€™ or ā€˜Falseā€™, not ā€˜trueā€™ or ā€˜falseā€™. That screwed me up doing a similar automation.

Does it work if you change the following?

Change

value_template: '{{ states.switch.red_room_switch.current_power_mwh }}'

to

value_template: '{{ state.attributes.current_power_mwh | int }}'

Great clues from both of you. The winning answer looks like:

# turn tv light on when tv goes on
  - alias: Auto tvlight on
    trigger:
      platform: template
      value_template: '{{ states.switch.red_room_switch.attributes.current_power_mwh > 30000 }}'
    action:
      service: light.turn_on
      entity_id: light.tvlight
  - alias: Auto tvlight off
    trigger:
      platform: template
      value_template: '{{ states.switch.red_room_switch.attributes.current_power_mwh < 30000 }}'
    action:
      service: light.turn_off
      entity_id: light.tvlight
2 Likes