Hi all,
I’m trying to make a few automations, allowing the user to move music from one device, to another. For that, i’m using Spotcast (which allow me to me the current playback to another Google device - Yep, wish i had started with Sonos, but with plenty of Google devices, i can’t make the move to Sonos right not).
There’s many good posts about defining the options for a input_select-item, and i did make that part yesterday, with a Rest command. More details about that part, in this post:
However, i have problem - and i’m not sure what to do
By defining the options for input_select.sound_target
with api/services/input_select/set_options
, the following automation is also triggered:
alias: Trigger Spotcast Sound Target Playback
trigger:
platform: state
entity_id: sensor.sound_target
action:
service: spotcast.start
data_template:
device_name: "{{ states('sensor.sound_target') }}"
So, everytime the rest_command
is executed, the sound-device changes, and that’s not good
My current hack, is to disable the automation with:
alias: Update Sound Targets
initial_state: True
trigger:
- platform: homeassistant
event: start
- platform: time_pattern
minutes: '/30'
action:
- service: automation.turn_off
entity_id: automation.trigger_spotcast_sound_target_playback
- delay:
seconds: 30
- service: rest_command.populate_input_select_from_sensor_chromecast_devices
- delay:
seconds: 5
- service: automation.turn_on
entity_id: automation.trigger_spotcast_sound_target_playback
Another hack could be to have a static value on the list, as the first element. “Pick one”, and ignore that value in the automation… However, it can’t be the only way to do it?!
Do you guys have a good idea?
I love Node-RED, but i would like to make this within HA, if possible
TL;DR:
Can i, somehow, use set_options
for my input_select
, but prevents the state to change? (Cause my automation is triggered, and the value is not longer the “correct one”)
Currently the state is updated to the first value on the sound_target-list (Eg. “Living room”), every time i use the set_options
function.
My `rest_command` for set_options
url: "http://localhost:8123/api/services/input_select/set_options"
method: POST
headers:
content-type: application/json
authorization: !secret rest_command_token_ha
content_type: application/json
payload: >-
{
"entity_id": "input_select.sound_targets",
"options": [{% set devices = states.sensor.chromecast_devices.attributes.devices_json | from_json %}
{%- for device in devices -%}
"{{ device.name }}"{% if not loop.last %}, {% endif %}
{%- endfor %}]
}