I’m just starting to try out automations in my setup. The aim is to test when my power tariff (Intelligent Octopus Go) triggers a cheap rate during normal peak hours. The to set up my solar and battery to make best use of the cheap energy. I have a couple that are working for the normal day/night rate turning on/off but haven’t been able to get the peak rate/ad hoc scheduled off peak periods to trigger.
I think this is because one of the conditions I am testing for (zappi__status) is taking a couple of minutes to wind up the spring and change state.
So I am attempting to introduce a delay to allow for this.
I can’t test it until I plug in later and octopus creates a charge schedule (hopefully with some ad hoc periods scheduled).
I have examined the entities concerned over a couple of days and think I have the correct logic for what I’m trying to achieve.
Could I ask those more experienced in yaml them me ( believe me that’s not a high bar) to check if my logic is correct and the syntax (especially my use of quotes) of the yaml will do what I want please?
I’m pretty happy with the actions I need to take on the solar side, it’s the logic and syntax to get the actions triggered that I’m unsure of.
Both yaml files below:
alias: Peak Hours Intelligent Despatching Turns On
description: |-
Test for Intelligent Dispatching on, Zappi is boosting and Peak Rate is on.
Then setup Growatt to charge battery and import all from grid.
trigger:
- platform: state
entity_id:
- binary_sensor.octopus_energy_a_********_intelligent_dispatching
from: "off"
to: "on"
action:
- delay: "00:03:00"
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.iogpeakhours
state: "on"
- condition: state
entity_id: sensor.myenergi_zappi_********_status
state: "Boosting"
- type: turn_on
device_id: 76747b33c758620b3a9c673b2fae7913
entity_id: fe1df43fe54f44aee44f083003607e81
domain: switch
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 0f5d6c23ccadb375b20f1d3c86236066
type: select_option
option: Battery first
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 802dec9df90526f6a03f5e4343144029
type: select_option
option: Enabled
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: number
entity_id: 0e0c82237cb16f866b35290fa49e880b
type: set_value
value: 0
mode: single
alias: Peak Hours Intelligent Despatching Turns Off
description: >-
Test for Intelligent Dispatching off.
Test myenergi Home Charger Status is NOT Boosting
Then setup Growatt to load first. Reset values changed in Peak Hours
Intelligent Despatching Turns ON
trigger:
- platform: state
entity_id:
- binary_sensor.octopus_energy_a_********_intelligent_dispatching
from: "on"
to: "off"
action:
- delay: "00:03:00"
- condition: state
entity_id: binary_sensor.iogpeakhours
state: "on"
- condition: or
conditions:
- condition: state
entity_id: sensor.myenergi_zappi_********_status
state: "Paused"
- condition: state
entity_id: sensor.myenergi_zappi_********_status
state: "Completed"
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: number
entity_id: 0e0c82237cb16f866b35290fa49e880b
type: set_value
value: 100
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 802dec9df90526f6a03f5e4343144029
type: select_option
option: Disabled
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 0f5d6c23ccadb375b20f1d3c86236066
type: select_option
option: Load first
- type: turn_off
device_id: 76747b33c758620b3a9c673b2fae7913
entity_id: fe1df43fe54f44aee44f083003607e81
domain: switch
mode: single
The timeout part says, after 3 minutes of waiting, continue anyways. This could be set to false and the automation would stop running / waiting after 3 minutes.
Personally prefer the wait_for_trigger - as then you get execution of your intended action immediately when triggered. You’re also not (based on how you set it up) going to ‘miss’ the execution if it doesn’t happen to occur within your fixed waiting timeframe. It also still gives you the ability to execute or abort after a fixed timeframe. Super powerful / efficient.
Thanks for that suggestion. It sounds like it would suit my use case.
Can I just check…
Is the logic of that:
IF intelligent_dispatching turns on AND stays on for 3 minutes,
then and only then the conditions are tested and.
If all conditions are met, the actions executed.
Else the automation exits without completing the actions?
So that will wait for both sensor conditions to be met within 5 minutes and carry on with the actions if both are met. If one or the other is not met within the timeout it will continue and not execute the remaining actions?
Sorry if I’m being a bit dim
Trying this out. It doesn’t like the syntax of the wait_for_trigger block as the side bar on the yaml editor goes red and I can’t save it.
It’s somewhere between the wait_for_trigger and continue_on_timeout lines as without them it goes green and can be saved.
Where have I got it wrong?
alias: Test wait for trigger Peak Hours Intelligent Despatching Turns On
description: |-
Test for Intelligent Dispatching on, Zappi is boosting and Peak Rate is on.
Then setup Growatt to charge battery and import all from grid.
trigger:
- platform: state
entity_id:
- binary_sensor.octopus_energy_a_********_intelligent_dispatching
from: "off"
to: "on"
action:
- wait_for_trigger:
- platform: template
value_template: "{{ is_state('sensor.myenergi_zappi_********_status','Boosting') and is_state('binary_sensor.iogpeakhours','on') }}"
timeout: "00:05:00"
continue_on_timeout: true
- type: turn_on
device_id: 76747b33c758620b3a9c673b2fae7913
entity_id: fe1df43fe54f44aee44f083003607e81
domain: switch
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 0f5d6c23ccadb375b20f1d3c86236066
type: select_option
option: Battery first
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 802dec9df90526f6a03f5e4343144029
type: select_option
option: Enabled
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: number
entity_id: 0e0c82237cb16f866b35290fa49e880b
type: set_value
value: 0
mode: single
Although strictly speaking I suppose it should be “WHEN intelligent_dispatching…”. Triggers are single changes of state, it can be confusing to think of them like conditions.
Seems to pass the save test anyway
Am I right to assume the wait_for_trigger doesn’t need to see a change of state to that specified, i.e. if the entity is already in that state it will pass the test?
I ask because it is highly likely that iogpeakhours will already be on when we get here.
No, I don’t think so. The trigger is the change of state. If the state doesn’t change, it won’t fire. You do have the timeout, however - as you have it, the action part of the automation will always run after five minutes, whether or not the test is passed.
The easiest way is to change the state of your sensors in Developer Tools | States. (It’s only a temporary change - they will revert to their real values next time they get an update.)
Is that because I have continue_on_timeout: true
I don’t want the actions to run if the test fails so if I set that to false will that stop the actions if the test fails? My assumption is it will.
I’m trying to implement something along these lines but I can’t get the syntax right.
I think it’s just an indentation issue but I’m damned if I can see it.
Can anyone help and old duffer out and see what’s wrong here please?
alias: Test wait for trigger Peak Hours Intelligent Despatching Turns On
description: |-
Test for Intelligent Dispatching on, Zappi is boosting and Peak Rate is on.
Then setup Growatt to charge battery and import all from grid.
trigger:
- platform: state
entity_id:
- binary_sensor.octopus_energy_a_********_intelligent_dispatching
from: "off"
to: "on"
action:
- if:
- condition: state
entity_id: 'sensor.myenergi_zappi_********_status'
state: 'Boosting'
- condition: state
entity-id: 'binary_sensor.iogpeakhours'
state: 'on'
for:
seconds: 0
then:
- type: turn_on
device_id: 76747b33c758620b3a9c673b2fae7913
entity_id: fe1df43fe54f44aee44f083003607e81
domain: switch
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 0f5d6c23ccadb375b20f1d3c86236066
type: select_option
option: Battery first
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 802dec9df90526f6a03f5e4343144029
type: select_option
option: Enabled
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: number
entity_id: 0e0c82237cb16f866b35290fa49e880b
type: set_value
value: 0
else:
- condition: state
entity-id: 'binary_sensor.iogpeakhours'
state: 'on'
- wait_for_trigger:
- platform: template
value_template: >-
{{ is_state('sensor.myenergi_zappi_********_status','Boosting') }}
timeout: "00:05:00"
continue_on_timeout: false
- type: turn_on
device_id: 76747b33c758620b3a9c673b2fae7913
entity_id: fe1df43fe54f44aee44f083003607e81
domain: switch
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 0f5d6c23ccadb375b20f1d3c86236066
type: select_option
option: Battery first
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: select
entity_id: 802dec9df90526f6a03f5e4343144029
type: select_option
option: Enabled
- device_id: 76747b33c758620b3a9c673b2fae7913
domain: number
entity_id: 0e0c82237cb16f866b35290fa49e880b
type: set_value
value: 0
Oddly it won’t save in HA but if I paste the code into Notepad++ it doesn’t throw any errors?
in HA the save error is
Message malformed: extra keys not allowed @ data[‘action’][0][‘if’][1][‘entity-id’]
If I take out the else section to the end it likes it.