Hello,
I have a light on a smart socket and I would like to add option to dashboard to shut it down (countdown) after given time, something similar to whats on the screenshot.
How to do it?
Hello,
I have a light on a smart socket and I would like to add option to dashboard to shut it down (countdown) after given time, something similar to whats on the screenshot.
How to do it?
Two input numbers - one for hours and one for minutes.
After you set the numbers, trigger a script where you set a delay with the input numbers and after the delay it turns off the plug.
Alternatively you could also make a datetime helper, where you set the absolute time and the script would wait for a trigger when the time is met.
I have this kind of a scenario, my motion sensors do not turn lights on or off they just (re)start or stop timers, and the timer duration is set to the setting for the input number formatted as a slider. Motion or turning the light on (re)starts the timer, automations also for restarting the time with the time selected on the slider when the slider changes, stoppping the timer when the bulb is turned off, starting the timer when the bulb is turned on, etc. (when the light is off and someone changes the slider you donât even need to do anything with that scenario!) All the logic is ignored if the drop down is changed to âDisabledâ, etc.
(I should probably rename my relay to âbathroom light switchâ or the likeâŚ)
I find the coding is MUCH easier if I have many automations, each named with an easy to understand name, and each automation only does one thing. I think people have a lot of issues when they try to build everything into one big automationm, it ends up being a mess - which is also hard to debug and when there is one mistake then everything is broken etc.) I think some people think it is bad to have alot of automations - and if so that is not the correct mindset!
Thoughts?
I agree that a timer is a good solution. Also that itâs better to have each automation only do one thing. I wonât argue that last point though, I know some prefer to pack 'em full of functionality.
My use was a timer for the outdoor water spigots in the yard. For a number of reasons, I wanted them all off when not in use. I use an input_select button to pick how long I want it to remain on for, and just a generic timer:
# Yard Water Time Select Button and Timer
input_select:
water_time_select:
name: Yard Water On Time Minutes
options:
- "OFF"
- "30"
- "60"
- "90"
- "120"
icon: mdi:timer
timer:
water_timer:
duration: '00:30:00'
My automations look like this:
#
# Activate Power Operated Water Valve
#
- id: id_water_timer
alias: Update Water Timer
trigger:
- platform: state
entity_id: input_select.water_time_select
condition:
- condition: template
value_template: '{{ not is_state(''input_select.water_time_select'', ''OFF'')
}}'
action:
- service: light.turn_on
entity_id: light.tz3000_o4cjetlm_ts0001_on_off
- service: timer.start
data:
entity_id: timer.water_timer
duration:
minutes: '{{ states(''input_select.water_time_select'') }}'
- id: id_water_timer_expired
alias: Water Timer Expired
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.water_timer
action:
- service: light.turn_off
entity_id: light.tz3000_o4cjetlm_ts0001_on_off
- service: input_select.select_option
data:
entity_id: input_select.water_time_select
option: 'OFF'
- id: id_water_timer_off
alias: Water Timer select OFF
trigger:
- platform: state
entity_id: input_select.water_time_select
to: 'OFF'
action:
- service: timer.finish
entity_id: timer.water_timer
Just to be clear, Iâm no expert. This is what I came up with, and it works. No doubt there are a dozen other ways, some better.
Just to clarify (I have read the suggestions) I want to mirror functionality from the app.
Light on a smart socket is just an example, it could be any device that I want to be shutdown in n time form now, turning on manually.
In my current use case itâs a 3D printer, which I want to turn off at night after print is done (+ some time for nozzle cool down).
I mean I got it kinda done by using GitHub - pmongloid/flipdown-timer-card: Flipdown Timer Card for Home Assistant Lovelace
From HACS,
And I would have to do that for every socket manually and I canât just click on icon of a socket to get to all functionality different that just switching it off or on.
Iâm just surprised this is not implemented as a default and Iâm gonna have to hack around to make it useful.