07-19-2023 11:55 PM
I am trying to create an automation script which handles all the lights in my dining room and kitchen working from a Hue sensor.
Essentially, what I want to create is from sunrise to 5pm, the lights in my kitchen turn on at 100% and after 5 mins turn back off again
between 5pm and 10pm the lights in my kitchen, dining room and hallway all turn on when motion detected at 100% brightness and after 10pm to sunrise, the same lights all come on but at 15% brightness but im having trouble. The code will all work if I create them in seperate scripts with different before and after times, but surely I can migrate them to one script? Sorry im a bit new to this.
The below code is as far as I got and I get errors on the - type line after the 5pm - 10pm condition relating to indentation errors, but no matter where I put it, it seems to fail.
Would love some thoughts please
metadata:
name: House Lights
description: When motion is detected, turn on the lights, then turn them off after five minutes of stillness.
automations:
- starters:
- type: device.state.MotionDetection
device: Hue motion sensor 1 - Default
state: motionDetectionEventInProgress
is: true
condition:
type: time.between
after: sunrise
before: 5pm
actions:
- type: device.command.BrightnessAbsolute # Adjust device absolute brightness.
brightness: 100
devices:
- Kitchen 1 - Kitchen
- Kitchen 2 - Kitchen
- Bench 1 - Kitchen
- Bench 2 - Kitchen
- Bench 3 - Kitchen
- type: device.command.OnOff
on: true
devices:
- Kitchen LED1 - Kitchen
- Kitchen LED 2 - Kitchen
- type: device.command.BrightnessRelative
brightnessRelativePercent: 100
devices:
- Kitchen LED1 - Kitchen
- Kitchen LED 2 - Kitchen
- type: device.command.ColorAbsolute
color:
name: "bright white"
devices:
- Kitchen LED 2 - Kitchen
- Kitchen LED1 - Kitchen
- starters:
- type: device.state.MotionDetection
device: Hue motion sensor 1 - Default
state: motionDetectionEventInProgress
is: false
for: 5min
actions:
- type: device.command.OnOff
devices:
- Bench 1 - Kitchen
- Bench 2 - Kitchen
- Bench 3 - Kitchen
- Kitchen 1 - Kitchen
- Kitchen 2 - Kitchen
- Kitchen LED 2 - Kitchen
- Kitchen LED1 - Kitchen
on: false
condition:
type: time.between
after: 5:00 pm
before: 10:00 pm
- type: device.command.BrightnessAbsolute
brightness: 100
devices:
- Kitchen 1 - Kitchen
- Kitchen 2 - Kitchen
- Bench 1 - Kitchen
- Bench 2 - Kitchen
- Bench 3 - Kitchen
- Hallway 1 - Hallway
- Hallway 2 - Hallway
- Dining Room 1 - Dining Room
- Dining Room 2 - Dining Room
- Dining Room 3 - Dining Room
- Dining Room 4 - Dining Room
- type: device.command.OnOff
on: true
devices:
- Kitchen LED1 - Kitchen
- Kitchen LED 2 - Kitchen
- type: device.command.BrightnessRelative
brightnessRelativePercent: 100
devices:
- Kitchen LED1 - Kitchen
- Kitchen LED 2 - Kitchen
- type: device.command.ColorAbsolute
color:
name: "bright white"
devices:
- Kitchen LED 2 - Kitchen
- Kitchen LED1 - Kitchen
- starters:
- type: device.state.MotionDetection
device: Hue motion sensor 1 - Default
state: motionDetectionEventInProgress
is: false
for: 5min
actions:
- type: device.command.OnOff
devices:
- Kitchen 1 - Kitchen
- Kitchen 2 - Kitchen
- Bench 1 - Kitchen
- Bench 2 - Kitchen
- Bench 3 - Kitchen
- Hallway 1 - Hallway
- Hallway 2 - Hallway
- Dining Room 1 - Dining Room
- Dining Room 2 - Dining Room
- Dining Room 3 - Dining Room
- Dining Room 4 - Dining Room
on: false
07-20-2023 07:59 AM - edited 07-20-2023 09:38 AM
Is there a reason why you don't just create separate scripts? Even after correcting all of the indentation errors, your struct has duplicate action, condition, and starter fields. I'm not a YAML coder, and unless I'm wrong, I don't think there is a way that you can rearrange this struct so that it would pass the validation check. Have you seen the example scripts?
Example scripted automations
https://developers.home.google.com/automations/example-scripts
Edit: Apparently this can be done but your array structure is incorrect.
Reference:
https://developers.home.google.com/automations/schema/basics#array