So I have a pump at a weekend house that I want to turn on if I’m there, after 5AM and off again after 23:00.
I have a presence thing that reliably detects when I’m “home” (at the weekend house) and can turn on the relay. Unfortunately, it only triggers when the state changes. So if for some reason, I restart HA, the state comes up “home” so the pump doesn’t turn on. It looks like this:
id: recirc_on
alias: Turn on recirculation pump after 5AM, if we’re here
initial_state: ‘on’
trigger:
platform: state
entity_id: device_tracker.tr60
to: ‘home’
condition:
I’ve changed it to run every 5 seconds (which I know is short but I’m developing a component so I’m doing a lot of restarting) but this way it checks the current state of device_tracker.tr60 and set the pump accordingly. The drawback is it runs a lot, but it also sends an MQTT message to turn on the pump very frequently (though not every 5 seconds, curiously):
id: recirc_on
alias: Turn on recirculation pump after 5AM, if we’re here
trigger:
platform: time
seconds: 5
condition:
condition: and
conditions:
condition: state
entity_id: device_tracker.tr60
state: ‘home’
condition: time
after: ‘05:00:00’
before: ‘23:00:00’
action:
Is there some way to set the initial state of the device tracker to ‘away’ so that it’ll cascade all of my dependent automations to do the right thing on startup? Or is there a better way to do this automation?
I’m not quite sure I understand. Where does the condition get set? I assume you mean the initial state of the automation should be ‘off’ and then some other event turns the automation on?
That’s a good idea actually. I just did added a new automation that triggers on homeassistant start that turns on the pump if we’re “home” and between the correct times.
rabittn: I see what you’re doing there. Yes, that would work. I do like ‘teachingbirds’ solution better.