Skip to content

odio-ha automation examples

These automations use the entities of three example nodes: raspodio, the streamer driving the amplifier, plus an htpc and a desktop running go-odio-api. Replace the hostnames and the non-odio entities (lights, covers, alarm, amplifier switch) with your own.

The receiver counts the audio streams playing on the node in its playing_clients attribute: MPD, Spotify, AirPlay, Bluetooth, a desktop streaming over the network, anything that outputs sound. A paused stream doesn’t count.

The first automation turns the amplifier on once a stream has played for 2 minutes, so short sounds don’t wake it. The second turns it off after 15 minutes without any stream.

- alias: Amplifier on with playback
triggers:
- trigger: numeric_state
entity_id: media_player.odio_remote_raspodio
attribute: playing_clients
above: 0
for:
minutes: 2
conditions:
- condition: state
entity_id: switch.amplifier
state: "off"
actions:
- action: switch.turn_on
target:
entity_id: switch.amplifier
- alias: Amplifier off when idle
triggers:
- trigger: numeric_state
entity_id: media_player.odio_remote_raspodio
attribute: playing_clients
below: 1
for:
minutes: 15
conditions:
- condition: state
entity_id: switch.amplifier
state: "on"
actions:
- action: switch.turn_off
target:
entity_id: switch.amplifier

switch.amplifier stands for whatever powers the amplifier, such as a smart plug.

The connection binary sensor turns on when Home Assistant reaches the node’s event stream, so when the machine is up and go-odio-api runs. On an HTPC, it means the HTPC was just switched on.

- alias: HTPC lights
triggers:
- trigger: state
entity_id: binary_sensor.odio_remote_htpc_connection
to: "on"
conditions:
- condition: state
entity_id: cover.living_room
state: closed
actions:
- action: light.turn_on
target:
entity_id: light.living_room

Starting the desktop in the morning disarms the night alarm, turns the amplifier on and plays a spoken message on the speakers. The message goes to the MPD MPRIS player of the streamer, which accepts text-to-speech through its queue.

- alias: Morning routine
triggers:
- trigger: state
entity_id: binary_sensor.odio_remote_desktop_connection
from: "off"
to: "on"
conditions:
- condition: state
entity_id: person.resident
state: home
actions:
- if:
- condition: state
entity_id: alarm_control_panel.home
state: armed_night
then:
- action: alarm_control_panel.alarm_disarm
target:
entity_id: alarm_control_panel.home
- action: switch.turn_on
target:
entity_id: switch.amplifier
- action: tts.speak
target:
entity_id: tts.google_translate_en_com
data:
media_player_entity_id: media_player.odio_remote_raspodio_music_player_daemon
message: Good morning!

At a fixed time, announce bedtime on the speakers, then shut down the HTPC and the desktop 5 minutes later with their power off buttons. Each machine is only shut down if it is still on. Once both are off, the night mode below takes over.

The power off button is disabled by default on go-odio-api: enable it in the power management section of each machine’s configuration.

- alias: Bedtime shutdown
triggers:
- trigger: time
at: "23:30:00"
conditions:
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.odio_remote_htpc_connection
state: "on"
- condition: state
entity_id: binary_sensor.odio_remote_desktop_connection
state: "on"
actions:
- action: tts.speak
target:
entity_id: tts.google_translate_en_com
data:
media_player_entity_id: media_player.odio_remote_raspodio_music_player_daemon
message: Time to go to bed, computers shut down in 5 minutes.
- delay:
minutes: 5
- if:
- condition: state
entity_id: binary_sensor.odio_remote_htpc_connection
state: "on"
then:
- action: button.press
target:
entity_id: button.odio_remote_htpc_power_off
- if:
- condition: state
entity_id: binary_sensor.odio_remote_desktop_connection
state: "on"
then:
- action: button.press
target:
entity_id: button.odio_remote_desktop_power_off

The reverse: late at night, once the HTPC and the desktop have both been off for 2 minutes, turn off the lights and arm the alarm in night mode. Each sensor triggers the automation, and the condition waits for the last one to go off.

- alias: Night mode
triggers:
- trigger: state
entity_id:
- binary_sensor.odio_remote_htpc_connection
- binary_sensor.odio_remote_desktop_connection
to: "off"
for:
minutes: 2
conditions:
- condition: state
entity_id:
- binary_sensor.odio_remote_htpc_connection
- binary_sensor.odio_remote_desktop_connection
state: "off"
- condition: state
entity_id: person.resident
state: home
- condition: time
after: "23:00:00"
before: "08:00:00"
actions:
- action: light.turn_off
target:
area_id: living_room
- if:
- condition: state
entity_id: alarm_control_panel.home
state: disarmed
then:
- action: alarm_control_panel.alarm_arm_night
target:
entity_id: alarm_control_panel.home