The automation ran this morning and correctly got to this bit of code and the trigger never happened.
I was expecting it to wait the 5 minutes and exit if the trigger doesn’t happen.
But the automation was still running (waiting?) hours later.
What have I done wrong?
What you created will trigger when the template’s value changes from false to true and remains true for at least 5 minutes (that’s what the for option does).
That triggering requirement wasn’t fulfilled so wait_for_trigger continues to wait.
If you don’t specify a value for timeout then there’s no default value and it will wait indefinitely.
I suggest provide a value for timeout that is greater than the value of for. Or remove the for option and simply use timeout. The choice depends on how you want the trigger to behave.
required key not provided @ data[‘actions’][0][‘then’][0][‘else’][1][‘wait_for_trigger’][0][‘trigger’]
One thing I’m wondering. Should the template be a value_template as I have or should it be a wait_tmplate and I do away with the wait_for_trigger line?
As you can probably tell, I’m a complete novice.
I think I may have other problems in the code which is confusing the issue here.
So, I am copying the complete YAML for the automation here. I think I have commented it so that it’s clear what I’m trying to achieve.
The current error is
Message malformed: Unable to determine action @ data[‘actions’][0][‘then’][0][‘else’][1]
The complete code is as follows, any pointers as to what I doing wrong or a better way to achieve this appreciated…
alias: IOG intelligent Despatching Turns On with timeout
description: >-
Trigger octopus_energy_a_********_intelligent_dispatching ON, if peak hours is
ON and Zappi is boosting or peak hours is OFF.
Then setup Growatt to charge battery and import all from grid.
triggers:
- entity_id:
- binary_sensor.octopus_energy_a_********_intelligent_dispatching
from: "off"
to: "on"
trigger: state
conditions: []
actions:
# Check if Peak Hours
- if:
- condition: state
entity_id: binary_sensor.iogpeakhours
state: "on"
for:
seconds: 0
then:
# If Peak Hours Check if Charging is taking place
if:
- condition: state
entity_id: sensor.myenergi_zappi_********_status
state: Boosting
# If Peak Hours and Charging then run script
then:
- action: script.turn_on_growatt_battery_first
else:
# In case charging didn't turn on quickly enough wait 5 mins formit to turn on
- condition: state
entity_id: binary_sensor.iogpeakhours
state: "on"
- wait-for-trigger:
- value_template: >-
{{ is_state('sensor.myenergi_zappi_********_status','Boosting')
}}
timeout: "00:05:00"
trigger: template
# If charging doesn't turn on do nothing and quite the automation
# But, if charging does turn on then run the script
continue_on_timeout: false
- action: script.turn_on_growatt_battery_first
else:
# If it's not Peak Hours run the script
- condition: state
entity_id: binary_sensor.iogpeakhours
state: "off"
- action: script.turn_on_growatt_battery_first
data: {}
mode: single
Data at the end. Square brackets not curly ones. It complaiing it does not understand the data tag so scan through your code for anomalies focusing on data: entries:… Those curly brackets there are definitely an anomaly.
OK, I’m still having trouble with this.
So, I am trying a slightly different tack.
I currently have one automation for “intelligent despatching” turning on and one for it turning off. With different actions depending on the state of the charger and if it’s peak or off peak hours.
I’ve decided to try to split the peak and off peak hours actions into two different automations adding the “intelligentoffpeakhours” as a condition in each (on for one and off for the other).
The code I have for the peak hours automation is looking much simpler but I still can’t get it right. It throws the error
Message malformed: Unable to determine action @ data[‘actions’][0][‘else’][0]
I’ve tried every combination of indenting I can think of.
What’s wrong with this…
alias: Intelligent Despatching turns on During Peak Hours
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.octopus_energy_a_********_intelligent_dispatching
from: "off"
to: "on"
conditions:
- condition: state
entity_id: binary_sensor.iogpeakhours
state: "on"
actions:
- if:
- condition: state
entity_id: sensor.myenergi_zappi_********_status
state: Boosting
# If Peak Hours and Charging then run script
then:
- action: script.turn_on_growatt_battery_first
else:
# In case charging didn't turn on quickly enough wait 5 mins for it to turn on
- wait-for-trigger:
- value_template: >-
{{ is_state('sensor.myenergi_zappi_********_status','Boosting')
}}
timeout: "00:05:00"
trigger: template
# If charging doesn't turn on do nothing and quite the automation
# But, if charging does turn on then run the script
continue_on_timeout: false
- action: script.turn_on_growatt_battery_first
mode: single
Do I need a data: [ ] line? If so what for and where.
Sorry if I’m being dim here, I thought if I could get a fairly simple one right I could try and amalgamate them later.
Are you using the Automation Editor? Because it will help you avoid making the kind of mistakes you’re experiencing.
BTW, your latest posted example still uses hyphens instead of underscores.
I strongly recommend you use the Automation Editor so that you can learn how it composes valid YAML. Repeatedly guessing about indentation isn’t a speedy way to learn it.
Thanks for the tip. I’ve been doing that and think I’m starting to get there.
One question. In the visual editor how do I test for an entity NOT in a given state?
Do I have to use a template? aka
“{{ not is_state(‘sensor.myenergi_zappi_24258124_status’ ‘Boosting’) }}”
I couldn’t get the template idea to work. So, using the visual editor I changed tack.
I am trying to create a wait_for_trigger that triggers on charger state changing from Boosting to another state (of which there are about three.
So, If I trigger on ‘state’ ‘from’ ‘Boosting’ and don’t declare a ‘to’ state like this