This time I’m trying to automate the exhaust fan in my bathroom, such that it comes on above 65% humidity and goes off again when the humidity drops below 60% and also if someone manually turned it on after five minutes. I’ve stared at this thing until I’m cross-eyed and stupid and can’t see why it doesn’t work. Please, some input?
- id: '4685773456356'
alias: Auto bathroom fan shutoff
trigger:
- platform: template
value_template: "{% if states.sensor.vision_zp3111_multisensor_4in1_relative_humidity.state | float < 60.0 %}true{% endif %}"
- platform: state
entity_id: switch.ge_45609_onoff_relay_switch_switch_3
to: 'on'
for:
minutes: 5
condition:
condition: and
conditions:
- condition: template
value_template: "{% if states.sensor.vision_zp3111_multisensor_4in1_relative_humidity.state | float < 60.0 %}true{% endif %}"
- condition: state
entity_id: switch.ge_45609_onoff_relay_switch_switch_3
state: 'on'
for:
minutes: 5
action:
- service: switch.turn_off
entity_id: switch.ge_45609_onoff_relay_switch_switch_3
- id: '2345677453356'
alias: Auto bathroom fan
trigger:
- platform: template
value_template: "{% if states.sensor.vision_zp3111_multisensor_4in1_relative_humidity.state | float > 65.0 %}true{% endif %}"
action:
- entity_id: switch.ge_45609_onoff_relay_switch_switch_3
service: switch.turn_on
What it does right now is nothing whatsoever, which is what’s baffling me. I even validated the template and it comes back ‘true’ even as I watch the humidity go over 65% and the fan stay off. It’s like HA isn’t even bothering to run it.
What you describe is exactly what I want; I figure there are two reasons for the fan, getting rid of humidity from a shower and getting rid of bad odors. In the case of a shower, it comes on above 65%RH and turns off again below 60%. Perfect. But if I go in there after a Taco Bell binge, I’d turn it on manually expecting that it’ll shut off again five minutes later. If the humidity is above 60% it’ll just trigger again when it drops below that and shut off then.
Thank you! I’d played with it quite a bit and finally come to the conclusion it was spitting out a string rather than a float, and that was why my numeric_state version wasn’t doing anything. I figured the template would work no matter what and so used that. Which is extra weird because HA properly graphs humidity over time, and I’d think it wouldn’t be able to do that if it were actually a string (unless HA converts strings to numeric data for graphing?)
I do kind of want to retain the five minutes condition, since there’s an edge case where I stink up the place while the humidity is only slightly above the threshold; this would result in the fan getting the humidity down, but not the smell. I can run this and if it works, maybe try adding that condition back…kind of reduce the number of possible failure points.
So all entity states are strings, even if they look like something else (like a number.) But the numeric_state trigger will convert the state (and the values provided for above: or below:) to floats, which is why it works.
Yes, definitely add the other condition back in. Not sure what I was thinking when I suggested taking it out. It makes perfect sense for the automation to have both conditions. (I’ll edit the reply above accordingly.)