Gentlemen, plz help to set the duration of Condition in sequence in my automation.
Basic scenario - if Humidity Sensor stays below/above particular figure during a set time (I need to point 1 minute, for example), Action should be executed (OFF/ON correspondingly).
Here is my working example, where all conditions are set, but I don’t see any option for the duration.
alias: 'Towel Dryer: HostBath Shelly ON / OFF'
description: 'Turns ON Towel Dryer if humidity is high '
trigger:
- platform: state
entity_id: sensor.sh_khoz_su_vlazhnost
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.sh_khoz_su_vlazhnost
above: '67'
sequence:
- service: switch.turn_on
data: {}
entity_id: switch.sh_khoz_su
- conditions:
- condition: numeric_state
entity_id: sensor.sh_khoz_su_vlazhnost
below: '57'
sequence:
- service: switch.turn_off
data: {}
entity_id: switch.sh_khoz_su
default: []
mode: single
I think you can only use ‘for’ in a trigger as otherwise you’d need to have a full database history on all entities.
If you can’t move the ‘for’ bits into a trigger, I’d create a binary sensor for each condition or combination in a choose.
Please educate me if I’m wrong
I think the best option is to return to 2 automations (ON and OFF) with corresponding condition options.
I used that before, but then decided to utilize one automation instead of separate two.
I have noticed a strong preference to combine automations, this is only necessary when it makes sense to do so.
Most times, because it’s easier to maintain, better to read and you understand it better - stick with the two.
Don’t get me wrong, it’s good to experiment, but keep backups of anything you are playing with so you can revert.
I could have sworn I’d seen a post (maybe by pnbruckner who had done some updating of some things a while back) that said that the for: had been added to all templates. It must have been in relation to just the template trigger.
Well, guys, optimization of automation is a sort of sporting event
It’s like any programming - you feel you did the perfect job when the code is concise!
Thanks for your participation, I am reverting to 2 automations.
alias: 'Towel Dryer: HostBath Shelly ON / OFF'
description: 'Turns ON/OFF Towel Dryer depending on humidity level '
trigger:
- platform: state
entity_id: sensor.sh_khoz_su_vlazhnost
condition: []
action:
- variables:
humidity: '{{ trigger.to_state.state | int }}'
- condition: template
value_template: '{{ humidity > 67 or humidity < 57 }}'
- service: "switch.turn_{{ 'on' if humidity > 67 else 'off' }}"
entity_id: switch.sh_khoz_su
mode: single
The condition within the action confirms the humidity is either greater than 67 or less than 57. If it’s not then the action stops and does not proceed to the service call.
The service call turns the switch on if humidity is above 67 otherwise it turns the switch off.
Thanks!
But where is time “1 minute” considered?
I was about to set timing: automation is intended for towel dryer and the fact that you take away towel periodically should not switch on/off the switch instantly.
Thanks! Looks cool!
Does code else 'off' provide switch.turn_off for condition below: 57? Or should I denote explicitly smth like else if trigger.to_state.state | int < 57 ?
It looks neat, but at first glance not very understandable (if it switches off the device or not in case Humidity is between 57 & 67%)