RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    sleep / wake scripts for Sony BRAVIA TVs and Bluetooth Xbox One Controller

    Scheduled Pinned Locked Moved Projects and Themes
    scriptssony receiversleep modexbox controller
    1 Posts 1 Posters 359 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kentzo
      last edited by

      I recently finished integrating RetroPie with my AV system. Hope these sleep/wake scripts will be useful to someone else too.

      I wanted RetroPie to turn off my AV and disconnect the bluetooth controller on sleep. On wake I wanted it to turn on my AV and select the appropriate Input.

      I could not (or missed how) use HDMI-CEC since it only controlled my TV and not my AV receiver with other connected peripherals. I had to use Sony Bravia Rest API instead.

      ~/.emulationstation/scripts/sleep/1_hdmi_sleep.sh

      #!/usr/bin/env bash
      
      # Only turn off the AV system if RetroPie is the current input
      # which on my system is HDMI 2.
      
      tvIP="..." # IP reserved for the TV (statically or via a DHCP server)
      currentInput=$(\
        curl \
          --silent \
          -X POST \
          -H "Content-Type: application/js" \
          -H "X-Auth-PSK: ..." \ # password you set up on the TV
          -d "{\"id\": 103, \"method\": \"getPlayingContentInfo\", \"version\": \"1.0\", \"params\": []}" \
          http://${tvIP}/sony/avContent
      )
      
      if [[ "${currentInput}" =~ "extInput:hdmi?port=2" ]]; then 
        curl \
          --silent \
          -X POST \
          -H "Content-Type: application/js" \
          -H "X-Auth-PSK: ..." \ # password you set up on the TV
          -d "{\"id\": 20, \"method\": \"setPowerStatus\", \"version\": \"1.0\", \"params\": [{\"status\": false}]}" \
          http://${tvIP}/sony/system
      fi
      
      # No need to waste power on the HDMI port
      vcgencmd display_power 0
      

      ~/.emulationstation/scripts/sleep/2_bt_sleep.sh

      #!/usr/bin/env bash
      
      controllerMac="..." # bluetooth Mac address of the xbox controller
      coproc bluetoothctl
      echo -e 'agent on\ndisconnect ${controllerMac}\nexit\n' >&${COPROC[1]}
      wait ${COPROC_PID}
      

      ~/.emulationstation/scripts/wake/1_hdmi_wake.sh

      #!/usr/bin/env bash
      
      # Unconditionally turn on the AV and switch input to RetroPie 
      # which on my system is HDMI 2.
      
      tvIP="..." # IP reserved for the TV (statically or via a DHCP server)
      
      vcgencmd display_power 1
      
      sleep 1
      
      curl \
        --silent \
        -X POST \
        -H "Content-Type: application/js" \
        -H "X-Auth-PSK: ..." \ # password you set up on the TV
        -d "{\"id\": 20, \"method\": \"setPowerStatus\", \"version\": \"1.0\", \"params\": [{\"status\": true}]}" \
        http://${tvIP}/sony/system
      
      sleep 5
      
      curl \
        --silent \
        -X POST \
        -H "Content-Type: application/js" \
        -H "X-Auth-PSK: ..." \ # password you set up on the TV
        -d "{\"id\": 20, \"method\": \"setPlayContent\", \"version\": \"1.0\", \"params\": [{\"uri\": \"extInput:hdmi\?port=2\"}]}" \
        http://${tvIP}/sony/avContent
      

      What's left out is "waking" the RetroPie whenever I turn on my controller, but there is no simple way right now:

      • RetroPie does not support an event like this, so one would have to use bluez
      • Couldn't find how to "wake" RetroPie from CLI
      1 Reply Last reply Reply Quote 2
      • First post
        Last post

      Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

      Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.