Add a condition to a script

I only want to send the IR command to turn off the TV if it’s drawing more than 0.5 watts. But I can’t figure out the syntax.

This doesn’t work.

script:
  power_guest_tv_off:
    sequence:
      - service: remote.send_command
        target:
          entity_id: remote.ir1_remote
        data:
          command: b64:JgBeAZCPETYRNxE3EBMRExESEhISERI2EjYRNhETERMRExESERMRExE3ERIRExETERMRExATETYSEhI1EjYRNxA3ETcRNhEABdaPkBE2EjYRNhETERMRExETEBMRNxE2ETYSEhISEhERExETERMRNhETERMRExETERIRExE2EhIRNhI2ETYRNxE3EDcRAAXWj48SNhE3EDcRExETERMQExETETYSNRI2ERMREhETERMRExETETYRExETERMQEhISEhISNhATETcRNxA3ETcRNRI2EgAF1o+PETcRNhE3ERMREhESEhISEhI2EDcRNxESERMRExETERMQExE2EhISEhESEhIRExETETYRExE3ETYRNhI2ETYRNxEABdaPkBE3EDYSNhISERIRExETERMRNhE3ETYRExESEhISEhIREhISNhETEBMRExETERMRExA3ERMRNhE2EjYRNhE3ETYRAA0F=
        condition:
          - condition: numeric_state
            entity_id: "sensor.guest_tv_current"
            below: 0.5
            value_template: "{{ states('sensor.guest_tv_current')|float }}"

This is the error message in the log file.

Script with object id 'power_guest_tv_off' could not be validated and has been disabled: Unexpected value for condition: '[OrderedDict([('condition', 'numeric_state'), ('entity_id', 'sensor.guest_tv_current'), ('below', 1), ('value_template', "{{ states('sensor.guest_tv_current')|float }}")])]'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone, a list of conditions or a valid template @ data['sequence'][0]. Got OrderedDict([('service', 'remote.send_command'), ('target', OrderedDict([('entity_id', 'remote.ir1_remote')])), ('data', OrderedDict([('command', 'b64:JgBeAZCPETYRNxE3EBMRExESEhISERI2EjYRNhETERMRExESERMRExE3ERIRExETERMRExATETYSEhI1EjYRNxA3ETcRNhEABdaPkBE2EjYRNhETERMRExETEBMRNxE2ETYSEhISEhERExETERMRNhETERMRExETERIRExE2EhIRNhI2ETYRNxE3EDcRAAXWj48SNhE3EDcRExETERMQExETETYSNRI2ERMREhETERMRExETETYRExETERMQEhISEhISNhATETcRNxA3ETcRNRI2EgAF1o+PETcRNhE3ERMREhESEhISEhI2EDcRNxESERMRExETERMQExE2EhISEhESEh...

Try this:

script:
  power_guest_tv_off:
    sequence:
      - condition: numeric_state
        entity_id: sensor.guest_tv_current
        below: 0.5
      - service: remote.send_command
        target:
          entity_id: remote.ir1_remote
        data:
          command: b64:JgBeAZCPETYRNxE3EBMRExESEhISERI2EjYRNhETERMRExESERMRExE3ERIRExETERMRExATETYSEhI1EjYRNxA3ETcRNhEABdaPkBE2EjYRNhETERMRExETEBMRNxE2ETYSEhISEhERExETERMRNhETERMRExETERIRExE2EhIRNhI2ETYRNxE3EDcRAAXWj48SNhE3EDcRExETERMQExETETYSNRI2ERMREhETERMRExETETYRExETERMQEhISEhISNhATETcRNxA3ETcRNRI2EgAF1o+PETcRNhE3ERMREhESEhISEhI2EDcRNxESERMRExETERMQExE2EhISEhESEhIRExETETYRExE3ETYRNhI2ETYRNxEABdaPkBE3EDYSNhISERIRExETERMRNhE3ETYRExESEhISEhIREhISNhETEBMRExETERMRExA3ERMRNhE2EjYRNhE3ETYRAA0F=

Condition before the thing you’re controlling, no need for the value_template, entity_id shouldn’t be quoted.

1 Like

That fixed it. Thank you so much!!!