Tuesday
Hi everyone,
I'm having some trouble getting my Google Assistant automation script to work correctly. I'm trying to adjust the color temperature of my lights based on the time of day, but it's not behaving as expected.
Here's my current script:
# ------------------------------------------------------------------------------------------ #
# Lines starting with “#” are comments and will be ignored by the automation.
# Indentation determines hierarchy within the script.
# Visit g.co/home/script-editor-docs for full documentation.
# ------------------------------------------------------------------------------------------ #
metadata:
name: Daily Light Routine # Choose a short name that summarizes your automation
description: Adjusts light brightness and color temperature based on time of day. # Write a detailed description
automations:
# "starters" and "actions" are required; "conditions" are optional.
# Use Ctrl + Space to see autocomplete suggestions.
# ---- STARTERS ---- #
# Starters describe events that will start the automation.
# Today, you have two starters: time-based and state change.
starters:
- type: time.schedule
at: 00:00:00 # Midnight
- type: time.schedule
at: 07:00:00 # 7 AM
- type: time.schedule
at: 09:00:00 # 9 AM
- type: time.schedule
at: 17:00:00 # 5 PM
- type: time.schedule
at: 18:00:00 # 6 PM
- type: time.schedule
at: 24:00:00 # Midnight (duplicate for clarity)
- type: time.schedule
at: 09:00:00 # Midnight
- type: time.schedule
at: 17:00:00 # 7 AM
- type: device.state.OnOff # The basic on and off functionality for any device that has binary on and off, including plugs and switches as well as many future devices.
device: Hallway - Hallway # The basic on and off functionality for any device that has binary on and off, including plugs and switches as well as many future devices.
state: on
# Whether a device with an on/off switch is on or off. <code>true</code> if the device is on, <code>false</code> if the device is off. [available operators: is, isNot]
is: true
# ---- CONDITIONS ---- #
# You don't have any conditions for now, so delete this section.
# ---- ACTIONS ---- #
# Actions will start when a starter event takes place.
actions:
- type: device.command.ColorAbsolute # Sets the color to the specified hue. When the color is set on a device that is off, the device powers on, and the [`OnOffState.state`](./on_off_state) changes to reflect this. Likewise, when brightness is set to 0, the device powers off and the [`OnOffState.state`](./on_off_state) changes accordingly.
# Color to set.
device: Hallway - Hallway
color: {{ (now.hour >= 0 and now.hour < 7) or (now.hour >= 18 and now.hour <= 23) ? 2200 : (now.hour >= 7 and now.hour < 9) ? 6500 : (now.hour >= 9 and now.hour < 17) ? 4000 : 3000 }}
# Service to control the lights
- type: device.command.BrightnessAbsolute
device: Hallway- Hallway
brightness: | # Set brightness based on time
{{ (now.hour >= 0 and now.hour < 7) or (now.hour >= 18 and now.hour <= 23) ? 1 : (now.hour >= 7 and now.hour < 9) or (now.hour >= 9 and now.hour < 17) ? 100 : (now.hour >= 17 and now.hour < 18) ? 60 : 20 }}
Any help would be greatly appreciated.