I have not done any automation before so first I decided to get water circulation to work more meaningfully way. Obviously, circulation is not needed when everybody is asleep. Also, it does not have to be continuous but let’s say 3min on 10 off.
So I set 2 triggers - circulation (morning time) on, and circulation (evening time) off.
When the condition morning time is fulfilled automation should go on.
Then simple actions: turn the smart plug on, delay 3min, turn off, delay 10min, repeat until condition evening time is true.
Straight forward simple logic. Unfortunately, it turns out HA logic is completely different and this does not work What should I do?
alias: Circulation
description: ""
trigger:
- platform: time
at: "09:00:00"
id: Circulation on
- platform: time
at: "22:00:00"
id: Circulation off
condition:
- condition: trigger
id: Circulation on
action:
- service: switch.turn_on
data: {}
target:
entity_id: switch.energy_monitoring_smartplug
device_id: 55c108ed637de06f6151dbeea8c8cff0
- delay:
hours: 0
minutes: 3
seconds: 0
milliseconds: 0
- service: switch.turn_off
data: {}
target:
entity_id: switch.energy_monitoring_smartplug
device_id: 55c108ed637de06f6151dbeea8c8cff0
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- repeat:
until:
- condition: trigger
id: Circulation off
sequence: []
mode: restart
I think you could use something like this:
alias: Circulation
description: ""
trigger:
- platform: time
at: "09:00:00"
id: Circulation on
condition: []
action:
- repeat:
until:
- condition: time
after: "22:00:00"
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.energy_monitoring_smartplug
device_id: 55c108ed637de06f6151dbeea8c8cff0
- delay:
hours: 0
minutes: 3
seconds: 0
milliseconds: 0
- service: switch.turn_off
data: {}
target:
entity_id: switch.energy_monitoring_smartplug
device_id: 55c108ed637de06f6151dbeea8c8cff0
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
mode: restart
HOWEVER, this is a very long running automation. If you restart HA between 9:00 and 22:00 the automation will be abandoned and your circulation could be left on for up to 24 hours.
I’ll try and think of an improved version.
Maybe this will be better:
alias: Circulation
description: ""
trigger:
- platform: time
at: "09:00:00"
id: Circulation on
- platform: homeassistant
event: start
condition:
- condition: time
after: "09:00:00"
before: "22:00:00"
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
action:
- repeat:
until:
- condition: time
after: "22:00:00"
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.energy_monitoring_smartplug
device_id: 55c108ed637de06f6151dbeea8c8cff0
- delay:
hours: 0
minutes: 3
seconds: 0
milliseconds: 0
- service: switch.turn_off
data: {}
target:
entity_id: switch.energy_monitoring_smartplug
device_id: 55c108ed637de06f6151dbeea8c8cff0
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
mode: restart
Your can also use time_pattern as trigger:
trigger:
- platform: time_pattern
minutes: "/13"
So automation runs every 13 Minutes for 3 Minutes and not (as single automation) all day long.
Thanks
I also learned from this that repeat must be before actions despite the fact that everyday logic instills the opposite.
Depends on where the “everyday logic” of your native language chooses to put a verb within a sentence.
Run to the store.
To the store, run.
Repeat this action.
This action, repeat it.
well, in hindsight it is absolutely logical for computer language that action is nested inside repeat. However, based on everyday wisdom, I would not proceed from the language, but really from the logic of the action, in order to repeat something, we must first know what the action is.
The “logic of the action” is to literally ‘repeat these actions’ as opposed to ‘these actions, repeat them’.
Are there two entities being turned on/off or just one? The target
appears to reference two entities.
target:
entity_id: switch.energy_monitoring_smartplug
device_id: 55c108ed637de06f6151dbeea8c8cff0
I think they are remnants from my own first try. When I had no idea why I couldn’t get it to work, I added targets the device as well as smartplug switch as an entity. I actually still don’t know is there any difference.
I understand that you are returning to language-based logic. Action is always more logical to me. When we observe the world around us, action always precedes repetition. So agree to disagree…
If you’re turning on/off one thing then you only need to reference it once, either by its entity_id or device_id (using both is redundant).
Nice sound bite.