rpitera
(Robert Pitera)
March 1, 2017, 9:23pm
6
When you post code, instead of a screen shot please copy and paste the code into the forum post editor and then select it. The press the pre-formatted text button as indicated in the image below:
This makes it easy to read the code and also preserves the formatting in a way that others can see to check it. This is especially important with stuff like YAML! Also, it keeps the storing of images on the AWS servers low, which is also a good thing.
Thanks!
xpress142
(Xpress142)
March 1, 2017, 9:27pm
7
Here it is. Sorry for that
# My Existing Automation
automation:
- alias: Select Patio Music
trigger:
- platform: state
entity_id: input_select.patio_music
action:
- service: media_player.play_media
entity_id: media_player.patio_chromecast
data:
media_content_type: audio/mp3
data_template:
media_content_id: >
{% if trigger.to_state.state == 'Party Station' %}
http://xx.xx.xx.xxx/PARTY
{% elif trigger.to_state.state == 'Classical Station' %}
http://xx.xx.xx.xxx/CLASSICAL
{% elif trigger.to_state.state == 'Relax Station' %}
http://xx.xx.xx.xxx/RELAX
{% endif %}
__________________________________________________________________________
# My Custom Internet Radio Station Database File
Party Station: http://xx.xx.xx.xxx/PARTY #line 1
Classical Station: http://xx.xx.xx.xxx/CLASSICAL #line 2
Relax Station: http://xx.xx.xx.xxx/RELAX #line 3
__________________________________________________________________________
# New Automation
automation:
- alias: Select Patio Music
trigger:
- platform: state
entity_id: input_select.patio_music
action:
- service: media_player.play_media
entity_id: media_player.patio_chromecast
data:
media_content_type: audio/mp3
data_template:
media_content_id: >
{% if trigger.to_state.state == '{FIRST PART of 3rd line on "My Internet Radio Station Database File" (example > "Relax Station") %}'
{SECOND PART of 3rd line on "My Internet Radio Station Database File" (example - http://xx.xx.xx.xxx/RELAX) %}
{% endif %}
1 Like
krsandvik
(Krsandvik)
March 2, 2017, 3:30pm
8
I got some problem with this, I can’t see the play icon, the “Start Playing” and ACTIVATE.
Where is the code for that?
Thanx in advanced
Bob_NL
(Bob Visser)
March 2, 2017, 6:18pm
9
@krsandvik That would be the script:
group:
Residence Radio:
name: Residentie Radio
entities:
- input_select.radio_station
- input_select.chromecast_radio
- script.radio538 <--------
I forget to mention that I customized the script name to “start playing” (I added it to the startpost now):
customize:
script.radio538:
friendly_name: Start Playing
icon: mdi:play
Did you add all the code’s in the startpost in your yaml?
Bob_NL
(Bob Visser)
March 2, 2017, 8:55pm
10
I understand what your saying but i’m afraid I can’t help you with that, sorry.
Bob_NL
(Bob Visser)
March 2, 2017, 9:14pm
11
I extended it with a volume slider:
Mod Edit (2020) : Since this topic was originally created several years ago, you might see outdated references to input_slider
throughout this thread. It was renamed to input_number
in Home Assistant 0.55. So whenever you see posts mentioning input_slider
, make sure to replace that with input_number
in your code - otherwise you will have invalid config.
Input number:
input_number:
volume_radio:
name: Volume
icon: mdi:volume-high
min: 0
max: 1
step: 0.05
View:
group:
Residence Radio:
name: Residentie Radio
entities:
- input_select.radio_station
- input_select.chromecast_radio
- script.radio538
- input_number.volume_radio
Automation:
- alias: 'Set 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", "Livingroom") %} media_player.ca_livingroom
{% elif is_state("input_select.chromecast_radio", "Hall") %} media_player.ca_hall
{% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bed_room
{% elif is_state("input_select.chromecast_radio", "Bathroom") %} media_player.ca_bathroom
{% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.home_group
{% endif %}
volume_level: '{{ states.input_number.volume_radio.state }}'
I used a separate automation for this instead adding it to the script because that way you won’t have to restart the stream everytime you adjust the volume. State change of the volume slider will change the volume of the selected speakers instantly this way.
8 Likes
krsandvik
(Krsandvik)
March 3, 2017, 2:37pm
12
thanx for your reply, sorry but I still can’t get the activate button in the group. I have customize the radio to a Norwegian radio station.
Here is my configuration.yaml
homeassistant:
# Name of the location where Home Assistant is running
name: Home
# Location required to calculate the time the sun rises and sets
latitude: 59.7967
longitude: 10.8136
# Impacts weather/sunrise data (altitude above sea level in meters)
elevation: 168
# metric for Metric, imperial for Imperial
unit_system: metric
# Pick yours from here:
time_zone: Europe/Oslo
customize:
# Add an entry for each entity that you want to overwrite.
media_player.bathroom:
friendly_name: CC Bathroom
media_player.google_home:
friendly_name: Google Home
media_player.hele_leiligheten:
friendly_name: CC Apartment
media_player.kitchen:
friendly_name: CC Kitchen
switch.rullegardin_soverom_oppenede:
friendly_name: Rullegardin
script.nrk_radio:
friendly_name: Start Playing
icon: mdi:play
# Example configuration.yaml entry
group:
####VIEWS
livingroom_view:
view: yes
name: Living Room
entities:
- group.livingroom
####Groups
livingroom:
name: Living Room
entities:
- media_player.google_home
- media_player.nexus_player
- media_player.stereo
- sensor.broadlink_sensor_temperature
bedroom:
name: Bedroom
entities:
- switch.rullegardin_soverom_oppenede
hytta:
name: Hytta
entities:
- sensor.netatmo_hytta_inne_temperature
- sensor.netatmo_hytta_ute_temperature
environment:
- sensor.yr_symbol
- sun.sun
nrkradio:
name: NRK Radio
entities:
- input_select.radio_station
- input_select.chromecast_radio
- script.nrkradio
- input_slider.volume_radio
####Selectors
input_select:
radio_station:
name: 'Select Radio Station:'
options:
- "NRK P1"
- "NRK p3"
- "NRK Klassisk"
chromecast_radio:
name: Select Speakers
options:
- Livingroom
- Bathroom
- Kitchen
- Everywhere
initial: Everywhere
icon: mdi:speaker-wireless
input_slider:
volume_radio:
name: Volume
icon: mdi:volume-high
min: 0
max: 1
step: 0.05
# Enables the frontend
frontend:
http:
# Uncomment this to add a password (recommended!)
#api_password:
# Uncomment this if you are using SSL or running in Docker etc
# base_url: example.duckdns.org:8123
# Checks for available updates
updater:
# Discover some devices automatically
discovery:
# Allows you to issue voice commands from the frontend in enabled browsers
conversation:
# Enables support for tracking state changes over time.
history:
# View all events in a logbook
logbook:
# Track the sun
sun:
# Weather Prediction
sensor:
platform: yr
# Text to speech
tts:
platform: google
# IFTTT
ifttt:
key:
#### Scripts
nrkradio:
alias: Play Radio on Chromecast Audio
sequence:
- service: media_player.volume_set
data:
entity_id: media_player.hele_leiligheten
volume_level: '0.35'
- service: media_player.volume_set
data:
entity_id: media_player.bathroom
volume_level: '0.20'
- service: media_player.volume_set
data:
entity_id: media_player.stereo
volume_level: '0.30'
- service: media_player.volume_set
data:
entity_id: media_player.kitchen
volume_level: '0.30'
- service: media_player.play_media
data_template:
entity_id: >
{% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.stereo
{% elif is_state("input_select.chromecast_radio", "Bathroom") %} media_player.bathroom
{% elif is_state("input_select.chromecast_radio", "Kitchen") %} media_player.kitchen
{% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.hele_leiligheten
{% endif %}
media_content_id: >
{% if is_state("input_select.radio_station", "NRK P1") %} h__p://lyd.nrk._no/nrk_radio_p1_ostfold_mp3_h
{% elif is_state("input_select.radio_station", "NRK P3") %} h__p://lyd.nrk._no/nrk_radio_p3_mp3_h
{% elif is_state("input_select.radio_station", "NRK Klassisk") %} h__p://lyd._nrk.no/nrk_radio_klassisk_mp3_h
{% endif %}
media_content_type: 'audio/mp4'
1 Like
Bob_NL
(Bob Visser)
March 3, 2017, 5:28pm
13
Do you see the script under the Script tab in your frontend?
Your streaming links seem to miss the “http”:
h__p://lyd.nrk._no/nrk_radio_p3_mp3_h
If the links are wrong, it could be your script is failing to initialize and therefor not showing at all.
What does your home-assistant.log file look like?
Bob_NL
(Bob Visser)
March 3, 2017, 5:35pm
14
krsandvik:
script.nrk_radio:
Update: I see what’s the problem now:
script.nrk_radio: <--------
friendly_name: Start Playing
icon: mdi:play
No underscore in your group:
nrkradio:
name: NRK Radio
entities:
- input_select.radio_station
- input_select.chromecast_radio
- script.nrkradio
- input_slider.volume_radio
No underscore in your script:
nrkradio:
alias: Play Radio on Chromecast Audio
sequence:
.....
loose the underscore in your customize section and it will probably work
krsandvik
(Krsandvik)
March 3, 2017, 11:47pm
15
Still no go after the removing the underscore.
The URL I changed because of forum restictions
This is what I found in the home-assistant.log
17-03-03 23:39:19 ERROR (MainThread) [homeassistant.loader] Unable to find component nrkradio
1 Like
switched
(Jason)
March 4, 2017, 3:33am
16
It looks like you your script nrkradio isnt under a script header in your configuration file … HA thinks that your script name is a component hence the radio.
I use a separate file to load my scripts but you may be able to add th nrkradio script under a script: header config in the file.
1 Like
switched
(Jason)
March 4, 2017, 3:33am
17
Thanks @Bob_NL - works a treat.
2 Likes
Bob_NL
(Bob Visser)
March 4, 2017, 8:57am
18
Wow, can’t believe I missed that. Nice find!
krsandvik
(Krsandvik)
March 4, 2017, 9:15am
19
Oh, that was it. It is my first week with home assistant.
Thank you both very much!
2 Likes
This is very cool. I like the idea of having some buttons, like Dinner Party, Working in the Garage, etc. Then having those trigger some stations and possibly some lighting. Thanks for the examples!
1 Like
Hello @Bob_NL .
Friend, tell me, how many speakers do you have? 5? Can you share which ones? Does the sound go to the columns with only a chromecast? Sorry for my questions but this topic has not yet dominated.
Bob_NL
(Bob Visser)
March 5, 2017, 9:13pm
23
I currently have 4 speakers setup (just a couple of cheap ball speakers I got from Wallmart several years ago). Not the best sound quality but perfect for TTS and radio streaming.
Yes, sound is send straight to Chromecast. The nice thing of Chromecast Audio is that it’s a very affordable multiroom audio solution. “Sonos on a budget” (with a slight setback of options)
humm, ok so, i only need to buy a wireless speakers and one chromecast? do you have a idea, where i can buy it cheap?
Bob_NL
(Bob Visser)
March 5, 2017, 9:23pm
25
You don’t even need a wireless speaker, any speaker with a 3.5mm “headphone” jack will do (actually you absolutely do need the 3.5 inch jack input). Connection to your Chromecast is wireless, connection from your Chromecast to your speaker is wired (cable comes in the box with the Chromecast).
Off course you will need a seperate Chromecast per speaker (so you’ll need to buy several if you want multiroom audio).
I don’t have these myself but these supposed to be pretty decent for this price: https://www.amazon.com/JBL-Portable-Wireless-Bluetooth-Strap-Hook/dp/B00TFGWAA8