Node Red: toggle switch based on consumption

Hi,

I’m a little lost, using hass for quite some time but still a noob when it comes to automation.
Recently I replaced my living room setup with a new tv and stuff… this setup consumes more than 20w in standby and I wan’t to automate a main power-off solution, using a simple wifi switch.

Can anyone point me in the right direction? I’m able to measure consumption with the switch, and I would like to toggle the switch state when the consumption is <30w for let’s say 5 minutes.

How do I set this up in node red to have a time based rule on the sensor state?

Cheers, mason

I was able to built this with a custom binary template… but I like to have this translated to node red. any ideas?

template:

binary_sensor:
  - platform: template
    sensors:
      media_idle:
        value_template: '{{states("sensor.media_power") < "40"}}'

automation:

- id: '1545238663012'
  alias: media_ausschalten
  trigger:
  - entity_id: binary_sensor.media_idle
     for: 00:05
     from: 'off'
     platform: state
     to: 'on'
   condition: []
   action:
    - service: switch.turn_off
      entity_id: switch.media
- id: '1545238663012'
  alias: media_poweroff_idle
  trigger:
  - below: '40'
    entity_id: sensor.media_power
    for: 00:10
    platform: numeric_state
  condition: []
  action:
  - data:
      entity_id: switch.media
    entity_id: switch.media
    service: switch.turn_off

I don’t know why I always think maximum complicated… this does it aswell and more elegant I guess.
Only thing I don’t get, why does this states the switch under data and once again under action?