I have an automation that does a “short” defrost cycle by switching off the compressor for 7 minutes. Relay on cuts off the compressor, Delay 7 minutes, Relay off allows the compressor to turn on again. This is triggered by a sensor that can happen pretty much any time of day when the coils are icing up. So far working so good.
Now, I want to add a “long” 30 minute defrost cycle once daily before sunrise. I’ve got the trigger by sunrise -30 minutes, and the relay on, delay 30 minutes, relay off, but… I’m concerned that if the short defrost cycle is in progress when this longer one gets triggered, it will switch the relay back off at the end of the short cycle and the long cycle won’t happen as intended.
What I think will mitigate this issue is: making the “Relay off” step of the short cycle conditionally executed with: “If Running automations of Defrost 30 min before sunrise is off”
What I’m unclear on is: what does Attribute: “Running Automations” State: “off” really correspond to? Does it mean that the “Defrost 30 min before sunrise” automation is not “current” or active at the moment, or does it mean that the automation is ready and waiting for a trigger to run?
If I could see a timeline of other automations’ “Running Automations” state, that would answer the question directly, but I can’t find how to do that.
You could add a set of conditions to your short cycle so that it won’t ever run in a time range that would interfere with the long cycle. Something like
- condition: or
conditions:
- condition: sun
before: sunrise
before_offset: "-00:40:00"
- condition: sun
after: sunrise
after_offset: "00:10:00"
I added 10 minutes on either side of when you described your long cycle as running; you should adjust to whatever suits you.
Note: you can add a before and after in the same Sun condition, but I think that only works if one of them is sunrise and the other is sunset. That’s why I’ve used an Or condition here.
Thanks, that’s a workable thought: conditionally block the whole shorter defrost cycle around sunrise.
This is what I have at the moment with the conditional on the long defrost automation’s state being off, for switching off of the relay. I just don’t know if condition:state state: “off” attribute: current is what I think it is.
Edit: actually, I just confirmed by test, nope. The long defrost isn’t “running” but the conditional below blocked the relay off action of the shorter defrost cycle.
The current attribute of an automation is a count. If is is 0, the automation isn’t running. if it is above 0 it is active. For automations that can run in parallel mode the count can be above 1. By testing the attribute for 0 you can be sure it isn’t active.
An option is to put it all in one automation and set the automation mode to queued. This way only one operation will occur at a time and triggers that occur which the automation is running will be queued and execute when the current operation completes.
Bear in mind that long delays in an automation may not be a good idea - 30 minutes is on the long side. If HA restarts while it is running, for example, the compressor will not switch on again.
For your daily one, maybe a schedule helper, with an automation triggered by it going on and off. For the other a timer helper, maybe, (which can be set to resume when HA restarts) triggering an automation on start and stop.
So, the “short” defrost automation is nominally triggered by a button, but more often it gets triggered when an “ice sensor” passes a threshold - this is the code with the kludgy check to see if the longer defrost is running:
If I didn’t want this defrost cycle to run longer (to guarantee a thorough defrost, not leaving any stubborn ice that might survive a 7 minute cycle), I’d just use the sunrise to trigger the regular defrost automation above, but since it’s longer…
Here’s the ice sensor trigger, it just triggers the same automation with the button, I suppose I could merge them into one more complex automation with two triggers - I also have dashboard interface buttons that do the same (trigger the standard Defrost):
alias: Defrost Because Ice Level is High
description: ""
triggers:
- trigger: numeric_state
entity_id:
- sensor.coils_ice_level
above: 10
conditions: []
actions:
- action: automation.trigger
metadata: {}
data:
skip_condition: true
target:
entity_id: automation.defrost
mode: single
So the standard defrost can be started two three ways (remote-control button or dashboard button or by frost sensor) and the longer defrost just one way (time-based; half-hour before sunrise). Is that correct? Any other ways to start defrosting?
If I understood your requirements correctly, if a long defrost is underway then an attempt to start a short defrost should simply be ignored (to prevent it from prematurely ending the long defrost).
If that’s correct then it means a short defrost started during the 30 minutes before sunrise should be ignored.