homebridge-cmd4: Television characteristic 'Active' not working from GUI

Another one for you John that has been on my to-do-list for a while and may have just stumbled across a potential issue; low priority but just thought I would create an issue for it.

Describe The Bug: The Television accessory I have created a shell script for would work when it was a simple Switch with only the characteristic On, but applying the same logic (wol command for on and mosquitto_pub for off) to the characteristic Active has not worked for me.

It would seem when I turn off the TV, I cannot issue the Active ‘true’ command again; at first I had figured maybe this has something to do with the addition of "linkedTypes" for TV and HDMI input sources and I had not set these up right. I am now thinking it has something to do with the characteristic Active itself and the GUI instead. The odd thing is if I set Active to true or false from my terminal, it works perfectly; but when I do it from the GUI; it does not work. Proof of working commands below.

Logs:

pi@homebridge:~ $ bash -x /home/pi/HisenseTV.sh Set TELEVISION Active false
+ ip=192.168.0.156
+ port=36669
+ '[' Set = Get ']'
+ '[' Set = Set ']'
+ case "$3" in
+ '[' false = true ']'
+ mosquitto_pub --cafile /home/pi/hisense.crt --insecure -h 192.168.0.156 -p 36669 -P multimqttservice -u hisenseservice -t /remoteapp/tv/remote_service/8C:84:01:20:57:18/actions/sendkey -m KEY_POWER
+ exit 0
pi@homebridge:~ $ bash -x /home/pi/HisenseTV.sh Set TELEVISION Active true
+ ip=192.168.0.156
+ port=36669
+ '[' Set = Get ']'
+ '[' Set = Set ']'
+ case "$3" in
+ '[' true = true ']'
+ wakeonlan 7C:B3:7B:76:77:D4
Sending magic packet to 255.255.255.255:9 with 7C:B3:7B:76:77:D4
+ exit 0
pi@homebridge:~ $

Shell Script:

Click to expand
#!/bin/bash

ip="192.168.0.156"
port="36669"

if [ "$1" = "Get" ]; then
  case "$3" in

    #Set to 1=CONFIGURED for all inputs added in config.json.
    IsConfigured )
      echo 1
      ;;

    # Set to 0=SHOWN for inputs configured.
    CurrentVisibilityState )
      echo 0
      ;;

    # Polls the TV over your network to see if it is still active.
    Active )
      if [ "$(timeout 2 /bin/bash -c "(echo > /dev/tcp/192.168.0.156/36669)" > /dev/null 2>&1 && echo 1 || echo 0)"  = '1' ]; then
        echo 1
      else
        echo 0
      fi
      ;;

    ActiveIdentifier )
     # For now TV=1 and anything else is HDMI1 as I am keeping it simple with 2 sources
        if [ "$(timeout 2 /bin/bash -c "(echo > /dev/tcp/192.168.0.156/36669)" > /dev/null 2>&1 && echo 1 || echo 0)"  = '1' ]; then

         input=$(mosquitto_sub --cafile /home/pi/hisense.crt --tls-version tlsv1.2 --insecure -W 1 -h $ip -p $port -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.sourceid')
         case "$input" in

            '"TV"' )
                  echo 0
            ;;

            '"HDMI1"' )
                   echo 1
            ;;
         esac

        else
          echo 0
        fi
     ;;

  esac
fi

if [ "$1" = "Set" ]; then
  case "$3" in

    Active )
      if [ "$4" = "true" ]; then
        #TV can only be turned back on by WOL using MAC ADDRESS
        wakeonlan 7C:B3:7B:76:77:D4

      else
        #TV can turn off using MQTT
        mosquitto_pub --cafile /home/pi/hisense.crt --insecure -h $ip -p $port -P multimqttservice -u hisenseservice -t "/remoteapp/tv/remote_service/8C:84:01:20:57:18$normal/actions/sendkey" -m "KEY_POWER"
      fi
    ;;

    ActiveIdentifier )
      case "$4" in
        #TV
        0 )
        mosquitto_pub --cafile /home/pi/hisense.crt --insecure -h $ip -p $port -P multimqttservice -u hisenseservice -t "/remoteapp/tv/ui_service/8C:84:01:20:57$normal/actions/changesource" -m '{"sourceid":"0","sourcename":"TV"}'
        ;;

        #HDMI1
        1 )
        mosquitto_pub --cafile /home/pi/hisense.crt --insecure -h $ip -p $port -P multimqttservice -u hisenseservice -t "/remoteapp/tv/ui_service/8C:84:01:20:57$normal/actions/changesource" -m '{"sourceid":"4","sourcename":"HDMI1"}'
        ;;
      esac
    ;;

esac
fi


exit 0

Config:

Click to expand
{
                    "type": "Television",
                    "outputConstants": true,
                    "category": "TELEVISION",
                    "publishExternally": true,
                    "name": "TELEVISION",
                    "active": "ACTIVE",
                    "activeIdentifier": 0,
                    "configuredName": "TELEVISION",
                    "sleepDiscoveryMode": "ALWAYS_DISCOVERABLE",
                    "linkedTypes": [
                        {
                            "type": "InputSource",
                            "displayName": "TV",
                            "configuredName": "TV",
                            "currentVisibilityState": "SHOWN",
                            "inputSourceType": "TUNER",
                            "isConfigured": "CONFIGURED",
                            "identifier": 0,
                            "targetVisibilityState": "SHOWN",
                            "name": "TV"
                        },
                        {
                            "type": "InputSource",
                            "displayName": "HDMI 1",
                            "configuredName": "HDMI 1",
                            "currentVisibilityState": "SHOWN",
                            "inputSourceType": "HDMI",
                            "isConfigured": "CONFIGURED",
                            "identifier": 1,
                            "targetVisibilityState": "SHOWN",
                            "name": "HDMI 1"
                        }
                    ],
                    "remoteKey": "SELECT",
                    "polling": [
                        {
                            "characteristic": "active",
                            "interval": 50,
                            "timeout": 5000
                        },
                        {
                            "characteristic": "activeIdentifier",
                            "interval": 50,
                            "timeout": 5000
                        }
                    ],
                    "stateChangeResponseTime": 1,
                    "state_cmd": "bash /home/pi/HisenseTV.sh"
                }

Environment:

  • Node.js Version: v14.15.4
  • NPM Version: v6.14.11
  • Homebridge Version: v1.2.5
  • Operating System: Raspbian
  • Process Supervisor: hb-service

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (17 by maintainers)

Most upvoted comments

After much work by all, I’m glad to close this one.

Gotta go back to bed. Ttyl.

John

On Mon, Feb 1, 2021 at 1:06 AM John Talbot ztalbot2000@gmail.com wrote:

Output constants set to false will make active send 0 or 1 as it is supposed to, being a uint format. Having outputConstants set to true it would send the strings "INACTIVE’ or “ACTIVE”

Bool types send 0 or 1 with outputConstants set to false and the strings “FALSE” “TRUE” when outputConstants is true.

As for the restart glitch, I’ll test these tomorrow. I’ve never seen it myself.

TTFN, John

On Mon, Feb 1, 2021 at 1:01 AM Mitch Williams notifications@github.com wrote:

So that means I would need outputConstants set to false; which I currently have it set to true.

Yeah I have had the glitch once or twice where it separates them; a restart always fixes it. But took a screenshot in case the linkedType being ‘on’ while the main service is ‘off’ is what is stopping me from turning it on (active); due to thinking something in the service is already ‘on’. If you get my thought process.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/81#issuecomment-770593727, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX6WLCZOQQ6LYIJ7T53S4Y7SDANCNFSM4WRKZMBQ .

I’m not going to give up. Everything I try is a step in the right direction. I especially like the unit tests, because they are easily repeatable against everything I do.

You have been a great help, believe me!

ttfn, John

On Mon, Feb 1, 2021 at 12:40 AM Mitch Williams notifications@github.com wrote:

Me too! I just wish I could do more than just present problems and have more skills to find the solution haha you should have everything of mine in that first post, but let me know if there is anything else you might need from me or want me to try.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/81#issuecomment-770583582, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX6IAEVNULLFPGRM5PLS4Y5DNANCNFSM4WRKZMBQ .

Hi,

I have not forgot about this. I tried to reproduce it, but could not. It can be very tedious at times and error prone trying. I stopped for a while to complete the Cmd4 Portal on the GitHub pages of https://ztalbot2000.github.io/homebridge-cmd4/autoGenerated/CMD4_AccessoryDescriptions.html Anyway that’s done for awhile. I started on your issue again yesterday tackling it from a unit testing perspective. I’m trying to use sinon to pump commands directly into Cmd4Accessory.getValue and Cmd4Accessory.setValue. It’s not easy either, but it is the best way to procédé as automating this makes it a continuous process forever. I hope to have an answer soon.

John