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)
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:
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:
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