cancel
Showing results for 
Search instead for 
Did you mean: 

Script Editor And Condition.

yodatom10
Community Member

I have a night time script that shuts down the house once we've gone to bed. I have multiple starting triggers just in case we aren't in bed/home at the original trigger point. I've also built in a condition block to prevent it from running over and over. However the script is continuing to do so. Doing some debugging the first condition(Presence sensing) is working correctly however it seems that the second part(And) of this condition is not working as I expect:

 

`condition:`

 

`type: and`

 

`# "AND" together two or more conditionals`

 

`conditions:`

 

`- type: home.state.HomePresence`

 

`state: homePresenceMode`

 

`# [available operators: is, isNot]`

 

`is: HOME`

 

`- type: device.state.ArmDisarm # For devices such as security systems that support arming and disarming, this indicates whether the device is armed or disarmed.`

 

`state: isArmed`

 

`is: false`

 

`device: ADT - Coat Closet`

 

 

 

Does anyone have any ideas on why this condition is still returning as TRUE where it should return as false after the first execution? Especially seeing part of the script is setting the security system:

 

 

 

`- type: device.command.ArmDisarm # Set the alarm level of the device.`

 

`# <code>true</code> to arm the device, <code>false</code> to disarm. [Available parameter options: arm, cancel, armLevel]`

 

`arm: true`

 

`devices: ADT - Coat Closet`

 

`armLevel: NIGHT`

 

 

 

TIA!

3 REPLIES 3

GoogleDevForum
Solutions Expert
Solutions Expert

Thanks for sharing. Can you please provide the full automation script for us to better understand the issue?

Sure:

# ------------------------------------------------------------------------------------------ #

# 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: Good Night # Choose a short name that summarizes important starters and actions, like “Sunset lights”.

  description: Locks Doors, Arms security,lowers temp , turns off lights and starts downstairs vacuum

 

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: time.schedule

      # Required. Time to schedule automation. 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)

      at: 11:00 PM # HH:MM XM (12 hours format). Adjust time as needed

      # Optional. Days of the week to run automation on.

      weekdays:

        - MON

        - TUE

        - WED

        - THU

        - FRI

        - SAT

        - SUN

 

    - type: time.schedule

      # Required. Time to schedule automation. 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)

      at: 12:00 am # HH:MM XM (12 hours format). Adjust time as needed

      # Optional. Days of the week to run automation on.

      weekdays:

        - MON

        - TUE

        - WED

        - THU

        - FRI

        - SAT

        - SUN

 

    - type: time.schedule

      # Required. Time to schedule automation. 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)

      at: 1:00 am # HH:MM XM (12 hours format). Adjust time as needed

      # Optional. Days of the week to run automation on.

      weekdays:

        - MON

        - TUE

        - WED

        - THU

        - FRI

        - SAT

        - SUN

    - type: time.schedule

      # Required. Time to schedule automation. 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)

      at: 2:00 am # HH:MM XM (12 hours format). Adjust time as needed

      # Optional. Days of the week to run automation on.

      weekdays:

        - MON

        - TUE

        - WED

        - THU

        - FRI

        - SAT

        - SUN

 

  # ---- CONDITIONS ---- #

  # Conditions are optional. Delete this section if it’s empty.

  # Conditions will prevent an automation from starting if the conditions aren’t met.

  # See g.co/home/script-editor-docs for documentation about how to use logical operators like “and”, “or”, and “not”.

  condition:

    type: and

    # "AND" together two or more conditionals

    conditions:

      - type: home.state.HomePresence

        state: homePresenceMode

        # [available operators: is, isNot]

        is: HOME

      - type: device.state.ArmDisarm # For devices such as security systems that support arming and disarming, this indicates whether the device is armed or disarmed.

        state: isArmed

        is: false

        device: ADT - Coat Closet

 

  # ---- 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.

      # Whether to turn the device on or off.

      on: false

      devices:

        - Front Yard Lights - Front Yard

        - Master Bathroom Lights - Master Bathroom

        - Garage Lights - Garage

        - Entryway Lights - Entryway

        - Family Room Lights - Family Room

        - Kitchen Lights - Kitchen

        - Stairway Lights - Stairway

        - Office Light overhead - Office

        #- Parents Room Overhead - Parents Room

        - Master Bedroom Lights - Master Bedroom

        - Dining Room light - Dining Room

        - Front Yard Fountain - Front Yard

        - Entryway Fountain - Entryway

    - type: device.command.LockUnlock # Lock or unlock the device.

      # <code>true</code> to lock the device, <code>false</code> to unlock.

      lock: true

      devices: Garage Entry Lock - Garage

    - type: device.command.ArmDisarm # Set the alarm level of the device.

      # <code>true</code> to arm the device, <code>false</code> to disarm. [Available parameter options: arm, cancel, armLevel]

      arm: true

      devices: ADT - Coat Closet

      armLevel: NIGHT

    - type: device.command.StartStop # Start or stop the device.

      # <code>true</code> to start device operation, <code>false</code> to stop.

      start: true

      devices: Jojoba - Dining Room

 

    - type: home.command.Notification # Send a notification to the specified home members.

      # Title of the notification. [Available parameter options: title, body, members]

      title: Debug

      body: "Good Night Automation has just ran"

      members: #

 

    - type: device.command.ThermostatTemperatureSetpoint # Set the target temperature for a ther

mostat device.

      # Target temperature setpoint.

      thermostatTemperatureSetpoint: 70F

      devices: Thermostat - Entryway

 

 

Thanks for sharing the full script. We weren’t able to reproduce the issue on our end using virtual devices in the Google Home Playground. We used the same condition structure, and the script did not run again when the presence was set to HOME and the security system was already armed:

condition:
type: and
conditions:
- type: home.state.HomePresence
state: homePresenceMode
is: HOME
- type: device.state.ArmDisarm
state: isArmed
is: false
device: securitysystem - Entryway

How do you determine whether the script is running more than once?