Script entity field turn on/off no matter its domain

Hi everyone,

I am working on a script to be used in an automation collecting different button triggers. The script should turn on a device (field of the script) if it is on and turn it off if it is on. This should be possible for lights, plugs, fans… I have it working for lights with light.turn_on. Is there a general command to turn on an entity no matter its domain (light, plug, fan…)?

Thanks for your support!

Regards
Jonas

Here is my code:

sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ is_state(entity, 'off') }}"
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: "{{ entity }}"
      - conditions:
          - condition: template
            value_template: "{{ is_state(entity, 'on') }}"
        sequence:
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: "{{ entity }}"
fields:
  entity:
    selector:
      entity:
        multiple: false
    required: true
alias: Button on/off
description: Gerät an machen, wenn es aus ist, und aus machen, wenn es an ist.
icon: mdi:toggle-switch-variant

Yep. Use homeassistant.turn_on instead.

Double check which entities you’re targeting with it, since this can switch on/off almost everything

1 Like

that was easy… thanks! :pray:t2:

1 Like