In your revised service template, the bedroom and living room variables are identical.
… because they’re also identical in the original service template. Which must be an error.
I think this is one automation that would be dramatically simplified by separating it into two separate automations (one to handle the bedroom fan, the other for the living room).
It took me awhile to the untangle the logic but here’s what it boils down to for the bedroom:
- alias: Bedroom Humidifier toggle
trigger:
- platform: state
entity_id:
- binary_sensor.door_window_sensor_bedroom
- sensor.humidity_bedroom
action:
- service_template: >-
{% set fan = states('fan.humidifier_bedroom') %}
{% set sensor = states('binary_sensor.door_window_sensor_bedroom') %}
{% set humidity = states('sensor.humidity_bedroom')|int %}
{% if fan == 'on' and (sensor == 'on' or humidity > 60) %}
fan.turn_off
{% elif fan == 'off' and (sensor == 'off' or humidity < 45 %}
fan.turn_on
{% else %}
fan.turn_off
{% endif %}
data:
entity_id: fan.humidifier_bedroom
Take a look at a solution I provided for another user. It also involves controlling room humidity within a desired range. It might be of interest to you.