cancel
Showing results for 
Search instead for 
Did you mean: 

Automations… if xxx else yyyy

jh9
Community Member

Hi, Basically I’m after a google home automation script that turns lights on (if they are off) and off (if they are on).

When I run the following script it turns the lights on, then off 😐, and on other occasions it seems to do 2 or 3 actions… eg on off on, off on, etc. I assume it’s doing the following starters and actions sequentially

ps the reason for this request is to minimise the growing number of automations I have, an if then else command would half the number of automations needed and simplify favourites and automations tabs on google home

regards

jim

metadata:
name: test lights
description: toggle lights, if off turn on, if on turn off
automations:
# if off turn on
- starters:
- type: device.state.OnOff
device: pendant lights - Kitchen
state: on
is: false
actions:
- type: device.command.OnOff
devices: pendant lights - Kitchen
on: true
# if on turn off
- starters:
- type: device.state.OnOff
device: pendant lights - Kitchen
state: on
is: true
actions:
- type: device.command.OnOff
devices: pendant lights - Kitchen
on: false

3 REPLIES 3

OpethNJ
Community Member

First glance you would want a condition for each that separates so they dont randomly trigger each other.  Could also probably do it with FOR or supressFOR in your starter. 

jh9
Community Member

hi, thanks for the info (i'm just back from hols), i'll google FOR and see what it can do 

jh9
Community Member

I couldn’t find anything to help, I also looked at conditions

i guess “if then else” is not supported which seems rather odd as it’s a basic element of all programming languages I’ve used for the last 50 years…