04-28-2024 06:58 AM
Hello everyone.
I am new to coding as a whole. But I adore automations, especially when they work, so I embarked on this path of reading and learning the principles.
I wanted to share my current automation, which I made using the script editor for Google Home, and I want your opinion on it.
I primarily attempted to make this using the "and" and "not" operators, but it does not appear to read my criteria. So I went with the longer path. Could there be another approach to writing this script?
Here's my script
metadata:
name: Living Room - Revamp
description: Turn on the light when someone is in living room
automations:
- starters:
- type: device.state.MotionDetection
device: Living room - Living Room
state: motionDetectionEventInProgress
is: true
condition:
type: time.between
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
before: 07:00 # HH:MM (24 hours format). Adjust time as needed
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
after: 03:50 #
weekdays:
- MON
- TUE
- WED
- THU
- FRI
- SAT
- SUN
actions:
- type: device.command.OnOff
devices:
- Living Room - Living Room
on: true
# The not and or wasn't working. Could be cause of the wrong time.between or command isn't program correctly
- starters:
- type: device.state.MotionDetection
device: Living room - Living Room
state: motionDetectionEventInProgress
is: true
condition:
type: time.between
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
before: 20:40 # HH:MM (24 hours format). Adjust time as needed
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
after: 17:40 #
weekdays:
- MON
- TUE
- WED
- THU
- FRI
- SAT
- SUN
actions:
- type: device.command.OnOff
devices:
- Living Room - Living Room
on: true
Answered! Go to the Recommended Answer.
a month ago
Hello @Drjay18 ,
One recommendation for your automation script to look more clean and understandable is to make use of nested conditional constructs, something like 'or' with 'and'. Currently, we don't seem to be supporting this particular aspect. I would recommend opening up a feature request in this regard on the Public Issue Tracker, so that we can have this capability in our bag.
a month ago
Hello @Drjay18 ,
One recommendation for your automation script to look more clean and understandable is to make use of nested conditional constructs, something like 'or' with 'and'. Currently, we don't seem to be supporting this particular aspect. I would recommend opening up a feature request in this regard on the Public Issue Tracker, so that we can have this capability in our bag.