Hello!
Is it possible to programm something in home assistant to start a sonos speaker (for example with a favorite playlist or radio station) when the sonos speaker gets connected to the electricity?
Thanks,
Marius
Hello!
Is it possible to programm something in home assistant to start a sonos speaker (for example with a favorite playlist or radio station) when the sonos speaker gets connected to the electricity?
Thanks,
Marius
No idea?
Yes that should be possible. Setup a sensor that detects the state of the sonos. If the state has a value, then (using automation) run a Shell script that triggers a favorite or playlist using the Node based HTTP sonos api.
Check out the stuff I’ve got in My git repo, you’ll find some code in the automation, script and shell command folders. I’ve got a Sonos based template sensor too.
Oh great!
Thanks for your examples! I will try it next week when i’m back from buisness Travel.
Hey!
I try it this way:
I create a sensor which check the State of the player.
sensor:
- platform: template
sensors:
sonos_status_bad:
value_template: '{{ states.media_player.bad.state }}'
Then I create a trigger when the state change from ‘empty’ to ‘paused’.
The problem is, that NO new media_player appears when I plug in the Sonos Sub.
Is there a way to check every 10 sec or something for a new media_player device- so that I can check the state?
Thanks! And sorry for my english:)
Hi,
can you explain me how you check the state of your Sonos sub?
In your Github sonos.yaml, you have two sensors- one for the kitchen and one for the sonos controller? what is the sonos controller- what does the ‘sonos_controller_online_shell’ do?
Do you scan the network with for the kitchen sub with this sensor?
- platform: command_line
scan_interval: 5
command: /usr/bin/curl --silent GET http://192.168.0.140:5005/kitchen/state | python -c 'import sys, json; print json.load(sys.stdin)["playbackState"]'
name: 'sonos_kitchen_state_shell'
The IP is the IP of your sub in the kitchen?
Thank you
The online Shell is supposed to check the state of the nodejs, but I don’t think it’s working properly
192.168.0.140 is the ip of my raspberry pi where I’m running the Nodejs Sonos library. That library, on that link, returns some Json code that I’m parsing. But you might as well use the built in functionality to check the state. Checking state is done using the template sensor.
My solution:
sensor:
- platform: template
sensors:
sonos_status_bad:
value_template: '{{ states.media_player.bad.state }}'
automation:
- alias: 'Auto Start Bad'
initial_state: 'on'
hide_entity: True
trigger:
platform: state
entity_id: sensor.sonos_status_bad
from: 'off'
to: 'paused'
action:
service: media_player.play_media
entity_id: media_player.bad
data:
media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
media_content_type: music