I’m trying to control a switch using adjustable on/off times, with several options:
for example,
I’d like to be able to:
— Choose a time to turn on an entity (example: 2pm (14:00)) — Choose a time to turn off the entity (example: turn off at 6pm (18:00)) — Option to NOT turn off at chosen time (example: ignore 6pm turn off and keep running)
I’ve seen a few examples where people have used Input_number to customise the time, etc, but I couldn’t quite figure it out, nor is it the most user friendly option - open to suggestions.
Any assistance would be greatly appreciated.
Thank you in advance
You might get some real good examples looking at Garden irrigation topics like this one:
There’s quite a few people who built great, elaborate setups including definition of input variables and interfaces that you can probably just copy from a package, cut it down, and use it for your switch.
This time changes each day based on whether he has school so that hopefully he will sleep in on the weekdays he doesn’t have school. So I have an automation that runs each day to set the time of this input_datetime:
automation:
- id: set_skylar_morning_report_time
alias: set skylar morning report time
trigger:
- platform: time
at: '05:50:00'
action:
- service: input_datetime.set_datetime
entity_id: input_datetime.skylar_morning_report
data_template:
time: >
{% if states.calendar.skylar_school.attributes.offset_reached == True %}
06:15
{% else %}
07:58
{% endif %}
That simply sets the time based on whether he has school. Just two options to choose from, but it could be as many as needed. The only catch is the set time automation has to happen when the calendar is going to show it is a school day.
Then the announcement is triggered at what ever time is set in that input_datetime and the announcement happens at different times without needing my input:
You could easily set the start time and the end time to be adjustable either with an automation like I used or via the UI. I’ve tried to build my whole Home Assistant setup around the idea that I dont have to actually set these things myself or flips switches at all if I can help it. It supposed to be home “automation” and not home “remote control” right? lol
sensor:
- platform: time_date
display_options:
- 'time'
input_boolean:
spa_timer_on_enabled:
name: "SPA ON timer"
initial: off
icon: mdi:hot-tub
spa_timer_off_enabled:
name: "SPA OFF timer"
initial: off
icon: mdi:hot-tub
input_datetime:
turn_spa_on_time:
name: "Turn SPA on at"
has_time: true
has_date: false
initial: "14:00"
turn_spa_off_time:
name: "Turn SPA off at"
has_time: true
has_date: false
initial: "16:00"
#TURN SPA ON AT SPECIFIC TIME
automation:
- id: '1587771123429'
alias: Turn on SPA with Timer
trigger:
platform: template
value_template: '{{ states(''sensor.time'') == (states.input_datetime.turn_spa_on_time.attributes.timestamp
| int | timestamp_custom(''%H:%M'', False)) }}'
condition:
- condition: state
entity_id: input_boolean.spa_timer_on_enabled
state: 'on'
action:
- data: {}
entity_id: input_boolean.spa_on_switch
service: input_boolean.turn_on
#TURN OFF SPA TIMER ON
- delay: '2'
- data: {}
entity_id: input_boolean.spa_timer_on_enabled
service: input_boolean.turn_off
#TURN SPA OFF AT SPECIFIC TIME
- id: '1587771123430'
alias: Turn off SPA with Timer
trigger:
platform: template
value_template: '{{ states(''sensor.time'') == (states.input_datetime.turn_spa_off_time.attributes.timestamp
| int | timestamp_custom(''%H:%M'', False)) }}'
condition:
- condition: state
entity_id: input_boolean.spa_timer_off_enabled
state: 'on'
action:
- data: {}
entity_id: input_boolean.spa_on_switch
service: input_boolean.turn_off
#TURN OFF SPA TIMER ON
- delay: '2'
- data: {}
entity_id: input_boolean.spa_timer_on_enabled
service: input_boolean.turn_off
#TURN OFF SPA TIMER OFF
- data: {}
entity_id: input_boolean.spa_timer_off_enabled
service: input_boolean.turn_off
This allows me to turn on / off the spa at a given 24hr time. It will also turn off the timers once actioned. I’ll play around with adding the day of the week in there next.
Again, thank you for everyone’s contributions, this really is a terrific community.
Thanks Carl.
Haven’t made any modifications since, however, I’m looking at perhaps making a dropdown list selection of devices that I can customise a timer for… in the next project
I’ll post here any updates