Background
My air conditioning units are split unit, each of them is controlled by remote / by ESPHome. On the remote, they have “run once only timer”. Here is the example:
At the bottom of the remote, there is TIMER group. If I press, it will cycle through 1h, 2h, 3h timers. If 1h is chosen, the AC will be turned off in 1 hour.
Goal
I want to replicate that functionality but for several air conditioning units. I imagine to be able to choose the AC units from my lovelace dashboard, then type/slide a timer to determine how long should the AC be turned off.
Any suggestion?
Thank you very much for your assistance.
So sorry wrong category. Edited & moved it to the right category.
I think you can achieve that by using the following-
Input select containing the your list of air conditioning units
Input Select - Home Assistant
Input datetime for storing the timer value (configurable from the dashboard)
Input Datetime - Home Assistant
For your reference, you could take a look at tom_l’s setup for his pizza delivery-
Another way to do it is with some helpers, a template sensor and some state triggered automations. I have this timer that switches on my porch light if I’m expecting a food delivery at night:
[Screenshot 2021-08-07 at 12-59-47 Overview - Home Assistant]
I set the time with the slider and turn the switch (input_boolean) on.
Input boolean:
pizza_delivery:
name: Pizza Delivery
icon: mdi:pizza
Input Number:
pizza_delivery_time:
name: Delivery Time
min: 15
max: 120
step: 5
unit_of…
1 Like
If the room is divided by a wall then this is possible, however, if your device is in close proximity and under the same brand you will have a nightmare to setup
1 Like
It can be blocked by covering the side(s) of the IR transmitter using aluminum foil.
1 Like
Fortunately, only 1 air conditioning per room.
Great example @tom_l thanks! Using this, what happen if before the counter reaches 0, my HA crashes? Can the timer know after it starts up?
tom_l
August 13, 2021, 4:17pm
8
Yes it can recover from a restart.
1 Like
I have created an input_boolean as the example made by tom. But it seems the last_changed by input_boolean is not being saved after a restart. The last_changed value is replaced by when home assistant started which would make the timer longer.
Any idea?
tom_l
August 17, 2021, 1:30am
10
Oh sorry, no it won’t recover from a restart. last_changed is set on restart (the state changes from unavailable to something).
123 wrote a post about restoring timers on restart.
Notice of Deprecation
Thanks to the contribution of raman325, starting from Home Assistant version 2022.4, an active or paused timer entity can be restored after a restart . Therefore the restoration technique described in this topic is no longer needed.
This topic remains for historical purposes, in case someone is curious to learn more about the scripting techniques it used to restore active/paused timers. However no further support for it will be provided now that timer restoration is a nat…
1 Like
Alternative method for you-
Create an input_datetime
to be used to input your desired timer (Helpers)
input_datetime:
ac_timer:
name: AC Timer
has_date: false
has_time: true
Create an input_select
containing your list of air conditioner (Helpers). If your climate entity_id
is climate.living_room_ac
, then you write Living Room AC
in the option.
input_select:
ac_list:
name: AC List
options:
- Living Room AC
- Pantry AC
Create an input_boolean
to determine the status of your timer (Helpers)
input_boolean:
ac_timer_status:
name: AC Timer Status
Create a “dummy” automation to turn on
the air conditioning, retrieve last_triggered
, and to turn on input_boolean
. Make sure to turn off
the dummy automation. You will only use automation.trigger
service to call the action of this automation.
alias: 'Timer: Air Conditioning ON'
trigger:
- platform: tag
tag_id: ''
condition: []
action:
- service: climate.set_hvac_mode
data:
hvac_mode: cool
target:
entity_id: >-
climate.{{ states('input_select.ac_list')
| regex_replace(find=' ', replace='_', ignorecase=False)
| lower }}
- service: input_boolean.turn_on
target:
entity_id: input_boolean.ac_timer_status
Create a template sensor
to be used as a countdown timer
template:
- sensor:
- name: Remaining AC Timer
icon: "{{ 'mdi:timer-off' if is_state('input_boolean.ac_timer_status','off') else 'mdi:timer' }}"
state: >-
{% set t = (as_timestamp(state_attr('automation.timer_air_conditioning_on', 'last_triggered'))
+ state_attr('input_datetime.ac_timer', 'timestamp') - as_timestamp(now())) | int %}
{% set r = ([0, t ]|max) if is_state('input_boolean.ac_timer_status', 'on') else 0 %}
{{ '{:02d}:{:02d}'.format(r // 3600, (r % 3600) // 60) }}
Create an automation
to turn off the air conditioning based on the states of the template sensor
alias: 'Timer: Air Conditioning OFF'
trigger:
- platform: template
value_template: >-
{{ states('sensor.remaining_ac_timer') == '00:00' }}
- platform: homeassistant
event: start
condition:
- condition: template
value_template: >-
{{ states('sensor.remaining_ac_timer') == '00:00' }}
- condition: state
entity_id: input_boolean.ac_timer_status
state: 'on'
action:
- service: climate.turn_off
target:
entity_id: >-
climate.{{ states('input_select.ac_list')
| regex_replace(find=' ', replace='_', ignorecase=False)
| lower }}
- service: input_boolean.turn_off
target:
entity_id: input_boolean.ac_timer_status
Create an automation
to prevent changing the AC List
while the timer
is running
trigger:
- platform: state
entity_id: input_select.ac_list
condition:
- condition: state
entity_id: input_boolean.ac_timer_status
state: 'on'
- condition: template
value_template: >-
{{ (as_timestamp(now())-as_timestamp(state_attr('automation.timer_air_conditioning_failsafe', 'last_triggered') | default(0)) | int > 3) }}
action:
- service: input_select.select_option
target:
entity_id: input_select.ac_list
data:
option: "{{ trigger.from_state.state }}"
- service: notify.mobile_app_your_name_here
data:
message: Timer for {{ trigger.from_state.state }} is currently running.
Create a grid card to control your timer.
This will be displayed in the card:
AC List
Input Datetime to control your timer duration
Remaining Timer for your AC
Button to Start/Stop the Automation Timer
type: grid
cards:
- type: entities
entities:
- entity: input_select.ac_list
- entity: input_datetime.ac_timer
- entity: sensor.remaining_ac_timer
show_header_toggle: false
- type: button
tap_action:
action: call-service
service: automation.trigger
service_data: {}
target:
entity_id: automation.timer_air_conditioning_off
hold_action:
action: call-service
service: automation.trigger
service_data: {}
target:
entity_id: automation.timer_air_conditioning_on
icon: mdi:air-conditioner
name: Run AC Timer
columns: 2
square: false
Let me know if it works for you.
3 Likes
It worked!!! Thanks for the help @ardysusilo also @tom_l .
I ended up using automation example from ardysusilo as I can implement it directly without changing much from it.
In the future if I need a timer that can be restored after a restart, I’ll take a look at this topic again (thanks @tom_l ).