I’m new to HA and have set up some automations using blueprints, but now I want something more specific that I can not find a matching blue print for. I want to automate my central ventilation. I found an automation by frenck, ventilation.yaml, that seemed like it was close to what I want and started reading it to understand how it works, then adapt it to my needs. But after making the changes I now get an error when I try to save the changed yaml. Please help me understand how to find what’s wrong.
The error message I get is: Message malformed: Unable to determine action @ data['action'][0]['choose'][1]['sequence'][1]
Can you please help me understand how to relate that action @ data[‘action’][0][‘choose’][1][‘sequence’][1] to a specific line in my script? i.e. I’m not only looking for a corrected script, although that would be appreciated of course :-), but I also want to understand how to read such error messages properly.
This is the yaml I’m trying to save:
alias: "Ventilatie"
description: >-
Controls the central ventilation system of the house.
My central ventilation system is controlled by a Fibrao FGS223
Double Switch 2. My ventilation unit is a Zehnder WHR930, for which
the low speed (1) is permanently on, medium speed (2) is activated
by one of the FGS223's switches and high speed (3) is activated by
the other. When 2 or more speeds are selected at the same time,
the unit will run at the highest of the selected speeds.
This automation has 2 main goals:
- Keep the air quality index in my living room at a healthy level,
- Bring the humidity in the bathroom down after someone has taken a shower.
However, it:
- Switches to low speed (1) when we go to sleep.
id: "c2153826-fa86-4448-91a5-53791f86a5f6"
mode: queued
max_exceeded: silent
trace:
stored_traces: 25
trigger:
- alias: "When Home Assistant starts"
platform: homeassistant
event: start
- alias: "When automations are reloaded"
platform: event
event_type: automation_reloaded
- platform: state
entity_id:
- input_boolean.mode_sleep_house
- input_number.setting_iaq_high
- input_number.setting_iaq_medium
- input_number.setting_humidity_high_bathroom
- input_number.setting_humidity_low_bathroom
- sensor.badkamer_temphum_sensor_humidity
- sensor.bme680_bme680_iaq
from: ~
- alias: "When attic ventilation state changes"
platform: state
id: &ventilation "ventilation"
entity_id:
- switch.washok_ventilatie_medium
- switch.washok_ventilatie_high
variables:
anchors:
- &low_speed
alias: "Turn on ventilation on low speed"
service: switch.turn_off
target:
entity_id:
- switch.washok_ventilatie_medium
- switch.washok_ventilatie_high
- &medium_speed
alias: "Turn on ventilation on medium speed"
- service: switch.turn_on
target:
entity_id: switch.washok_ventilatie_medium
- service: switch.turn_off
target:
entity_id: switch.washok_ventilatie_high
- &high_speed
alias: "Turn on ventilation on high speed"
- service: switch.turn_on
target:
entity_id: switch.washok_ventilatie_high
- service: switch.turn_off
target:
entity_id: switch.washok_ventilatie_medium
action:
choose:
- alias: "Turn off when sleep mode is active
conditions:
- alias: "When the house is in sleep mode"
condition: state
entity_id: input_boolean.mode_sleep_house
state: "on"
sequence: *turn_off
- alias: "Humidity in the bathroom is above the high threshold"
conditions:
- alias: "When the bathroom humidity is above the high threshold"
condition: numeric_state
entity_id: sensor.badkamer_temphum_sensor_humidity
above: input_number.setting_humidity_high_bathroom
sequence: *high_speed
- alias: "IAQ in the living room is above the high threshold"
conditions:
- alias: "When the living room IAQ is above the high threshold"
condition: numeric_state
entity_id: sensor.bme680_bme680_iaq
above: input_number.setting_iaq_high
sequence: *high_speed
- alias: "Humidity in the bathroom is above the low threshold"
conditions:
- alias: "When the bathroom humidity is above the low threshold"
condition: numeric_state
entity_id: sensor.badkamer_temphum_sensor_humidity
above: input_number.setting_humidity_low_bathroom
sequence: *medium_speed
- alias: "IAQ in the living room is above the low threshold"
conditions:
- alias: "When the living room IAQ is above the low threshold"
condition: numeric_state
entity_id: sensor.bme680_bme680_iaq
above: input_number.setting_iaq_medium
sequence: *medium_speed
default: *low_speed
It’s telling you the problem is in the action key, the first element of the list (list indexing starts at zero), in the choose action, in the second item of the choose list, in its sequence key, in the second item of that sequence list.
Note that some things take lists, and if you don’t make it specifically a list in the YAML, it will get converted to a list when the YAML is parsed. E.g., this:
action:
choose:
will automatically get converted to this:
action:
- choose:
Basically, your YAML is incorrect. You might try it out with a YAML parser first. I use this quite often and it’s very helpful, especially with anchors & aliases:
Excellent, thank you. Yes, I was aware that it had to be something syntactically, but couldn’t figure out whether the index into the lists was 0 or 1 based, neither matched my expectations. That automatic conversion into a list is indeed what put me on the wrong foot.
The actual error that got me stuck was simple: a missing " at the end of a string literal. So thank you for the link to that yaml parser.
Although I like a lot of things in HA, I don’t yet understand the choice for yaml for scripts. The resulting scripts have little to no connection with natural language and thus will always be pretty hard to read, let alone write for most people.
I don’t understand why you employed YAML Anchors and Aliases. With just a minor revision to the conditions in choose and there’s no need for anchors and aliases.
In this case, it would be easier to read without the anchors and aliases.
That’s me being a novice, not a consious choice. It was this way in the example I found. This was one of the first examples that seemed somewhat useful and actually made sense to me.
It’s not that easy to just OR the conditions, choose: also has the effect that it evaluates the options in a top-down order: later options in this script do rely on the fact that the options before this one were not matched. If I were to simply OR all conditions together I would have to elaborate a lot more in each individual condition to exclude those previous conditions.
You’re overthinking it. If I had more time, and interest, I would redesign your automation for you (as I have done for many others). Unfortunately, I don’t.
No problem, I’ve got it working the way I want it. I will further expand it from here. I’ve had a similar script running for years in Domoticz, now re-doing it for HA.
For anyone interested, here’s what I’ve got working now. I will later add more conditions like f.e. and emergency mode: full speed when CO is detected, two toilet timers, IAQ sensors in multiple rooms, etc.
alias: "Ventilatie"
description: >-
Controls the central ventilation system of the house.
My central ventilation system is controlled by a Fibrao FGS223
Double Switch 2. My ventilation unit is a Zehnder WHR930, for which
the low speed (1) is permanently on, medium speed (2) is activated
by one of the FGS223's switches and high speed (3) is activated by
the other. When 2 or more speeds are selected at the same time,
the unit will run at the highest of the selected speeds.
This automation has 2 main goals:
- Keep the air quality index in my living room at a healthy level,
- Bring the humidity in the bathroom down after someone has taken a shower.
However, it:
- Switches to low speed (1) when we go to sleep.
Source: https://github.com/frenck/home-assistant-config/blob/a34f1f4a7f8ca9e6e1dbf452744d6f76e7f1bc29/automations/attic/ventilation.yaml
id: "c2153826-fa86-4448-91a5-53791f86a5f6"
mode: queued
max_exceeded: silent
trace:
stored_traces: 25
trigger:
- alias: "When Home Assistant starts"
platform: homeassistant
event: start
- alias: "When automations are reloaded"
platform: event
event_type: automation_reloaded
- platform: state
entity_id:
- schedule.sleep
- input_number.setting_iaq_high
- input_number.setting_iaq_medium
- input_number.setting_humidity_high_bathroom
- input_number.setting_humidity_low_bathroom
- sensor.badkamer_temphum_sensor_humidity
- sensor.bme680_bme680_iaq
from: ~
- alias: "When ventilation state changes"
platform: state
id: &ventilation "ventilation"
entity_id:
- switch.washok_ventilatie_medium
- switch.washok_ventilatie_high
variables:
anchors:
- &low_speed
alias: "Turn on ventilation on low speed"
service: switch.turn_off
target:
entity_id:
- switch.washok_ventilatie_medium
- switch.washok_ventilatie_high
- &medium_speed
- alias: "Turn on ventilation on medium speed"
service: switch.turn_on
target:
entity_id: switch.washok_ventilatie_medium
- alias: "Turn off ventilation high speed"
service: switch.turn_off
target:
entity_id: switch.washok_ventilatie_high
- &high_speed
- alias: "Turn on ventilation on high speed"
service: switch.turn_on
target:
entity_id: switch.washok_ventilatie_high
- alias: "Turn off ventilation medium speed"
service: switch.turn_off
target:
entity_id: switch.washok_ventilatie_medium
action:
choose:
- alias: "Turn off when sleep mode is active"
conditions:
- alias: "When the house is in sleep mode"
condition: state
entity_id: schedule.sleep
state: "on"
sequence: *low_speed
- alias: "High speed if humidity or IAQ is above its high threshold"
conditions:
or:
- alias: "Humidity is above the high threshold"
condition: numeric_state
entity_id: sensor.badkamer_temphum_sensor_humidity
above: input_number.setting_humidity_high_bathroom
- alias: "IAQ is above the high threshold"
condition: numeric_state
entity_id: sensor.bme680_bme680_iaq
above: input_number.setting_iaq_high
sequence: *high_speed
- alias: "Medium speed if humidity or IAQ is above its low threshold"
conditions:
or:
- alias: "Humidity is above the low threshold"
condition: numeric_state
entity_id: sensor.badkamer_temphum_sensor_humidity
above: input_number.setting_humidity_low_bathroom
- alias: "IAQ is above the low threshold"
condition: numeric_state
entity_id: sensor.bme680_bme680_iaq
above: input_number.setting_iaq_medium
sequence: *medium_speed
default: *low_speed