From 5cb9ed1c83eb592b7cc30dfee34f0fccf89b672a Mon Sep 17 00:00:00 2001 From: Georgi Gardev Date: Sat, 4 Apr 2020 20:02:33 +0300 Subject: [PATCH] Add twitch controls. Improve TV and Shield --- config/lovelace/home_dashboard/07_media.yaml | 65 ++++++++++++++++++ config/lovelace/home_dashboard/09_system.yaml | 1 + config/packages/modules/media/music.yaml | 36 ---------- config/packages/modules/media/sonos.yaml | 47 +++++++++++++ config/packages/modules/media/tv.yaml | 67 ++++++++++++++----- config/packages/modules/media/twitch.yaml | 8 +++ config/packages/modules/speech.yaml | 2 +- config/secrets.example.yaml | 2 + 8 files changed, 174 insertions(+), 54 deletions(-) create mode 100644 config/packages/modules/media/sonos.yaml create mode 100644 config/packages/modules/media/twitch.yaml diff --git a/config/lovelace/home_dashboard/07_media.yaml b/config/lovelace/home_dashboard/07_media.yaml index 6220c97..b74b3c6 100644 --- a/config/lovelace/home_dashboard/07_media.yaml +++ b/config/lovelace/home_dashboard/07_media.yaml @@ -4,6 +4,71 @@ panel: false icon: mdi:youtube badges: [] cards: + - type: vertical-stack + cards: + - type: custom:button-card + template: small + entity: script.tv_fireplace + name: Fireplace + - type: custom:config-template-card + entities: + - sensor.day9tv + - sensor.lirik + - sensor.cohhcarnage + - sensor.sacriel + card: + type: vertical-stack + title: Twitch + cards: + - type: horizontal-stack + cards: + - type: picture-entity + entity: sensor.day9tv + image: ${states['sensor.day9tv'].attributes.entity_picture} + state_filter: + "online": brightness(110%) + "offline": brightness(50%) saturate(0) + tap_action: + action: call-service + service: script.tv_twitch + service_data: + channel: day9tv + - type: picture-entity + entity: sensor.lirik + image: ${states['sensor.lirik'].attributes.entity_picture} + state_filter: + "online": brightness(110%) + "offline": brightness(50%) saturate(0) + tap_action: + action: call-service + service: script.tv_twitch + service_data: + channel: lirik + - type: horizontal-stack + cards: + - type: picture-entity + entity: sensor.cohhcarnage + image: ${states['sensor.cohhcarnage'].attributes.entity_picture} + state_filter: + "online": brightness(110%) + "offline": brightness(50%) saturate(0) + tap_action: + action: call-service + service: script.tv_twitch + service_data: + channel: cohhcarnage + - type: picture-entity + entity: sensor.sacriel + image: ${states['sensor.sacriel'].attributes.entity_picture} + state_filter: + "online": brightness(110%) + "offline": brightness(50%) saturate(0) + tap_action: + action: call-service + service: script.tv_twitch + service_data: + channel: sacriel + - type: vertical-stack cards: - type: entities diff --git a/config/lovelace/home_dashboard/09_system.yaml b/config/lovelace/home_dashboard/09_system.yaml index f5b5b99..09213be 100644 --- a/config/lovelace/home_dashboard/09_system.yaml +++ b/config/lovelace/home_dashboard/09_system.yaml @@ -8,6 +8,7 @@ cards: show_header_toggle: false entities: - automation.youtube_download_latest_pds + - automation.tv_join_beam_to_sonos_group_when_off - type: custom:fold-entity-row head: diff --git a/config/packages/modules/media/music.yaml b/config/packages/modules/media/music.yaml index d70b38a..116b81b 100644 --- a/config/packages/modules/media/music.yaml +++ b/config/packages/modules/media/music.yaml @@ -1,36 +1,8 @@ -# https://www.home-assistant.io/integrations/sonos -sonos: - media_player: - hosts: !secret sonos_hosts - # https://www.home-assistant.io/integrations/spotify spotify: client_id: !secret spotify_client_id client_secret: !secret spotify_client_secret -group: - all_sonos: - name: All Sonos - entities: - - media_player.master_bedroom - - media_player.living_room - - media_player.kitchen - - media_player.bathroom - -binary_sensor: - - platform: template - sensors: - sonos_recoverable: - friendly_name: Sonos recoverable - entity_id: media_player.master_bedroom - value_template: >- - {% if state_attr('media_player.master_bedroom', 'media_content_id').startswith('x-sonos-spotify:spotify') - or state_attr('media_player.master_bedroom', 'media_content_id').startswith('x-sonosapi-hls-static') %} - True - {% else %} - False - {% endif %} - script: music_play: alias: Music · Play @@ -49,14 +21,6 @@ script: entity_id: media_player.master_bedroom source: "{{ playlist | default('Evening Chill') }}" - music_join_sonoses: - alias: Music · Join Sonoses - sequence: - - service: sonos.join - entity_id: group.all_sonos - data_template: - master: media_player.master_bedroom - automation: - alias: Music · Play/Pause on Magic Cube Knock trigger: diff --git a/config/packages/modules/media/sonos.yaml b/config/packages/modules/media/sonos.yaml new file mode 100644 index 0000000..2886b2f --- /dev/null +++ b/config/packages/modules/media/sonos.yaml @@ -0,0 +1,47 @@ +# https://www.home-assistant.io/integrations/sonos +sonos: + media_player: + hosts: !secret sonos_hosts + +group: + all_sonos: + name: All Sonos + entities: + - media_player.master_bedroom + - media_player.living_room + - media_player.kitchen + - media_player.bathroom + +binary_sensor: + - platform: template + sensors: + sonos_recoverable: + friendly_name: Sonos recoverable + entity_id: media_player.master_bedroom + value_template: >- + {% if state_attr('media_player.master_bedroom', 'media_content_id').startswith('x-sonos-spotify:spotify') + or state_attr('media_player.master_bedroom', 'media_content_id').startswith('x-sonosapi-hls-static') %} + True + {% else %} + False + {% endif %} + +script: + music_join_sonoses: + alias: Music · Join Sonoses + sequence: + - service: sonos.join + entity_id: group.all_sonos + data_template: + master: media_player.master_bedroom + +homeassistant: + customize: + media_player.master_bedroom: + icon: mdi:speaker + media_player.living_room: + icon: mdi:speaker + media_player.kitchen: + icon: mdi:speaker + media_player.bathroom: + icon: mdi:speaker diff --git a/config/packages/modules/media/tv.yaml b/config/packages/modules/media/tv.yaml index 31dbef4..0d1400b 100644 --- a/config/packages/modules/media/tv.yaml +++ b/config/packages/modules/media/tv.yaml @@ -6,12 +6,6 @@ webostv: service: wake_on_lan.send_magic_packet data: mac: !secret living_room_tv_mac - # customize: - # sources: - # - livetv - # - youtube - # - makotv - # - netflix media_player: - platform: androidtv @@ -19,24 +13,26 @@ media_player: host: !secret nvidia_shield_host script: + tv_twitch: + icon: mdi:twitch + alias: TV · Start Twitch stream + sequence: + - service: script.tv_prepare_for_playback + - service: androidtv.adb_command + entity_id: media_player.nvidia_shield + data_template: + command: "am start -a android.intent.action.VIEW -d twitch://stream/{{ channel }}" + tv_fireplace: icon: mdi:fireplace alias: TV · Fireplace sequence: - - service: sonos.unjoin + - service: script.tv_prepare_for_playback data: - entity_id: media_player.living_room - - service: media_player.select_source - data: - entity_id: media_player.living_room - source: TV - - service: media_player.volume_set - data: - entity_id: media_player.living_room volume_level: 0.08 - service: media_extractor.play_media + entity_id: media_player.shield data: - entity_id: media_player.shield media_content_id: "https://www.youtube.com/watch?v=AWKzr6n0ea0" media_content_type: video/youtube @@ -44,7 +40,44 @@ script: alias: Play the latest PDS sequence: - service: media_extractor.play_media + entity_id: media_player.shield data_template: - entity_id: media_player.shield media_content_id: "{{ state_attr('sensor.philip_defranco', 'url') }}" media_content_type: video/youtube + + tv_prepare_for_playback: + alias: TV · Prepare for playback + sequence: + - service: sonos.unjoin + entity_id: media_player.living_room + - service: media_player.select_source + entity_id: media_player.living_room + data: + source: TV + - service: media_player.volume_set + entity_id: media_player.living_room + data_template: + volume_level: "{{ volume_level | default(0.3) }}" + - service: media_player.turn_on + entity_id: media_player.nvidia_shield + +automation: + - alias: TV · Join Beam to Sonos group when off + trigger: + platform: state + entity_id: media_player.living_room_tv + to: "off" + action: + - service: sonos.join + data: + master: media_player.master_bedroom + entity_id: media_player.living_room + +homeassistant: + customize: + media_player.living_room_tv: + icon: mdi:television + friendly_name: LG TV + media_player.nvidia_shield: + icon: mdi:television-ambient-light + friendly_name: Nvidia Shield diff --git a/config/packages/modules/media/twitch.yaml b/config/packages/modules/media/twitch.yaml new file mode 100644 index 0000000..16f2feb --- /dev/null +++ b/config/packages/modules/media/twitch.yaml @@ -0,0 +1,8 @@ +sensor: + - platform: twitch + client_id: !secret twitch_client_id + channels: + - LIRIK + - day9tv + - cohhcarnage + - sacriel diff --git a/config/packages/modules/speech.yaml b/config/packages/modules/speech.yaml index 763de5f..f8512a8 100644 --- a/config/packages/modules/speech.yaml +++ b/config/packages/modules/speech.yaml @@ -69,7 +69,7 @@ script: entity_id: input_boolean.sarah_talking # Don't shout :) - service: media_player.volume_set - entity_id: group.all_sonos + entity_id: media_player.master_bedroom data_template: volume_level: >- {% if now().strftime('%H')|int < 6 and now().strftime('%H')|int > 0 %} diff --git a/config/secrets.example.yaml b/config/secrets.example.yaml index f7e8e7e..e6f7dfe 100644 --- a/config/secrets.example.yaml +++ b/config/secrets.example.yaml @@ -98,3 +98,5 @@ tile_password: pass tuya_username: email tuya_password: pass + +twitch_client_id: client-id