cancel
Showing results for 
Search instead for 
Did you mean: 

How to toggle a light on or off with one command word

CubeLead
Community Member

I've been trying to write a script for my light to turn on when I say "Command word" if the light is off, and to turn off when I say "command word" if the light is on. The script AI cannot create it, and I've been trying to use conditions to no avail. All I need is "if light on --> turn off --- else -->turn on" but in script editor language. Please help!

1 Recommended Answer

MarciaMellow
Community Member

You can do this by using the same starter twice (make sure you use the hyphen in front of the starters as indicated in the following example:

metadata:
  name: Light on/off with same command
  description: Light on/off same command
automations:
  - starters:
      - type: assistant.event.OkGoogle
        eventData: query
        is: Toggle light
    condition:
      type: device.state.OnOff
      device: Light - Living room
      state: on
      is: false
    actions:
      - type: device.command.OnOff
        devices: Light - Living room
        on: true
        
  - starters:
      - type: assistant.event.OkGoogle
        eventData: query
        is: Toggle light
    condition:
      type: device.state.OnOff
      device: Light - Living room
      state: on
      is: true
    actions:
      - type: device.command.OnOff
        devices: Light - Living room
        on: false

 

View Recommended Answer in original post

2 REPLIES 2

No script required. Just a simple Routine. Even though I say "Hey Google, Air conditioner" you can also use any word.

This is my YouTube video from my channel...

https://youtube.com/shorts/5z69ruHrU3I?feature=share

MarciaMellow
Community Member

You can do this by using the same starter twice (make sure you use the hyphen in front of the starters as indicated in the following example:

metadata:
  name: Light on/off with same command
  description: Light on/off same command
automations:
  - starters:
      - type: assistant.event.OkGoogle
        eventData: query
        is: Toggle light
    condition:
      type: device.state.OnOff
      device: Light - Living room
      state: on
      is: false
    actions:
      - type: device.command.OnOff
        devices: Light - Living room
        on: true
        
  - starters:
      - type: assistant.event.OkGoogle
        eventData: query
        is: Toggle light
    condition:
      type: device.state.OnOff
      device: Light - Living room
      state: on
      is: true
    actions:
      - type: device.command.OnOff
        devices: Light - Living room
        on: false