cancel
Showing results for 
Search instead for 
Did you mean: 

scrips newbie issue (aqara door sensor X yeelight)

bellete
Community Member

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?

sc1_2.JPGsc1.JPG

3 REPLIES 3

DWB1973
Community Member

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

bellete
Community Member

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

DWB1973
Community Member

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.