02-24-2024 09:53 AM
Why is the automation script below having an error thrown: redundant struct
metadata:
name: fitness custom
description: Scripted automation
automations:
starters:
- type: assistant.event.OkGoogle
eventData: query
is: "training time"
- type: device.state.TemperatureControl
state: temperatureAmbient
lessThan: 18C
device: Thermal sensor Wellness - Wellness room
actions:
- type: device.command.ActivateScene # Activate or deactivate a scene.
activate: true
devices: Wintertime Wellness ON
starters:
- type: assistant.event.OkGoogle
eventData: query
is: "training time"
- type: device.state.TemperatureControl
state: temperatureAmbient
greaterThan: 22C
device: Thermal sensor Wellness - Wellness room
actions:
- type: device.command.ActivateScene # Activate or deactivate a scene.
activate: true
devices: Summertime Wellness ON
Answered! Go to the Recommended Answer.
02-26-2024 03:42 PM
In general, all starters are always "or", but they are also a type of conditional because they are basically saying, "If starter, then 'the rest of the script tries to execute'." An "if" inside of another "if" is logically equivalent to an "and". Therefore, by making your ambient temperature a conditional, you will effectively achieve an "and". So your script would look something like this:
metadata:
name: fitness custom
description: Scripted automation
automations:
- starters:
type: assistant.event.OkGoogle
eventData: query
is: training time
condition:
type: device.state.TemperatureControl
state: temperatureAmbient
lessThan: 18C
device: Thermal sensor Wellness - Wellness room
actions:
type: device.command.ActivateScene # Activate or deactivate a scene.
activate: true
devices: Wintertime Wellness ON
- starters:
type: assistant.event.OkGoogle
eventData: query
is: training time
condition:
type: device.state.TemperatureControl
state: temperatureAmbient
greaterThan: 22C
device: Thermal sensor Wellness - Wellness room
actions:
type: device.command.ActivateScene # Activate or deactivate a scene.
activate: true
devices: Summertime Wellness ON
You will notice that the hyphen that you had on "type" isn't necessary (it doesn't hurt either) because there is only one "type" per block now. Also, you don't need quotes in your OkGoogle query because you aren't using any other delimiter like apostrophe.
02-25-2024 02:35 PM
In order to have more than one starter you need a hyphen in front of each occurrence of the word "starter" with the appropriate indenting.
02-25-2024 11:16 PM
Ok, where to put the hyphen??
I haven't seen hyphens in front of starters neither in code examples, nor by the pilot.
02-26-2024 05:43 AM - edited 02-26-2024 06:54 AM
Here is an example:
metadata:
name: Dog or cat notification
description: Testing out the dog and cat sensing
automations:
- starters:
type: device.event.AnimalCatDetection
device: Front Yard camera - Front Yard
actions:
type: home.command.Notification
title: Cat
body: I tawt I taw a puddy tat
members:
- John G - #
- Krista G - #
- starters:
type: device.event.AnimalDogDetection
device: Front Yard camera - Front Yard
actions:
type: home.command.Notification
title: Dog
body: Oh, dog!
members:
- John G - #
- Krista G - #
I should also remind you that in your example in the first starter block if either is true then that action will be performed. In other words, if you say "training time" OR the temperature is less than 18C then you action will be performed. It doesn't seem to me that this is your intent.
02-26-2024 08:44 AM
I can't see the much needed hyphens in your code by the multiple starters.
My identation was also seemed correct.
The error message was about repeating columns error in struct.
Where can i make the logical and formula definition?
02-26-2024 09:13 AM
The hyphen is how YAML stores multiple values for each key. If your familiar with programming it is how YAML stores array values. Without it, the script will see it as redundant or repeated values for the same single variable.
02-26-2024 02:14 PM
Ok, thanks, but how to put AND clause between the starters?
02-26-2024 03:42 PM
In general, all starters are always "or", but they are also a type of conditional because they are basically saying, "If starter, then 'the rest of the script tries to execute'." An "if" inside of another "if" is logically equivalent to an "and". Therefore, by making your ambient temperature a conditional, you will effectively achieve an "and". So your script would look something like this:
metadata:
name: fitness custom
description: Scripted automation
automations:
- starters:
type: assistant.event.OkGoogle
eventData: query
is: training time
condition:
type: device.state.TemperatureControl
state: temperatureAmbient
lessThan: 18C
device: Thermal sensor Wellness - Wellness room
actions:
type: device.command.ActivateScene # Activate or deactivate a scene.
activate: true
devices: Wintertime Wellness ON
- starters:
type: assistant.event.OkGoogle
eventData: query
is: training time
condition:
type: device.state.TemperatureControl
state: temperatureAmbient
greaterThan: 22C
device: Thermal sensor Wellness - Wellness room
actions:
type: device.command.ActivateScene # Activate or deactivate a scene.
activate: true
devices: Summertime Wellness ON
You will notice that the hyphen that you had on "type" isn't necessary (it doesn't hurt either) because there is only one "type" per block now. Also, you don't need quotes in your OkGoogle query because you aren't using any other delimiter like apostrophe.
02-26-2024 07:03 PM
Thanks man.
I did it in parallel on my way, however it was the hard way figuring out on your own.