Help with A/C automation

Hoping someone can help me work through an automation. I’m still somewhat new at this.

I want to be able to have my AC set a desired temperature if a door has been opened for more than 10 minutes, and once closed, return to the temperature it was set at before the door was opened. I’m using a RadioThermostat CT101 as my thermostat.

Here’s what I have currently. It somewhat works, but is setting the temp of whatever the thermostat value is AFTER the door has been open for 10 minutes, which is obviously higher than it was when it first opened.

- id: '1587171094927'
  alias: Thermostat (door/windows open)
  description: Sets thermostat to 78 after 10 mins of door open
  trigger:
  - entity_id: binary_sensor.playroom_slider
    for: 00:10:00
    platform: state
    to: 'on'
  condition: []
  action:
  - data_template:
      entity_id: input_number.slider1
      value: '{{states.sensor.thermostat_temperature.state | float}}'
    service: input_number.set_value
  - data:
      target_temp_high: 78
      target_temp_low: 69
    entity_id: climate.thermostat_mode
    service: climate.set_temperature
  - data:
      message: Setting temperature to 78 degrees. A door has been open longer than
        10 minutes.
    service: tts.google_translate_say
    entity_id: media_player.living_room_speaker

and to return to the previous state

- id: '1587173645836'
  alias: Thermostat (return to pre-door temp)
  description: Sets thermostat to last temp before door was opened
  trigger:
  - entity_id: binary_sensor.playroom_slider
    platform: state
    to: 'off'
  condition: []
  action:
  - data_template:
      target_temp_high: '{{ states.input_number.slider1.state | float }}'
      target_temp_low: '69'
    entity_id: climate.thermostat_mode
    service: climate.set_temperature

My only thought was to record the temp and set the value every time the door is opened in a separate automation, then call that value in the wait automation. Seems like there would be an easier way.

I see the issue. You want to record the temperature at the start of the 10-minute period, not the end (like it’s currently doing).

Here’s what I suggest:

  • Remove the first action from the automation (the one that stores the temperature sensor’s value in an input_number).
  • Create a new automation that triggers whenever the state of binary_sensor.playroom_slider changes to on for, say, 15 seconds. We use a short period of time (as opposed to none) to prevent the automation from reacting to each and every momentary opening of playroom_slider.
  • Make this new automation’s action the one you removed from your first automation.

Example:

- id: '8675309'
  alias: Set reference temperature
  trigger:
  - platform: state
    entity_id: binary_sensor.playroom_slider
    to: 'on'
    for: '00:00:15'
  - service: input_number.set_value
    data_template:
      entity_id: input_number.slider1
      value: '{{states.sensor.thermostat_temperature.state | float}}'
    

Fifteen seconds is not long enough for the room temperature to rise significantly so the input_number will be set to a desirable “reference temperature”. If the door continues to be left open for the full 10 minutes the other automation kicks in and sets the temperature back to the “reference temperature” recorded 9 minutes and 45 seconds ago.

Thanks, Taras. I’ve also realized that my 2nd automation to restore the temp just restores the temp any time the door is shut, no matter how long it’s open.

Wondering if there is a node-red flow that would be easier to implement. Trying to work through that now.

I don’t understand why that’s a showstopper but you can add a condition to the 2nd automation that checks if the input_number is equal to (or plus/minus 1 degree of) the temperature. If it is then it doesn’t execute the action.

If that’s not good enough, you can use a flag to indicate when the door has been opened for 10+ minutes and then the 2nd automation will only reset the temperature if the flag is set. All of this can be done using an input_boolean to serve as the flag.

  • Set the input_boolean to on in the same automation that triggers when the door is left open for 10 minutes.
  • In your 2nd automation, add a condition that checks if the input_boolean is on. If it is, it proceeds to reset the temperature and then it should set the input_boolen back to off.

Example:

- id: '1587171094927'
  alias: Thermostat (door/windows open)
  description: Sets thermostat to 78 after 10 mins of door open
  trigger:
  - entity_id: binary_sensor.playroom_slider
    for: 00:10:00
    platform: state
    to: 'on'
  condition: []
  action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.flag
  - data:
      target_temp_high: 78
      target_temp_low: 69
    entity_id: climate.thermostat_mode
    service: climate.set_temperature
  - data:
      message: Setting temperature to 78 degrees. A door has been open longer than
        10 minutes.
    service: tts.google_translate_say
    entity_id: media_player.living_room_speaker
- id: '1587173645836'
  alias: Thermostat (return to pre-door temp)
  description: Sets thermostat to last temp before door was opened
  trigger:
  - entity_id: binary_sensor.playroom_slider
    platform: state
    to: 'off'
  condition:
    condition: state
    entity_id: input_boolean.flag
    state: 'on'
  action:
  - data_template:
      target_temp_high: '{{ states.input_number.slider1.state | float }}'
      target_temp_low: '69'
    entity_id: climate.thermostat_mode
    service: climate.set_temperature
  - service: input_boolean.turn_off
    entity_id: input_boolean.flag
1 Like

It’s not really, but somehow it’s getting set to 78 (which is the door open for more than 10 mins temp) at night. I haven’t fully figured out why yet. I think I have a node red flow that will work now. I’ll test it out and post it up if it works. I do appreciate the help and will try your suggestion if the NR flow doesn’t work out.