Hi guys. I tried to implement a way to load custom entity_picture to my Sonos media_players when streaming from an internet radio (*.mp3 source)
Followed the example from: https://community.home-assistant.io/t/chromecast-radio-with-station-and-player-selection/12732/237
Im however getting the following error and have been trying to change to different paths in the config. (for example /config/custom_components/radio_cast/ and /home/hass/.homeassistant/custom_components/radio_cast/ etc)
Log Details (ERROR)
Mon Jun 18 2018 13:18:49 GMT+0200 (W. Europe Daylight Time)
Error executing service <ServiceCall shell_command.radio_picture: my_media_player=media_player.livingroom, my_radio_station=Jayan.se_Radio>
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/homeassistant/core.py", line 1007, in _event_to_service_call
await service_handler.func(service_call)
File "/usr/lib/python3.6/site-packages/homeassistant/components/shell_command.py", line 88, in async_service_handler
process = yield from create_process
File "/usr/lib/python3.6/asyncio/subprocess.py", line 225, in create_subprocess_exec
stderr=stderr, **kwds)
File "uvloop/loop.pyx", line 2368, in __subprocess_run
File "uvloop/handles/process.pyx", line 564, in uvloop.loop.UVProcessTransport.new
File "uvloop/handles/process.pyx", line 87, in uvloop.loop.UVProcess._init
FileNotFoundError: [Errno 2] No such file or directory
My config looks as following:
Shell command
radio_picture: /home/hass/.homeassistant/custom_components/radio_cast/radio.py {{ my_media_player }} {{ my_radio_station }}
automation
alias: Set Radio Picture
trigger:
- platform: event
event_type: state_changed
condition:
- condition: or
conditions:
#list all media players here
- condition: template
value_template: "{{ trigger.event.data.entity_id == 'media_player.kitchen' }}"
- condition: template
value_template: "{{ trigger.event.data.entity_id == 'media_player.livingroom' }}"
- condition: template
value_template: "{{ trigger.event.data.entity_id == 'media_player.bedroom' }}"
- condition: template
value_template: "{{ trigger.event.data.new_state.state == 'playing' }}"
- condition: template
value_template: "{{ trigger.event.data.new_state.attributes is not none }}"
#only run if script triggered in last 30 sec to not overwrite other music services
- condition: template
value_template: "{{(as_timestamp(now()) - as_timestamp(states.script.radio_cast.attributes.last_triggered | default(0)) | int < 30 )}}"
action:
- service: shell_command.radio_picture
data_template:
my_media_player: '{{ trigger.event.data.entity_id }}'
my_radio_station: '{{ states.input_select.radio_station.state | replace(" ", "_") }}'
/custom_components/radio_cast/radio.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
import sys
import json, requests, simplejson
HA_URL = "!secret URL"
HA_PWD = "!secret PASSWORD"
##########################################
# Call the script with 2 parameters:
# parameter 1 is the full media_player entity name, e.g. media_player.bedroom
# Parameter 2 is the input_select of the selected radio station with spaces replaced with underscores, e.g. Absolute_Radio
##########################################
def HASS_API_State(Entity, State, Media_Title, Entity_Picture, media_content_id, friendly_name):
url = HA_URL + "/api/states/" + str(Entity) + "?api_password=" + HA_PWD
data={"state":"" + str(State) + "", "attributes": {"media_title": "" + str(Media_Title) + "", "entity_picture": "" + str(Entity_Picture) + "", "is_volume_muted": "false", "media_content_id": "" + str(media_content_id) + "", "friendly_name": "" + str(friendly_name) + "", "supported_features: ": "21437", "app_name: ": "Radio Cast", "media_position: ": "0"}}
headers = {'Content-type':'application/json', 'Accept-Encoding': 'text/plain', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers)
c = r.content
result = simplejson.loads(c)
if(sys.argv[2]=="Jayan.se_Radio"):
HASS_API_State(sys.argv[1],"playing",sys.argv[2].replace("_"," "), HA_URL +"/local/radio.jpg", "http://jayan.se:8000/stream.mp3", sys.argv[1].replace("media_player.","").capitalize())
If anyone can point me towards whats wrong i would be soooo thankful.
// Jayan