jah2212
(Joey)
March 10, 2018, 5:09am
1
I have the following two automations which automatically turn on and off a console humidifier based on the humidity in my house.
- id: humidifier_auto_off
alias: Humidifier Auto Off
trigger:
platform: template
value_template: "{{(states.sensor.home_humidity.state | int) > (states.input_number.humidity_input.state | int)}}"
action:
- service: homeassistant.turn_off
entity_id: switch.humidifier
- id: humidifier_auto_on
alias: Humidifier Auto On
trigger:
platform: template
value_template: "{{(states.sensor.home_humidity.state | int) < (states.input_number.humidity_input.state | int)}}"
action:
- service: homeassistant.turn_on
entity_id: switch.humidifier
Is there a way these could be grouped together or combined into a single automation?
I’m still a newbie to Home Assistant so any help would be appreciated.
Yes, but in the case of these particular automations it does not save you much work / space:
- id: humidifier_auto
alias: Humidifier Auto
trigger:
- platform: template
value_template: "{{(states.sensor.home_humidity.state | int) > (states.input_number.humidity_input.state | int)}"
- platform: template
value_template: "{{(states.sensor.home_humidity.state | int) < (states.input_number.humidity_input.state | int)}}"
action:
service_template: >
{% if (states.sensor.home_humidity.state | int) < (states.input_number.humidity_input.state | int) %} homeassistant.turn_on
{% else %} homeassistant.turn_off {% endif %}
entity_id: switch.humidifier
jah2212
(Joey)
March 10, 2018, 5:19am
3
Thank you very much, that’s exactly what I was looking for. And while it doesn’t save a lot of space, it definitely helps to have both of these automations as a single toggle.
1 Like
My OCD just nagged me in to shrinking your code a bit further…
- id: humidifier_auto
alias: Humidifier Auto
trigger:
platform: state
entity_id: sensor.home_humidity
action:
service_template: >
{% if (states.sensor.home_humidity.state | int) < (states.input_number.humidity_input.state | int) %} homeassistant.turn_on
{% else %} homeassistant.turn_off {% endif %}
entity_id: switch.humidifier
From 16 lines to 10
2 Likes