I have created a simple automation that turns on my bathroom fan if my humidity sensor reads above 50%. However, I’d like to reference 10% over the upstairs humidity instead (since my upstairs often reaches much higher humidity during the summer) which is from another sensor. I’d like to do “upstairs humidity value + 10%” in the trigger condition, how can that be done?
alias: Master Bathroom Fan
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.mysa_77d224_current_humidity
above: '50'
condition: []
action:
- type: turn_on
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
- wait_for_trigger:
- platform: numeric_state
entity_id: sensor.mysa_77d224_current_humidity
below: '45'
- type: turn_off
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
mode: single
The upstairs sensor is “sensor.upstairs_humidity”
Thanks!
Hellis81
(Hellis81)
January 26, 2022, 4:19am
2
Use a template trigger:
{{ (states('sensor.mysa_77d224_current_humidity') | int + 10) >= 50 }}
Tinkerer
(aka DubhAd on GitHub)
January 26, 2022, 7:37am
3
trigger:
- platform: template
value_template: >-
{{ states('sensor.mysa_77d224_current_humidity')|float > (states('sensor.upstairs_humidity')|float * 1.1) }}
That will trigger when sensor.mysa_77d224_current_humidity
is more than 110% of sensor.upstairs_humidity
Hellis81
(Hellis81)
January 26, 2022, 7:46am
4
Ahh… That might have been what he was asking about.
I would also remove the wait for trigger and have that as a second trigger.
alias: Master Bathroom Fan
description: ''
trigger:
- platform: template
id: "on"
value_template: >-
{{ states('sensor.mysa_77d224_current_humidity')|float > (states('sensor.upstairs_humidity')|float * 1.1) }}
- platform: numeric_state
id: "off"
entity_id: sensor.mysa_77d224_current_humidity
below: '45'
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: 'on'
sequence:
- type: turn_on
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
default: []
- choose:
- conditions:
- condition: trigger
id: 'off'
sequence:
- type: turn_off
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
default: []
mode: single
The way you have it, if you reload automations when the fan is on then it will not turn off.
Thanks to both of you! I ended up going +10 instead of *1.1 since I really want to be sure to be far enough away from the upstairs humidity.
As for the wait trigger, I have added in a HA start trigger with a condition to check that the humidity is still above the threshold, because the action does indeed get cancelled on system restart (which occurs every morning at 3 AM).
Here’s the final code:
description: ''
trigger:
- platform: template
value_template: >-
{{ states('sensor.mysa_77d224_current_humidity')|float >
(states('sensor.upstairs_humidity')|float +10) }}
- platform: homeassistant
event: start
condition:
- condition: template
value_template: >-
{{ states('sensor.mysa_77d224_current_humidity')|float >
(states('sensor.upstairs_humidity')|float +5) }}
action:
- type: turn_on
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
- wait_for_trigger:
- platform: template
value_template: >-
{{ states('sensor.mysa_77d224_current_humidity')|float <
(states('sensor.upstairs_humidity')|float +5) }}
- type: turn_off
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
mode: single
Hellis81
(Hellis81)
January 26, 2022, 2:56pm
6
Automations are reloaded at other times than just HA restarts.
I strongly advice against delaying automations the way you do here.
1 Like
Thanks for the heads up! Modified accordingly:
alias: Master Bathroom Fan
description: ''
trigger:
- platform: template
value_template: >-
{{ states('sensor.mysa_77d224_current_humidity')|float >
(states('sensor.upstairs_humidity')|float +10) }}
id: 'on'
- platform: template
value_template: >-
{{ states('sensor.mysa_77d224_current_humidity')|float <
(states('sensor.upstairs_humidity')|float +5) }}
id: 'off'
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: 'on'
sequence:
- type: turn_on
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
- conditions:
- condition: trigger
id: 'off'
sequence:
- type: turn_off
device_id: e548352edc304d484cb224d4b2982232
entity_id: switch.master_bathroom_fan
domain: switch
default: []
mode: single