I’m trying to figure out how to implement line 5. My idea was to keep a variable/entity, with a check on step 2. Something like on step 2, assign “true” value to spotify_playing_when_left, so that value can be checked on step 5 and work from there.
I’ll try making an input boolean and adjusting via GUI. Just a question before I do that, what’s the best place for new “manual entities”? (If this new input_boolean can be called that)
I’m trying to keep my configuration.yaml clean, so if you have any tips regarding this situation. The most specific thing I’m interested in is the best way to reload the config, without doing a full HA restart, same as I can do with templates, group entities etc.
alias: "Convenience: Spotify Automation"
description: ""
trigger:
- platform: state
entity_id:
- person.user
to: not_home
from: home
for:
hours: 0
minutes: 0
seconds: 0
id: user-left-home
- platform: state
entity_id:
- person.user
id: user-came-home
from: not_home
to: home
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: user-left-home
- condition: device
device_id: 9190989df60ebd064682a4ac54abf405
domain: media_player
entity_id: media_player.spotify_username
type: is_playing
sequence:
# Below block, so it doesn't pause playback on my phone in the car, because of left-home delay
- if:
- condition: not
conditions:
- condition: state
entity_id: media_player.spotify_username
attribute: source
state: "phone"
then:
- service: media_player.media_pause
data: {}
target:
entity_id: media_player.spotify_username
#- HELP HERE - assign "true" value to spotify_playing_when_left_home
- conditions:
- condition: trigger
id: user-came-home
# If music was playing in the car, and I come home within 5 minutes of pausing it (leaving the car), pass condition
- condition: template
value_template: >
{{ (as_timestamp(now()) -
as_timestamp(states.media_player.spotify_username.last_changed))
| round(0) < 300 }}
#- HELP HERE - or spotify_playing_when_left_home == true
sequence:
- if:
- condition: state
entity_id: switch.pc
state: not_home
then:
- wait_for_trigger:
- platform: state
entity_id:
- device_tracker.pc
from: not_home
to: home
timeout: "60"
continue_on_timeout: false
- service: media_player.select_source
data:
source: pc
target:
entity_id: media_player.spotify_username
- service: media_player.media_play
data: {}
target:
entity_id: media_player.spotify_username
default: []
mode: single