Triggers and Actions
Some components expose triggers that run a list of actions when something happens (for example a state change).
Triggers are available on the Binary Sensor:
on_press— runs when the state changes totrue.on_release— runs when the state changes tofalse.
and on the Template switch, button and number:
turn_on_action— runs when the template switch is turned on.turn_off_action— runs when the template switch is turned off.on_press— runs when the template button is pressed.set_action— runs when the template number is set to a new value.
and on the Media Player:
on_play— runs when playback starts.on_pause— runs when playback stops/pauses.on_volume_change— runs when the volume changes.
There is also a global on_startup trigger, configured under ubihome:, that runs once when UbiHome starts:
ubihome: name: 'Raspberry Pi behind the TV' on_startup: then: - switch.turn_on: status_ledA trigger takes a then block listing the actions to run in order:
binary_sensor: - platform: ... name: 'Motion' filters: # Debounce with a delayed_off/delayed_on filter so a trigger only # fires once the state has held for the configured duration. - delayed_off: 5s on_press: then: - switch.turn_on: screen on_release: then: - switch.turn_off: screenSee Filters for the available debounce filters.
Supported Actions
Section titled “Supported Actions”| Action | Argument | Description |
|---|---|---|
switch.turn_on | switch id | Turns the referenced switch on. |
switch.turn_off | switch id | Turns the referenced switch off. |
button.press | button id | Presses the referenced button, running its platform action. |
globals.set | id, value | Sets a global variable to value. |
delay | duration | Pauses the action list for the given duration (e.g. 2s, 500ms) before running the next action. |
logger.log | value | Logs the given value to the console at info level. |
For entity actions the argument is the id of the target entity, so make sure the switch or button you reference has an id set.
binary_sensor: - platform: gpio name: 'Button' pin: 17 on_press: then: - switch.turn_on: screen - delay: 30s - switch.turn_off: screenglobals.set takes id/value arguments instead of a single id; see
Globals for the value syntax.
logger.log takes a plain YAML scalar (string, boolean, or number), the same
way globals.set’s value does:
- logger.log: 'Motion detected'