Skip to content

Instantly share code, notes, and snippets.

@jonkristian
Last active January 19, 2018 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonkristian/6a0ef7b04168b13b2b1ff3a378e13716 to your computer and use it in GitHub Desktop.
Save jonkristian/6a0ef7b04168b13b2b1ff3a378e13716 to your computer and use it in GitHub Desktop.
Home Assistant - Radio with chromecast and xiaomi cube control
- id: radio_cube_play
alias: Play radio with cube
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000101ad7b
action_type: shake_air
condition:
- condition: template
value_template: >
{% if is_state('media_player.bathroom_speaker', 'off') %}
true
{% else %}
false
{% endif %}
action:
- service: input_number.set_value
data:
entity_id: input_number.volume_radio
value: '0.15'
- service: media_player.volume_mute
data:
entity_id: media_player.bathroom_speaker
is_volume_muted: "false"
- service: input_select.select_option
entity_id: input_select.radio_station
data:
option: "P4"
- id: radio_cube_source
alias: Change radio source with cube
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000101ad7b
action_type: tap_twice
condition:
- condition: template
value_template: >
{% if is_state('media_player.bathroom_speaker', 'playing') %}
true
{% else %}
false
{% endif %}
action:
- service: input_select.select_next
entity_id: input_select.chromecast_radio
- id: radio_cube_next
alias: Next radio station with cube
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000101ad7b
action_type: flip90
condition:
- condition: template
value_template: >
{% if is_state('media_player.bathroom_speaker', 'playing') %}
true
{% else %}
false
{% endif %}
action:
- service: input_select.select_next
entity_id: input_select.radio_station
- id: radio_cube_previous
alias: Previous radion station with cube
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000101ad7b
action_type: flip180
condition:
- condition: template
value_template: >
{% if is_state('media_player.bathroom_speaker', 'playing') %}
true
{% else %}
false
{% endif %}
action:
- service: input_select.select_previous
entity_id: input_select.radio_station
- id: radio_cube_volume
alias: Change radio volume with cube
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000101ad7b
action_type: rotate
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.bathroom_speaker
volume_level: >
{%if trigger.event.data.action_value | float > 0 %}
{{ states.media_player.bathroom_speaker.attributes.volume_level | float + 0.05 }}
{% else %}
{{ states.media_player.bathroom_speaker.attributes.volume_level | float - 0.05 }}
{% endif %}
- id: radio_cube_stop
alias: Stop radio with cube
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000101ad7b
action_type: shake_air
condition:
- condition: template
value_template: >
{% if is_state('media_player.bathroom_speaker', 'playing') %}
true
{% else %}
false
{% endif %}
action:
- service: input_select.select_option
entity_id: input_select.radio_station
data:
option: "Off"
- id: radio_select
alias: Listen Radio
hide_entity: True
trigger:
- platform: state
entity_id: input_select.radio_station
action:
- service: script.radio
volume_radio:
name: Volume
icon: mdi:volume-high
min: 0
max: 1
step: 0.05
radio_station:
name: 'Select Radio Station:'
options:
- NRK P1
- NRK P2
- NRK P3
- P4
- Nyheter
- Sport
- Rock
- Klassisk Rock
- Avslapning
- Jazz
chromecast_radio:
name: 'Select Speakers:'
options:
- Bathroom
- Living Room
- Everywhere
initial: Bathroom
icon: mdi:speaker-wireless
radio:
alias: Play Radio on Chromecast Audio
sequence:
- service: media_player.volume_set
data_template:
entity_id: >
{% if is_state("input_select.chromecast_radio", "Bathroom") %} media_player.bathroom_speaker
{% elif is_state("input_select.chromecast_radio", "Living Room") %} media_player.living_room
{% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.home_group
{% endif %}
volume_level: '{{ states.input_number.volume_radio.state }}'
- service: tts.google_say
data_template:
entity_id: >
{% if is_state("input_select.chromecast_radio", "Bathroom") %} media_player.bathroom_speaker
{% elif is_state("input_select.chromecast_radio", "Living Room") %} media_player.living_room
{% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.home_group
{% endif %}
message: "{{ states.input_select.radio_station.state }}"
- delay: '00:00:03'
- service: media_player.play_media
data_template:
entity_id: >
{% if is_state("input_select.chromecast_radio", "Bathroom") %} media_player.bathroom_speaker
{% elif is_state("input_select.chromecast_radio", "Living Room") %} media_player.living_room
{% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.home_group
{% endif %}
media_content_id: >
{% if is_state("input_select.radio_station", "NRK P1") %} http://lyd.nrk.no/nrk_radio_p1_ostlandssendingen_mp3_h
{% elif is_state("input_select.radio_station", "NRK P2") %} http://lyd.nrk.no/nrk_radio_p2_mp3_h
{% elif is_state("input_select.radio_station", "NRK P3") %} http://lyd.nrk.no/nrk_radio_p3_mp3_h
{% elif is_state("input_select.radio_station", "P4") %} http://stream.p4.no/p4_mp3_hq
{% elif is_state("input_select.radio_station", "Nyheter") %} http://lyd.nrk.no/nrk_radio_alltid_nyheter_mp3_h
{% elif is_state("input_select.radio_station", "Sport") %} http://lyd.nrk.no/nrk_radio_sport_mp3_h
{% elif is_state("input_select.radio_station", "Rock") %} http://stream.p4.no/p6_mp3_hq
{% elif is_state("input_select.radio_station", "Klassisk Rock") %} http://91.221.151.155/listen.mp3
{% elif is_state("input_select.radio_station", "Avslapning") %} http://live.radioart.com/fSleep.mp3
{% elif is_state("input_select.radio_station", "Jazz") %} http://lyd.nrk.no/nrk_radio_jazz_mp3_h
{% endif %}
media_content_type: 'audio/mp4'
@jonkristian
Copy link
Author

jonkristian commented Jan 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment