Skip to content

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 to true.
  • on_release — runs when the state changes to false.

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_led

A 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: screen

See Filters for the available debounce filters.

ActionArgumentDescription
switch.turn_onswitch idTurns the referenced switch on.
switch.turn_offswitch idTurns the referenced switch off.
button.pressbutton idPresses the referenced button, running its platform action.
globals.setid, valueSets a global variable to value.
delaydurationPauses the action list for the given duration (e.g. 2s, 500ms) before running the next action.
logger.logvalueLogs 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: screen

globals.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'