Been working on this today based on some of the input in this thread.
I’m using automation instead of a script.
Under speakers I have an ‘off’ selection, which stops all streams.
Changing the radio station, changes the stream on speakers selected.
Still working through tracking states of devices, so that this interface will get updated if the stream is stopped by another means (I have some TTS functions).
Would be nice to have the entity picture update the radio stations list…
I use individual audio controls, as the mini/home need different settings.
I am havinbg trouble with getting this working. I have tried to set it up as a package but it crashes my HassIO (it wont load the frontend and has the following in the log, however I dont see the issue. Can someone please help?
LOG
2018-02-12 10:49:16 ERROR (SyncWorker_0) [homeassistant.util.yaml] while parsing a block mapping
in “/config/packages/chromecast_radio.yaml”, line 76, column 7
expected , but found ‘-’
in “/config/packages/chromecast_radio.yaml”, line 84, column 7
2018-02-12 10:49:16 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/packages/chromecast_radio.yaml”, line 76, column 7
expected , but found ‘-’
in “/config/packages/chromecast_radio.yaml”, line 84, column 7
chromecast_radio.yaml
group:
radio:
name: Radio
entities:
- input_select.radio_station
- input_select.chromecast_radio
- script.radio
- input_slider.volume_radio
input_select:
radio_station:
name: 'Select Radio Station:'
options:
- Hit 92-9
- Nova 93-7
- Mix 94-5
- 96FM
- 80's
- OldSkool Hits
- Raw FM (dance)
- 181FM Power (Todays Hits)
- 181FM 90's Dance
- 181FM Star 90's
- 181FM The Breeze
- Heat Radio (RnB)
- Fresh 92-7
- DI Chill & Tropical House
- DI Disco House
- DI Liquid D&B
initial: Raw FM (dance)
icon: mdi:radio
chromecast_radio:
name: 'Select Speakers:'
options:
- Lounge
- Bedroom
- House
initial: Lounge
icon: mdi:speaker-wireless
input_slider:
volume_radio:
name: Volume
icon: mdi:volume-high
min: 0
max: 1
step: 0.05
automation:
- alias: Listen Radio
hide_entity: True
trigger:
- platform: state
entity_id: input_select.radio_station
action:
- service: script.radio
- alias: Set Chromecast Radio Volume
trigger:
platform: state
entity_id: input_number.volume_radio
action:
service: media_player.volume_set
data_template:
entity_id: >
{% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
{% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
{% elif is_state("input_select.chromecast_radio", "House") %} media_player.house_group
{% endif %}
volume_level: '{{ states.input_number.volume_radio.state }}'
script:
radio:
alias: Play Radio on Chromecast Audio
sequence:
- service: media_player.volume_set
data_template:
entity_id: >
{% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
{% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
{% elif is_state("input_select.chromecast_radio", "House") %} media_player.house_group
{% endif %}
volume_level: '{{ states.input_number.volume_radio.state }}'
- service: media_player.play_media
data_template:
entity_id: >
{% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
{% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
{% elif is_state("input_select.chromecast_radio", "House") %} media_player.house_group
{% endif %}
media_content_id: >
{% if is_state("input_select.radio_station", "Hit 92-9") %} http://sc01.scahw.com.au/6ppm_32
{% elif is_state("input_select.radio_station", "Nova 93-7") %} http://streaming.novaentertainment.com.au/nova937
{% elif is_state("input_select.radio_station", "Mix 94-5") %} http://sc01.scahw.com.au/6mix_32
{% elif is_state("input_select.radio_station", "96FM") %} https://icy.ihrcast.arn.com.au/au_012_icy
{% elif is_state("input_select.radio_station", "80's") %} http://streaming.the80s.com.au/;stream/1
{% elif is_state("input_select.radio_station", "OldSkool Hits") %} http://sc01.scahw.com.au/loveland_32
{% elif is_state("input_select.radio_station", "Raw FM (dance)") %} http://stream.rawfm.com.au:8000/;stream.nsv
{% elif is_state("input_select.radio_station", "181FM Power (Todays Hits)") %} http://listen.181fm.com/181-power_128k.mp3?
{% elif is_state("input_select.radio_station", "181FM 90's Dance") %} http://listen.181fm.com/181-90sdance_128k.mp3
{% elif is_state("input_select.radio_station", "181FM Star 90's") %} http://listen.181fm.com/181-star90s_128k.mp3
{% elif is_state("input_select.radio_station", "181FM The Breeze") %} http://listen.181fm.com/181-breeze_128k.mp3
{% elif is_state("input_select.radio_station", "Heat Radio (RnB)") %} http://174.37.159.206:8106/stream
{% elif is_state("input_select.radio_station", "Fresh 92-7") %} http://live.fresh927.com.au/freshmp3
{% elif is_state("input_select.radio_station", "DI Chill & Tropical House") %} http://pub1.diforfree.org:8000/di_chillntropicalhouse_hi
{% elif is_state("input_select.radio_station", "DI Disco House") %} http://pub1.diforfree.org:8000/di_discohouse_hi
{% elif is_state("input_select.radio_station", "DI Liquid D&B") %} http://pub1.diforfree.org:8000/di_liquiddnb_hi
{% endif %}
media_content_type: 'audio/mp4'
You have different indentations on the two service
tags in the radio script and a space too much between the hyphen and the second service
.
Hi Bob,
I have just received my Cube and want to use code like this to control my amplifier volume. Currently I use a Broadlink IR transmitter to send commands to the amp because its old and has no smarts. Since the IR sends separate volume up and volume down commands, would I be able to use this code in a modified way to achieve this goal?
I have tried to set up the Broadlink custom component as per this which I guess may let me use your code directly?..?
Hi @Bob_NL,
I tried using your rotate code but got the following error:
2018-02-22 07:52:54 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.volume_set: value must be at least 0 for dictionary value @ data[‘volume_level’]. Got ‘-0.05’
2018-02-22 07:52:56 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.volume_set: value must be at least 0 for dictionary value @ data[‘volume_level’]. Got ‘-0.05’
any idea why this isnt working for me? Cheers.
edit, here is my cube rotate code:
alias: Cube - Rotate
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010fd152
action_type: rotate
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.lounge_amp
volume_level: >
{%if trigger.event.data.action_value | float > 0 %}
{{ states.media_player.lounge_amp.attributes.volume_level | float + 0.05 }}
{% else %}
{{ states.media_player.lounge_amp.attributes.volume_level | float - 0.05 }}
{% endif %}
what I think I need is to generate a volume_up command on a clockwise rotation and a volume_down on an anticlockwise rotation but I dont know how to do this. Would love some help please.
Try it with brackets Dave - not sure it will make a difference tho’
{{ (states.media_player.lounge_amp.attributes.volume_level | float) - 0.05 }}
I just tried it but it makes no difference unfortunately
The + = clockwise and the - = anticlockwise in other words the cube generates a +ve number for clockwise and a -ve number for anticlockwise. So as it stands because the check is for > 0 then it’s generating a vol up for clockwise and vice versa. You may find that you need to change it to +/- 0.1 rather than 0.05, depends what the state table says, mine goes from 0 to 100% in steps of 10 but in HA it goes from 0.0 to 1 therefore I step it in 0.1 incements.
What media platform are you using? Take a look at your entity attributes while playing audio to find out the naming and steps for the volume level.
so would there be a way I can extract the >0 / <0 data from the cube to send a volume up / volume down command, rather than an increment to the volume attribute?
Yep the component just sends a broadlink vol up/down packet and does not use an attribute, just do a vol up/down, so maybe…
volume_level: >
{%if trigger.event.data.action_value | float > 0 %}
+1
{% else %}
-1
{% endif %}
or put whatever the command is, I’ve not looked at the component yet well not in any detail anyway
thanks for that. I tried your code but it didnt work so I also tried the below, same deal, not working
alias: Cube - Rotate
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010fd152
action_type: rotate
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.lounge_amp
volume_level: >
{%if trigger.event.data.action_value | float > 0 %}
service: switch.turn_on
entity_id: switch.amp_volume
{% else %}
service: switch.turn_off
entity_id: switch.amp_volume
{% endif %}
The above wouldn’t work it would be something like…
action:
- service: switch.turn_on
data_template:
{%if trigger.event.data.action_value | float > 0 %}
entity_id: switch.amp_volume_up
{% else %}
entity_id: switch.amp_volume_down <------------ or whatever you specified in the broadlink switches
{% endif %}
I have my doubts about this as well, I would ask the author how to go about using the volume switches from his media_player.
in the broadlink switch setup there is just switch.amp_volume which gets turned on for volume up and off for volume down… I suppose I could modify it to have two entities with only an ON command
You could just use the already setup switches, you must have defined them to put them in the .ini files to start with.
try a service_template
:
action:
- service_template: >
{%if trigger.event.data.action_value | float > 0 %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
entity_id: switch.amp_volume
The broadlink component doesnt have separate volume up and volume down commands though. It works likie switches with vol up being on and vol down being off. here is my .ini file for the amp
#switch:
- platform: broadlink
host: 192.168.0.71
mac: '34:ea:34:xx:xx:xx'
friendly_name: IR Transceiver
type: rm_mini
switches:
onkyo_amp:
friendly_name: "Amp Power"
command_on: 'JgBMAAYABD8AASiSFBEUNRQRFBEUNRQRFDYUNRU1FBEUNhQ1FBEUNhQ1FBEUERQQFDYUERQQFBEUEBQRFDYUNRQRFDYUNRU1FDYUNhQADQUAAAAAAAAAAAAAAAA='
command_off: 'JgBIAAABKJEUERQ2FBAUERQ2FBAUNhQ2FBAUERQ2FDUUERQ2FDYUEBQ2FDYUNRQRFBEUEBQ2FBEUEBQRFBAUNhQ2FDYUEBQ2FAANBQ=='
onkyo_amp_cd:
friendly_name: "Amp CD Input"
command_on: 'JgBQAAABKJIUEBQ2FBEUEBQ2FBETNhQ2FDYUERM2FDYUERM2FDYUERM2FBEUERM2FBEUERMRFBEUEBQ2FDYUERM2FDYUNhQ2EwAE8gABKEkTAA0FAAAAAAAAAAA='
onkyo_amp_v1:
friendly_name: "Amp V1 Input"
command_on: 'JgBIAAABKJEUERM2FBEUERM2FBEUNhM2FDYUERQ1FDYUERQ2EzYUERQ2EzYUNhQ2FBETERQRExEUERQRExEUERQ1FDYUNhQ2EwANBQ=='
onkyo_amp_volume_up:
friendly_name: "Amp Volume"
command_on: 'JgBIAAABKIwaERM2FBEUERM2FBEUNhM2FDYUERM2FDYUERQ1FDYUERQQFDYUERQQFBEUERMRFBEUNhMRFDYUNhM2FDYUNhQ2EwANBQ=='
command_off: 'JgBQAAkADMILAAzsAAEqkRQRFDYUEBQRFDYUEBQ2FDYUNRQRFDYUNhMRFDYUNhQQFDYUNhQQFBEUERQQFBEUEBQRFBEUNRQ2FDYUNhQ1FDYUAA0FAAAAAAAAAAA='
onkyo_amp_mute:
friendly_name: "Amp Mute"
command_on: 'JgBIAAABKJIUEBQ2FBEUEBQ2FBETNhQ2FDYUEBQ2FDYUERM2FDYUERQ1FBEUNhQQFBEUERMRFBEUEBQ2FBEUNRQ2FDYUNhQ1FAANBQ=='
command_off: 'JgBIAAABKJIUEBQ2FBEUEBQ2FBETNhQ2FDYUEBQ2FDYUERM2FDYUERQ1FBEUNhQQFBEUERMRFBEUEBQ2FBEUNRQ2FDYUNhQ1FAANBQ=='
So I’m thinking I should change the volume to be 2 separate entities with only an ON command for each