Advertisement
Snake8140

HA_SkyQ_MediaPlayer

Apr 12th, 2020
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #!/bin/bash
  2. IP="192.168.1.15"
  3. NAME="SkyQ Black"
  4. DIR="/home/homeassistant/.homeassistant/packages"
  5. FILE_MP="skyq_mediaplayer.yaml"
  6. FILE_CH="skyq_channels.yaml"
  7.  
  8. echo "Creating/Updating ${DIR}/${FILE_MP} file..."
  9.  
  10. echo "
  11. media_player:
  12. - platform:  skyq
  13.  name: ${NAME}
  14.  host: ${IP}
  15.  #config_directory: '${DIR}/'
  16.  #generate_switches_for_channels: true
  17.  sources:" > ${DIR}/${FILE_MP}
  18.  
  19. echo "Creating/Updating ${DIR}/${FILE_CH} file..."
  20.  
  21. echo "
  22. switch:
  23.  - platform: template
  24.    switches:" > ${DIR}/${FILE_CH}
  25.  
  26. echo "Getting SkyQ channel list..."
  27.  
  28. BODYRESPONSE=$(curl -s --location --request GET ${IP}:9006/as/services)
  29.  
  30. echo "Updating channel list..."
  31.  
  32. services=$( jq -r '.services' <<< "${BODYRESPONSE}" )
  33.  
  34. for row in $(echo "${services}" | jq -r '.[] | @base64'); do
  35.     channelName=`echo ${row} | base64 --decode | jq -r ${1} '.t' | tr -d ' ' | tr -d \' | sed 's/#//'`
  36.     channelNr=`echo ${row} | base64 --decode | jq -r ${1} '.c'`
  37.     channelNrCmd=`echo ${row} | base64 --decode | jq -r ${1} '.c' | sed 's/\(.\{1\}\)/\1,/g' | sed 's/.$//'`
  38.    
  39.     echo "    "${channelName}: \'${channelNrCmd}\' >> ${DIR}/${FILE_MP}
  40.  
  41.     echo "      canale_${channelNr}:
  42.        value_template: '{{\"off\"}}'
  43.        turn_on:
  44.          service: media_player.select_source
  45.          data:
  46.            entity_id: media_player.skyq_black
  47.            source: '${channelName}'
  48.        turn_off:
  49.          service: script.placeholder" >> ${DIR}/${FILE_CH}
  50.  
  51. done
  52. echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement