Start the air conditioner when entering the shower, turn off afterwards

So, I’ve always wanted to get out to the shower, where a warm room temperature will be waiting for me without me needing to turn on the air conditioner manually, here’s my go on it :

  1. I assembled a multi sensor using the great instructions made by @bruhautomation
  2. I wrote the following automation to detect high humidity (hence a shower is in progress) and start the air cond
  3. Within 15 minutes the air cond is automatically shutdown
  4. Please note the condition for automation last trigger - this is to avoid false triggers caused by humidity remaining high after a shower

- alias: Turn Bedroom Air conditioner upon Shower
  trigger: 
    - platform: template
      value_template: >-
        {% if states.sensor.shower_humidity %}
            {% if states.sensor.shower_humidity.state | int > 95 %}
              true
            {% endif %}
        {% endif %}      
  condition:
    condition: and
    conditions: 
      - condition: template
        value_template: "{%if is_state_attr('climate.master_bedroom_ac', 'aux_heat', 'off') %}true{%endif%}"
      - condition: template
        value_template: >-
          {% if states.automation.turn_bedroom_air_conditioner_upon_shower.attributes.last_triggered==None%}
            true
          {% else %}
            {%if as_timestamp(now()) - as_timestamp(states.automation.turn_bedroom_air_conditioner_upon_shower.attributes.last_triggered) | int > 1200 %}
              true
            {% endif %}           
          {% endif %}
      - condition: template
        value_template: >-
          {% if states.sensor.master_bedroom_current_temp %}
            {% if states.sensor.master_bedroom_current_temp.state | int < 23 %}
              true
            {% endif %}
          {% endif %}
  action:
  - service: climate.set_aux_heat
    data:
      entity_id: climate.master_bedroom_ac
      aux_heat: true
  - delay: '00:15:00'
  - service: climate.set_aux_heat
    data:
      entity_id: climate.master_bedroom_ac
      aux_heat: false

- platform: mqtt  
  state_topic: "benita/sensornode2"  
  name: "Shower Humidity"  
  unit_of_measurement: "%"
  value_template: '{{ value_json.humidity | round(1) }}'

This looks great, just what I was looking for.

Could you possibly break it down a little bit? I’m not so well versed with the templates as you clearly are. It looks like the trigger is saying if the humidity is over 95%? Why do you need two if statements to accomplish that?

The first condition has to do with the last time since the automation was triggered, correct? and it hasn’t happened in the past 1200 seconds?

Thanks!

Correct, trigger is humidity >95%

The conditions are

  • Is the air conditioner off
  • Has the automation been triggered since last reboot (==none) or, has it been more than than 20 mins since last triggered ( int > 1200 )
  • Is the temperature less than 23

Because of condition: and each of these three conditions have to be true before the action will run

Exactly as @jivesinger explained :slight_smile:
Is there something else you need me to explain here? feel free to ask @jhavens12

Thanks for the reply @jivesinger and @ohadbenita

What is the benefit of doing this part your way:

- platform: template
  value_template: >-
    {% if states.sensor.shower_humidity %}
        {% if states.sensor.shower_humidity.state | int > 95 %}
          true
        {% endif %}
    {% endif %}    

vs

- platform: template
  value_template: >-
      {% if states.sensor.shower_humidity.state | int > 95 %}
        true
      {% endif %}

I’m not quite sure what that first line does, are you just checking to make sure the sensor exists?

Thanks!

For the best of my understanding it’s exactly what you said, in the first example, when checking first if the sensor exists, the template will always return a value (even if not true when the sensor still doesn’t exist)

This will help in avoiding cases where when the automation is being initialized the sensor hasn’t yet