A home assistant integration for controlling switch entites by using a timer. Each individual switch entity can be set to turn on, turn off, or toggle after a specified period of time.
Using HACS
- Go to the main screen of HACS and select the custom repository option in the top right conner
- Enter the URL of this repository, select type as integration and click add
- Search for switch timer in HACS and download the first integration from the list
- Go to integrations page in settings or use the button below and add the Switch Timer integration
- Copy
custom_components/switch_timer
from this repository into your home assistant installationscustom_components/
directory. - Restart Home Assistant
- Add Switch Timer integration in settings.
Integration creates switch timer entity for every switch entity in the home assistant instance. Switch timer entities are assigned to switch_timer
domain, the entity name remains the same as original switch entity. As for example, switch.kitchen_light
=> switch_timer.kitchen_light
. The integration scans for new switch entities every 10 seconds, if a new switch entity is found, a switch timer entity is created for it automatically. A switch timer entity state can be either set or idle. An entity changes its state from idle to set when a timer is scheduled. Note that all scheduled timers are dropped upon a system restart, will change this in a future release. The integration provides two services for both scheduling and canceling timers. A set switch timer entity has the following attributes,
finishing_at
Shows the UTC timestamp when timer is scheduled to runduration
Duration of the timer in HH:MM:SS formataction
State scheduled for the corresponding switch entity to be set to. Possible values, 'turn_on', 'turn_off, 'toggle'
Service used for scheduling a timer. Maximum timer duration supported is 23:59:59. Required parameters are,
entity_id
switch timer entity to set the timer foraction
state action to be set on the corresponding switch entityduration
duration for the timer in HH:MM:SS format
action: switch_timer.set_timer
data:
entity_id: switch_timer.kitchen_light
action: "turn_off"
duration: "00:10:00"
Example service call on switch_timer.kitchen_light
entity to turn the device off after 10 minutes.
Service used for canceling a scheduled timer. The entity_id
for the timer to be canceled is required.
action: switch_timer.cancel_timer
data:
entity_id: switch_timer.kitchen_light
Example service call to cancel the timer scheduled on switch_timer.kitchen_light
entity.
Both services have a GUI support implemented in developer tools section.
In order to easily set timers for devices straight from the dashboard, I've created set timer popup card, which can be displayed in a browser mod popup as a hold action on a card, for example.
- Save timer states upon a restart
If you encounter any problems while using the integration, feel free to contact me by email romansa772@aol.com or open an issue in this repository. If you wish to support my work you can make a donation here or just give this repo a star.