07-15-2023 10:06 AM
Hello all,
just take a look a try to tell me whats wrong. And maybe try write me a funcional script.
I just wanna turn on three hallway light (H1-H3) when I open door on wardrobe, when close turn off.
What is a genuine identification of device - is enough to rename the device in google home or I need to change name in native/original app?
07-16-2023 04:17 PM - edited 07-17-2023 12:30 PM
Wardrobe open, lights on automation:
# ------------------------------------------------------------------------------------------ #
# 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: Wardrobe open, lights on
description: IF the wardrobe (WS1) door contact sensor is opened, THEN the hallway lights (H1-H3) will be turned on
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.
# To add more than one starter, duplicate the "- type" section under "starters".
# If you add multiple starter events, any one of them happening will start the automation
starters:
- type: device.state.OpenClose
state: openPercent
is: 100
device: WS1 - Hallway
# ---- ACTIONS ---- #
# Actions will start when a starter event takes place and all conditions are met.
# Actions will start in the order they appear in the script and with any delay specified.
# To add more than one action, duplicate the "- type" section under "actions".
actions:
- type: device.command.OnOff # Turn the device on or off.
on: true
devices:
- H1 - Hallway
- H2 - Hallway
- H3 - Hallway
Wardrobe closed, lights off automation:
# ------------------------------------------------------------------------------------------ #
# 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: Wardrobe closed, lights off
description: IF the wardrobe (WS1) door contact sensor is closed, THEN the hallway lights (H1-H3) will be turned off
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.
# To add more than one starter, duplicate the "- type" section under "starters".
# If you add multiple starter events, any one of them happening will start the automation
starters:
- type: device.state.OpenClose
state: openPercent
is: 0
device: WS1 - Hallway
# ---- ACTIONS ---- #
# Actions will start when a starter event takes place and all conditions are met.
# Actions will start in the order they appear in the script and with any delay specified.
# To add more than one action, duplicate the "- type" section under "actions".
actions:
- type: device.command.OnOff # Turn the device on or off.
on: false
devices:
- H1 - Hallway
- H2 - Hallway
- H3 - Hallway
07-18-2023 02:13 AM
Yeah, thank you dear friend! Its workin...but, I noticed that sensor in google home gives percentage. 1% when open (I did no see any diffrent value) and 0% when close.
It is possible to set range 1-100 for open an turn lights on?
thx
07-18-2023 08:38 AM
You're welcome.
According to Google Home's OpenClose Trait Schema, contact sensors (closet) are in the same category as window treatments (curtain); simple, single direction open-close devices. Script editor will only allow the 'openPercent' key to be used for contact sensors, and the Google Home app reports the sensor's open/close state in percentages - for simple, single direction open-close devices, anything above 1% is equal to the open state.
References:
OpenClose Trait Schema
https://developers.home.google.com/cloud-to-cloud/traits/openclose#single-direction-open-close
Smart Home Closet Guide
https://developers.home.google.com/cloud-to-cloud/guides/closet
If the automation is running as you intended, then nothing needs to be changed.