Create button that will Run A/C at set temp and time

I was wondering if someone could help me create an automation that will turn my A/c on a specific temp and run for 3:30 hours @1am after i click a button in lovelace. then the button will reset to off at 5am

alias: Run A/C tonight
description: ''
mode: restart
trigger:
  - platform: state
    entity_id: input_button.run_a_c_tonight
    from: 'off'
    to: 'on'
condition: []
action:
  - service: climate.set_temperature
    data:
      temperature: 64
      hvac_mode: cool
    target:
      entity_id: climate.kitchen

That is my code but i want to trigger the button in lovelave and then have it run at a set time.

So i created a date and time helper:

The i have modified my code to read as this in the automation:

alias: Run A/C tonight
description: ''
trigger:
  - platform: time
    at: input_datetime.a_c_date_and_time
condition: []
action:
  - service: climate.set_temperature
    data:
      temperature: 64
      hvac_mode: cool
    target:
      entity_id: climate.kitchen
mode: restart

The I created a lovelace card that has this code:

type: entities
entities:
  - entity: input_datetime.a_c_date_and_time
  - entity: timer.ac_timer
  - entity: automation.run_a_c_tonight

image

I am hoping when i click the switch it will turn on the automation to run at the time shown, then when the automation is done it will turn the switch back to off.

If anyone else can help that would be awesome.

PS I dont think i need the AC timer cause it is not in my automation

Let’s clarify what your goal is:

  1. Since you have used an Input datetime helper instead of a static time, it seems like you want to be able to adjust to start time. Does the off-time need to be 3.5 hours after the start or at 5am?

For a dynamic off-time, you can use a template trigger to calculate the desired time:

  - platform: template
    value_template: >
      {{ now() >= today_at(states('input_datetime.a_c_date_and_time')) 
      + timedelta(hours = 3.5) }}
    id: Off

For a static 5am off-time, you can use a second Time trigger:

  - platform: time
    at: "05:00:00"
    id: Off
  1. While you can disable and enable automations as you have in your dashboard card, it is generally better to design your automations with conditions so that you don’t need to do that. In your case, you could use an Input boolean helper as part of the conditions of your automation. (In the example below I have used input_boolean.run_ac_tonight)

Once you decide on the off-time and have created the input boolean helper, you can use an automation like the following:

alias: Run A/C tonight
description: ''
trigger:
  - platform: time
    at: input_datetime.a_c_date_and_time
    id: On
  - platform:  ** SEE ABOVE **
    id: Off
condition: []
action:
  - choose:
    - conditions:
        - condition: trigger
          id: On
        - condition: state
          entity_id: input_boolean.run_ac_tonight
          state: 'on'
      sequence:
        - service: climate.set_temperature
          data:
            temperature: 64
            hvac_mode: cool
          target:
            entity_id: climate.kitchen
    - conditions:
        - condition: trigger
          id: Off
      sequence:
        - service: climate.turn_off
          target:
            entity_id: climate.kitchen
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.run_ac_tonight 
    default: []

I want the time that it runs to be static. it needs to start at 1am. It always needs to be on for 3:30 hours. there will never be anytime that the time it starts needs to be adjusted.

For that, you do not need the Input datetime helper, but you should still use the Input boolean I suggested previously.

alias: Run A/C tonight
description: ''
trigger:
  - platform: time
    at: "01:00:00"
    id: On
  - platform: time
    at: "04:30:00"
    id: Off
condition: []
action:
  - choose:
    - conditions:
        - condition: trigger
          id: On
        - condition: state
          entity_id: input_boolean.run_ac_tonight
          state: 'on'
      sequence:
        - service: climate.set_temperature
          data:
            temperature: 64
            hvac_mode: cool
          target:
            entity_id: climate.kitchen
    - conditions:
        - condition: trigger
          id: Off
      sequence:
        - service: climate.turn_off
          target:
            entity_id: climate.kitchen
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.run_ac_tonight 
    default: []

this is the button that i created

alias: Run A/C tonight
description: ''
trigger:
  - platform: time
    at: '01:00:00'
    id: 'On'
  - platform: time
    at: '04:30:00'
    id: 'Off'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'On'
          - condition: state
            entity_id: input_boolean.run_ac_tonight
            state: 'on'
        sequence:
          - service: climate.set_temperature
            data:
              temperature: 64
              hvac_mode: cool
            target:
              entity_id: climate.kitchen
      - conditions:
          - condition: trigger
            id: 'Off'
        sequence:
          - service: climate.turn_off
            target:
              entity_id: climate.kitchen
            data: {}
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.run_ac_tonight
            data: {}
    default: []
mode: restart

I will try it out tonight.

There is no need for an Input button helper… and, as it stands, it isn’t linked to the Input boolean that was suggested. If you just want to use the Input button, you will need to have an automation to toggle the boolean when the button is pressed.

I am confused. I want a button to turn on the automation before i go to bed. and then i want the button to turn off after the cycle is done.

I think the source of the confusion is a misunderstanding of what a button helper actually is. The Input Button helper integration allows you to define buttons that can be pressed via the user interface, and can be used to trigger things, like an automation. But, they do not “turn on” or “turn off”…

Input booleans/toggles turn on and off. They can be switched on and off in the user interface. That is why I have suggested you use an Input boolean helper. You can create Input boolean helpers in the helper editor under the heading Toggle.

Steps to accomplish what has been discussed:

  1. Create an Input boolean (see link above) called input_boolean.run_ac_tonight
  2. Use the automation I provided in post #5 above
  3. Edit your dashboard card as follows:
type: entities
entities:
  - entity: input_boolean.run_ac_tonight

EDIT: Removed unneeded helper entity from card config

ok i have added this as the button

type: entities
entities:
  - entity: input_boolean.new_run_a_c_tonight
  - entity: input_datetime.a_c_date_and_time

But i am thinking i do not need to set the time cause it always to run at the same time of the night

here is the automation:

alias: Run A/C tonight
description: ''
trigger:
  - platform: time
    at: "01:00:00"
    id: On
  - platform: time
    at: "04:30:00"
    id: Off
condition: []
action:
  - choose:
    - conditions:
        - condition: trigger
          id: On
        - condition: state
          entity_id: input_boolean.new_run_a_c_tonight
          state: 'on'
      sequence:
        - service: climate.set_temperature
          data:
            temperature: 64
            hvac_mode: cool
          target:
            entity_id: climate.kitchen
    - conditions:
        - condition: trigger
          id: Off
      sequence:
        - service: climate.turn_off
          target:
            entity_id: climate.kitchen
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.run_ac_tonight 
    default: []

You are correct, I forgot we had removed the Input datetime helper from the automation.

If your kitchen thermostat controls both AC and Heating, one thing to think about for the future is what conditions might be needed to prevent this automation from turning off the heat in the middle of the night. For example:

    - conditions:
        - condition: trigger
          id: Off
        - condition: state
          entity_id: climate.kitchen
          state: 'cool'
      sequence:
        - service: climate.turn_off
          target:
            entity_id: climate.kitchen
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.run_ac_tonight 

It is a nest thermostat and it is in the off position at all times

Different thermostats may post the mode information to different attributes. My thermostat posts the mode to both the state and the hvac_action, others post it to hvac_modes. Just substitute the correct attribute or sensor name and value into the the condition… for example if your thermostat uses hvac_action you would use:

- conditions:
     - condition: trigger
       id: Off
     - condition: state
       entity_id: climate.kitchen
       attribute: hvac_action 
       state: 'cool'
   sequence:
     - service: climate.turn_off
       target:
       entity_id: climate.kitchen
     - service: input_boolean.turn_off
       target:
       entity_id: input_boolean.run_ac_tonight 

I am using a Nest thermostat

You need to check in the Developer Tools > States tool to figure out what the correct attribute for your device is…

It looks like yours should work with hvac_action, as in the example in post #13.

It would be easier to tell definitively if you switch it to cool or heat… ‘off’ can represent either the mode or fan state.

alias: Run A/C tonight
description: ''
trigger:
  - platform: time
    at: '01:00:00'
    id: 'On'
  - platform: time
    at: '04:30:00'
    id: 'Off'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'On'
          - condition: state
            entity_id: input_boolean.new_run_a_c_tonight
            state: 'on'
        sequence:
          - service: climate.set_temperature
            data:
              temperature: 64
              hvac_mode: cool
            target:
              entity_id: climate.kitchen
      - conditions:
           - condition: trigger
             id: Off
           - condition: state
             entity_id: climate.kitchen
             attribute: hvac_action 
             state: 'cool'
         sequence:
           - service: climate.turn_off
             target:
             entity_id: climate.kitchen
           - service: input_boolean.turn_off
             target:
             entity_id: input_boolean.run_ac_tonight 
                  data: {}
    default: []

How does this look?

I don’t see in the automation where the switch i create tells it to stat the automation

You have a stray data: {} and the indentation is off in the second half

Click to Expand
alias: Run A/C tonight
description: ''
trigger:
  - platform: time
    at: '01:00:00'
    id: 'On'
  - platform: time
    at: '04:30:00'
    id: 'Off'
condition: []
action:
  - choose:
    - conditions:
        - condition: trigger
          id: 'On'
        - condition: state
          entity_id: input_boolean.new_run_a_c_tonight
          state: 'on'
      sequence:
        - service: climate.set_temperature
          data:
            temperature: 64
            hvac_mode: cool
          target:
            entity_id: climate.kitchen
    - conditions:
        - condition: trigger
          id: 'Off'
        - condition: state
          entity_id: climate.kitchen
          attribute: hvac_action 
          state: 'cool'
      sequence:
        - service: climate.turn_off
          target:
          entity_id: climate.kitchen
        - service: input_boolean.turn_off
          target:
          entity_id: input_boolean.run_ac_tonight
    default: []

It is the times that start/trigger the automation, and the boolean/switch allows the “turn on” option to execute its actions.

Automation Basics
Automating Home Assistant