Toggle power based on power reading

How can I trigger a Broadlink IR toggle based on a power reading?

I have an Amino set top box connected to a Z-wave powerplug that measures the power usage. For the Amino, only a power toggle IR code is available (so no discrete ON and OFF).

What I’m looking to accomplish:

  1. Switch on the activity ‘watching television’ in HA → turn on the power plug.
  2. If Amino power usage < 5.1: send a power toggle through Broadlink IR.
  3. If Amino power usage > 5.1: do nothing, the Amino is already on.

What is the best way to accomplish this? I think it should be a template of some kind, but what should it look like?

Maybe a template switch like this:

  - platform: template
    switches:
      amino:
        value_template: "{{ sensor.powerplug_woonkamer_power | float > 5.1, 'on' }}"
        turn_on:
          service: switch.broadlink_send_packet_192_168_1_22
          data:  # Power toggle Amino
            packet: 'JgA4AD8zfg8UDwABdhATAAoRPzNsDyYPAAFkDyYAChE/Mm0PJg8AAWQPJgAKED8zbBAlEAABZA8lAA0F'
        turn_off:
          service: switch.broadlink_send_packet_192_168_1_22
          data:  # Power toggle Amino
            packet: 'JgA4AD8zfg8UDwABdhATAAoRPzNsDyYPAAFkDyYAChE/Mm0PJg8AAWQPJgAKED8zbBAlEAABZA8lAA0F'

Then … ? Am I on the right track?

for your value template, I’d amend into:

value_template: "{% if states.sensor.powerplug_woonkamer_power.state | float > 5.1 %}on{% else %}off{% endif %}"

above assumes when value = 5.1, template sensor shows off
For your scenario however, if I understand well, you only want to send the iR command if the power is less than 5.1? If so I’d probably run an automation that triggers on the “watching television” entity and only fires if power is less than 5.1:

- alias: Power Toggle Amino
  trigger:
    - platform: state
      entity_id: watching television entity id to track goes here
      to: "state when above is true"
  condition:
    - condition: template
      value_template: '{{ states.sensor.powerplug_woonkamer_power.state | float < 5.1}}'
  action:
    - service: switch.broadlink_send_packet_192_168_1_22
      data:  # Power toggle Amino
        packet: 'JgA4AD8zfg8UDwABdhATAAoRPzNsDyYPAAFkDyYAChE/Mm0PJg8AAWQPJgAKED8zbBAlEAABZA8lAA0F'

Thanks for your input! It helped me with the correct syntax. It seems to be working now :slight_smile:

1 Like