A simple switch component that once turned on will turn itself off.
This release includes a mode
configuration allowing the switch to be
momentarily on or off. Existing configurations will work with the new code but
use the new configuration going forward.
Wherever you see /config
in this README it refers to your home-assistant
configuration directory. For me, for example, it's /home/steve/ha
that is
mapped to /config
inside my docker container.
Many thanks to:
-
JetBrains for the excellent PyCharm IDE and providing me with an open source license to speed up the project development.
Momentary is part of the default HACS store. If you're not interested in development branches this is the easiest way to install.
Copy the momentary
directory into your /config/custom_components
directory.
Run the install script. Run it once to make sure the operations look sane and
run it a second time with the go
parameter to do the actual work. If you
update just rerun the script, it will overwrite all installed files.
install /config
# check output looks good
install go /config
Add the following to your configuration.yaml
to enable the component:
momentary:
To create a momentary on switch use the following:
switch:
- platform: momentary
name: Empty House Trigger
mode: "on"
toggle_for: 5
cancellable: True
The following additional parameters can be specified against the switches:
Field | Type | Default | Description |
---|---|---|---|
name | strings | Name of the switch. Has to be supplied. | |
mode | string | "on" | Is the switch a momentary ON or OFF switch. Use "on" for on and "off" for off. |
toggle_for | seconds | 1 | Amount of time to turn toggle switch for. |
cancellable | Boolean | False | Allow switched to be untoggled manually. |
To add multiple switches repeat the whole component configuration:
switch:
- platform: momentary
name: Empty House Trigger
mode: "on"
toggle_for: 5
- platform: momentary
name: Bad Weather Trigger
mode: "on"
toggle_for:
milliseconds: 500
By default, the code creates entities with momentary
as part of their name.
Switch 1
in the previous example will give an entity of
switch.momentary_switch_1
. If you don't want the momentary_
prefix add a !
to the device name. For example:
switch:
- platform: momentary
name: !Switch 1