ztalbot2000 / homebridge-cmd4

CMD4 Plugin for Homebridge - Supports ~All Accessory Types & now all Characteristics too
Apache License 2.0
149 stars 14 forks source link

Shell Script Help Using 'Mosquitto_sub' and 'jq' #65

Closed mitch7391 closed 4 years ago

mitch7391 commented 4 years ago

@ztalbot2000 I am not sure if you look over shell scripts when people are stuck, but I am still learning this stuff and can't seem to get any help with what I am doing wrong.

My shell script calls the functions 'mosquitto' sub and uses 'jq' to parse the json output. Currently the mosquitto_pub in my 'Set' section works perfectly but something is wrong with the mosquitto_sub in my 'Get' section that is being parsed by 'jq'. Right now I am trying to make a simple switch for my TV that uses MQTT, but once I have figured out this 'easier' bit, I will use that as an example to try and create a TV accessory.

If I run the commands in my terminal, they work perfectly, but once the same mosquitto_sub command is used in my shell script or the shell script is referenced by bash command in my terminal, it does not work. Here is a link to my bash script:

https://pastebin.com/BgdXvinp

When I run the mosquitto command in my terminal, I get the following response (proof the raw command connects and works):

_pi@homebridge:~ $ mosquitto_sub --cafile /home/pi/hisense.crt --tls-version tlsv1.2 --insecure -T -v -h 192.168.0.156 -p 36669 -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.issignal' 1

When I run the shell script as per cmd4 fault finding via bash:

pi@homebridge:~` $ bash -x HisenseSwitch.sh Get anything On

+ bash -x HisenseSwitch.sh Get anything On

+ ip=192.168.0.156

+ port=36669

+ '[' Get = Get ']'

+ case "$3" in

_++ mosquitto_sub --cafile /home/pi/hisense.crt --tls-version tlsv1.2 --insecure -h 192.168.0.156 -p 36669 -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/uiservice/state

_++ jq .issignal

I do not seem to get an output of 1 or 0 as I expect and like I do with the same command straight on my terminal; it seems to get stuck on response jq .is_signal and will stay like that until I cancel the command (ctrl+c). Also it is worth mentioning that I have the cmd4 config for a switch set up correctly in my config.json (not that it is being used at this stage where I am stuck). Any suggestions or guidance would be greatly appreciated, as I am sure it is just a simple noob mistake. Thanks in advance :)

mitch7391 commented 4 years ago

Also the json output from this mosquitto topic before it is parsed through jq is as follows:

{"statetype":"sourceswitch","sourceid":"HDMI1","sourcename":"HDMI1","is_signal":1,"is_lock":0,"hotel_mode":0,"displayname":"HDMI1"}

ztalbot2000 commented 4 years ago

Hi,

Just to say I read your message and will look at it a little later. Scripts are tricky. When they run from a process, they do not have access to any variables in your profile or paths you may have set up differently than the system has. In Extras/Cmd4Scripts there is a shell called CheckYourScript.sh and it's use is in the README. It may prove that your script fails. You may wish to have a look at this in the meantime. It may be useful. It's a shot for now.

I know that HomeBridge has an MQTT plugin if that helps too.

Ttyl, John

On Tue, Aug 18, 2020 at 7:50 AM mitch7391 notifications@github.com wrote:

Also the json output from this mosquitto topic before it is parsed through jq is as follows:

{"statetype":"sourceswitch","sourceid":"HDMI1","sourcename":"HDMI1","is_signal":1,"is_lock":0,"hotel_mode":0,"displayname":"HDMI1"}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-675431969, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCXZAZZKMICFEHKF7KX3SBJTKBANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Thanks John :) I will give the CheckYouScript.sh a go, I actually didn't think of that as last time I was able to slowly fault find my last project's shell script with the use of bash -x; but mostly with the help of someone from reddit. I will keep you updated on if I manage to figure it out before you get a chance to take a peak.

Also I am aware of homebridge-mqttthings plugin; originally I could not use it due to my need to have a 'cert file' and --insecure, but after the developer implemented that I still could not get his plugin to work; I have not been able to confirm with him yet whether I have the config correct. Pretty much I am trying to work on both methods but would probably prefer it to work with your plugin as there is a known issue with this TV for sending the ON command when it is off (most likely due to the MQTT broker turning off when the TV does), so I will need to implement WOL potentially as my ON command and use the rest as mosquitto; essentially a combo of methods to create a functioning accessory.

mitch7391 commented 4 years ago

Actually thinking about it more, my script will fail when using CheckYouScript.sh as when I call bash -x HisenseSwitch.sh Get anything On, I am not getting the output of my 'Get', if I run bash -x HisenseSwitch.sh Set anything On False it executes with no issue and turns my TV off. Or it is the 'Set' part of my script that fails.

mitch7391 commented 4 years ago

The timeout for my accessory config in my homebridge config.json? As the shell script does not have a timeout used and considering it is not working past the shell script point yet I had not thought to fiddle with the accessory config. I am hoping it is just something silly in the shell script or maybe how the shell script uses my working mosquitto_sub and jq functions (as they all work as raw terminal command of mosquitto_sub into jq) :)

ztalbot2000 commented 4 years ago

Yes in the config.json. If the timer fires while your script is running, it kills the script and returns false. This is in case of a runaway script.

Ttyl, John

On Tue, Aug 18, 2020 at 8:48 AM mitch7391 notifications@github.com wrote:

The timeout for my accessory config in my homebridge config.json? As the shell script does not have a timeout used and considering it is not working past the shell script point yet I had not thought to fiddle with the accessory config. I am hoping it is just something silly in the shell script or maybe how the shell script uses my working mosquitto_sub and jq functions (as they all work as raw terminal command of mosquitto_sub into jq) :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-675457602, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX7J6IJ2ZRKEPQAPXR3SBJ2BXANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

I just tried to use the this config:

{

                "type": "Switch",
                "displayName": "My_Switch",
                "on": "FALSE",
                "name": "Hisense",
                "stateChangeResponseTime": 1,
                "state_cmd": "bash /home/pi/HisenseSwitch.sh",
                "polling": [
                    {
                        "on": "FALSE",
                        "interval": 540,
                        "timeout": 8000
                    }
                ]
            },

And returned this in my Homebridge logs when I tried to get the accessory to load:

[8/18/2020, 21:06:05] [Cmd4] getGeneric On function for:My_Switch cmd:bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On' failed.

[8/18/2020, 21:06:05] [Cmd4] Error: Command failed: bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On'

at ChildProcess.exithandler (child_process.js:303:12)
at ChildProcess.emit (events.js:315:20)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

{ killed: true, code: null, signal: 'SIGTERM', cmd: "bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On'" } [8/18/2020, 21:06:05] [Cmd4] [8/18/2020, 21:06:05] [Cmd4]

mitch7391 commented 4 years ago

So timeout didn't work sadly, but worth a go :)

ztalbot2000 commented 4 years ago

You script has if $4 = "true". CMD4 only sends strings of true or false if outputConstants is set to true and by default it is set to false.

I hope this is your answer,

Ttyl, John

On Tue, Aug 18, 2020 at 8:52 AM John Talbot ztalbot2000@gmail.com wrote:

Yes in the config.json. If the timer fires while your script is running, it kills the script and returns false. This is in case of a runaway script.

Ttyl, John

On Tue, Aug 18, 2020 at 8:48 AM mitch7391 notifications@github.com wrote:

The timeout for my accessory config in my homebridge config.json? As the shell script does not have a timeout used and considering it is not working past the shell script point yet I had not thought to fiddle with the accessory config. I am hoping it is just something silly in the shell script or maybe how the shell script uses my working mosquitto_sub and jq functions (as they all work as raw terminal command of mosquitto_sub into jq) :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-675457602, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX7J6IJ2ZRKEPQAPXR3SBJ2BXANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

I just tried setting "outputConstants": true in my config but much the same error sadly:

[8/18/2020, 21:29:32] [Cmd4] getGeneric On function for:My_Switch cmd:bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On' failed. [8/18/2020, 21:29:32] [Cmd4] Error: Command failed: bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On'

at ChildProcess.exithandler (child_process.js:303:12)
at ChildProcess.emit (events.js:315:20)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

{ killed: true, code: null, signal: 'SIGTERM', cmd: "bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On'" } [8/18/2020, 21:29:32] [Cmd4] [8/18/2020, 21:29:32] [Cmd4]

I actually never had to have "outputConstants": true for my last project, which actually had some switches that would have used $4 = "true" in some parts of it (https://github.com/mitch7391/cmd4-E-Zone-MyAir).

ztalbot2000 commented 4 years ago

Hi Mitch Before if $4. Try echo $4 > /tmp/output

Then after the script runs and fails look at /tmp/output

I want to make sure we know what we are getting. You can also add commands like this elsewhere to see what is going on at the time.

Ttyl, John

On Tue, Aug 18, 2020 at 9:37 AM mitch7391 notifications@github.com wrote:

I just tried setting "outputConstants": true in my config but much the same error sadly:

[8/18/2020, 21:29:32] [Cmd4] getGeneric On function for:My_Switch cmd:bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On' failed.

[8/18/2020, 21:29:32] [Cmd4] Error: Command failed: bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On'

at ChildProcess.exithandler (child_process.js:303:12)

at ChildProcess.emit (events.js:315:20)

at maybeClose (internal/child_process.js:1021:16)

at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

{

killed: true,

code: null,

signal: 'SIGTERM',

cmd: "bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On'"

}

[8/18/2020, 21:29:32] [Cmd4]

[8/18/2020, 21:29:32] [Cmd4]

I actually never had to have "outputConstants": true for my last project, which actually had some switches that would have used $4 = "true" in some parts of it (https://github.com/mitch7391/cmd4-E-Zone-MyAir).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-675483246, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX2G65VRHGGKNQ72P5DSBJ7YHANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

I have just done this now John, this is where I put the new line in my script (hopefully in the right spot):

image

And the value written to this file was true. Hope this helps?

ztalbot2000 commented 4 years ago

Hi,

Thanks. I know stupid question, but sometimes it is something stupid. I'll poke around for another hour or so.

Ttyl, John

On Tue, Aug 18, 2020 at 11:36 PM mitch7391 notifications@github.com wrote:

I have just done this now John, this is where I put the new line in my script (hopefully in the right spot):

[image: image] https://user-images.githubusercontent.com/40288237/90589142-fcaffc00-e20f-11ea-851b-ab144dfeb385.png

And the value written to this file was true. Hope this helps?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-675832347, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX3RRYZWR3WR24LDMITSBNCDJANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Hey John, sorry for the delay in responses, I have just transitioned into night shifts and will have less time on this for the next few days. But will try give the two things you have suggested a go before/after shift. Also it is worth noting that I tried to follow the method for CheckYourScript.sh and I was not able to run it; I wonder if your method needs to be updated since all the recent upgrades in the Homebridge image and changes in Config UI-X?

I am still finding it curious that the commands for mosquitto_pub and in particular the parsing of mosquitto_sub through jq works as raw commands in my terminal but does not work once it is in a shell script.

(Works from terminal): _mosquitto_sub --cafile /home/pi/hisense.crt --tls-version tlsv1.2 --insecure -T -v -h 192.168.0.156 -p 36669 -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.issignal'

Well, actually mosquitto_pub does still work in the shell script as that has been proven by using bash -x HisenseSwitch.sh Set anything On False and it will turn my TV off referencing the command through the shell script. I think the issue lies in either my lack of knowledge of the basics of writing shell scripts and coding (using the correct syntax or whatever), or the fact that shell script itself has an issue with how the returned output from mosquitto_sub is piped into jq for parsing or how jq receives the piped response of mosquitto_sub as an input for parsing. The reason I am thinking this is that I can run the exact same command in my terminal separate of cmd4 or the created shell script and it works perfectly.

The moment I put it in the shell script and call bash -x HisenseSwitch.sh Get anything On it gets stuck and does not provide an output. The use of -x in my bash command is showing me it doesn't get past the point in my shell script of jq .is_signal; making me think that it is not parsing anything; which I know that outside of using a shell script this very same command does parse the value and outputs a 1 or 0 like I want. I hope my thought process here makes sense.

ztalbot2000 commented 4 years ago

Yes it makes sense. I'd still try coding the absolute path to jq in your script as an easy try.

TTFN, John

On Wed, Aug 19, 2020 at 11:27 AM mitch7391 notifications@github.com wrote:

Hey John, sorry for the delay in responses, I have just transitioned into night shifts and will have less time on this for the next few days. But will try give the two things you have suggested a go before/after shift. Also it is worth noting that I tried to follow the method for CheckYourScript.sh and I was not able to run it; I wonder if your method needs to be updated since all the recent upgrades in the Homebridge image and changes in Config UI-X?

I am still finding it curious that the commands for mosquitto_pub and in particular the parsing of mosquitto_sub through jq works as raw commands in my terminal but does not work once it is in a shell script.

(Works from terminal):

mosquitto_sub --cafile /home/pi/hisense.crt --tls-version tlsv1.2 --insecure -T -v -h 192.168.0.156 -p 36669 -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.is_signal'

Well, actually mosquitto_pub does still work in the shell script as that has been proven by using bash -x HisenseSwitch.sh Set anything On False and it will turn my TV off referencing the command through the shell script. I think the issue lies in either my lack of knowledge of the basics of writing shell scripts and coding (using the correct syntax or whatever), or the fact that shell script itself has an issue with how the returned output from mosquitto_sub is piped into jq for parsing or how jq receives the piped response of mosquitto_sub as an input for parsing. The reason I am thinking this is that I can run the exact same command in my terminal separate of cmd4 or the created shell script and it works perfectly.

The moment I put it in the shell script and call bash -x HisenseSwitch.sh Get anything On it gets stuck and does not provide an output. The use of -x in my bash command is showing me it doesn't get past the point in my shell script of jq .is_signal; making me think that it is not parsing anything; which I know that outside of using a shell script this very same command does parse the value and outputs a 1 or 0 like I want. I hope my thought process here makes sense.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-676495683, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCXZKLZAFR2REHBPY4QTSBPVNNANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Hey John, I do not mind the night shifts so much; it is the swapping in and out of them that is difficult at times. But yes, definitely beats a hospital bed; so I hope that is not your situation currently and I hope Ontario is doing as well as Western Australia is right now (we have been extremely lucky over here).

The response returned for the command which jq was /usr/bin/jq.

I have added it like you reccomended here in my shell script; I am not sure if I have the syntax right (if it needs any ' ', " ", etc.)

image

I then left the jq command as it was before, but was not sure if I should have used it as /usr/bin/jq | 'is_signal' instead?

image

I then ran my command bash -x HisenseSwitch.sh Get anything On and this is what I got returned:

image

ztalbot2000 commented 4 years ago

Since I can't run everything as I do not have your tv. Can you just tell me the exact output of: mosquitto_sub --cafile /home/pi/hisense.crt --tls-version tlsv1.2 --insecure -T -v -h 192.168.0.156 -p 36669 -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state

Thanks, John

On Fri, Aug 21, 2020 at 6:57 AM John Talbot ztalbot2000@gmail.com wrote:

Thé path to jq is not an issue. I just tried it.

For mosquitto_sub did you install all the certbot stuff? Requiring a certificate and all that? That is what I'm trying to do at the moment.

I'm in the depths of it now ....

Ttyl, John

On Fri, Aug 21, 2020 at 5:49 AM John Talbot ztalbot2000@gmail.com wrote:

Hi Mitch

So much for prefix. Thanks for trying that. We can throw that out the window.

The only thing I do want you to try is the change to your shell script is adding the path to your jq command. I freed up a pi and can try some stuff there now too.

Ttyl, John

On Fri, Aug 21, 2020 at 4:39 AM mitch7391 notifications@github.com wrote:

Also it did not seem to like my adding "state_cmd_suffix": "2>&1 | tee -a /tmp/log" to my config for the switch by the looks.

[8/21/2020, 16:35:31] [Cmd4] getGeneric On function for:My_Switch cmd:bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On' 2>&1 | tee -a /tmp/log failed.

[8/21/2020, 16:35:31] [Cmd4] Error: Command failed: bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On' 2>&1 | tee -a /tmp/log

at ChildProcess.exithandler (child_process.js:303:12)

at ChildProcess.emit (events.js:315:20)

at maybeClose (internal/child_process.js:1021:16)

at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

{

killed: true,

code: null,

signal: 'SIGTERM',

cmd: "bash /home/pi/HisenseSwitch.sh Get 'My_Switch' 'On' 2>&1 | tee -a /tmp/log"

}

[8/21/2020, 16:35:31] [Cmd4]

[8/21/2020, 16:35:31] [Cmd4]

It also didn't seem to create the file log in /tmp/log by the looks as well.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678119703, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCXYAR7H5CYXKFHZYMHDSBYXEZANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Hey John, by installing the 'certbot stuff' do you mean the certificate for my TV? I was able to obtain the certificate for my TV by running openssl s_client -host 192.168.0.156 -port 36669 -showcerts; this then provides two arrays of data in the output that you save in one file (mine is hisense.crt) the form of:

-----BEGIN CERTIFICATE----- qmierjfpaoisdjmçfaisldjcçfskdjafcaçskdjcçfmasidcf(...) -----END CERTIFICATE-----

-----BEGIN CERTIFICATE----- 7ferusycedaystraedyasredyatrdsecdtrseydtraESYDTRASCY (...) -----END CERTIFICATE-----

When I run mosquitto_sub --cafile /home/pi/hisense.crt --tls-version tlsv1.2 --insecure -T -v -h 192.168.0.156 -p 36669 -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state in my terminal I get the following output:

{"statetype":"sourceswitch","sourceid":"HDMI1","sourcename":"HDMI1","is_signal":1,"is_lock":0,"hotel_mode":0,"displayname":"HDMI1"}

I must say thanks for going above and beyond so far, even trying to set it up on a spare Raspberry Pi yourself to test with; I was going to say that you would not be able to run my commands as you wouldn't have the TV's MQTT broker to communicate with. Not sure if you have any fancy methods to 'fake' this connection and use my output just as a text file instead of receiving the actual output from the MQTT broker instead.

mitch7391 commented 4 years ago

Just so it does not look like I am sitting around doing nothing while you fault find for me, I have been trying to google some solutions and learn a bit more as we go. I did come across this which I think was interesting and maybe it is an issue with issuing these commands inside a shell script like I suspected:

https://www.thethingsnetwork.org/forum/t/mosquitto-sub-piping-not-working-with-ttn-v2/4858

https://unix.stackexchange.com/questions/435413/using-jq-within-pipe-chain-produces-no-output

I have tried adding --unbuffered option to the jq command but this also did not work. I have not yet tried the option of sending the output of mosquitto_sub to a temp file and then calling that file from the shell script to pipe into jq. I ran out of time before night shift so did not get to try that yet.

ztalbot2000 commented 4 years ago

i tried assigning the json output you gave me to a variable called result and it worked. so could you try this too. there is still a real issue to figure out, but every step helps. The which was a check and in my case /tmp/out contains the path to mosquitto_sub.

On ) which mosquitto_sub > /tmp/out

result='{"statetype":"sourceswitch","sourceid":"HDMI1","sourcename":"HDMI1","is_signal":1,"is_lock":0,"hotel_mode":0,"displayname":"HDMI1"}';

if [ $(mosquitto_sub --cafile /home/pi/hisense.crt --tls-version

tlsv1.2 --insecure -h $ip -p $port -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.is_signal') = '1' ]; then if [ "$(echo ${result} | /usr/bin/jq '.is_signal')" = "1" ]; then

ttyl, John

On Fri, Aug 21, 2020 at 7:44 AM mitch7391 notifications@github.com wrote:

Just so it does not look like I am sitting around doing nothing while you fault find for me, I have been trying to google some solutions and learn a bit more as we go. I did come across this which I think was interesting and maybe it is an issue with issuing these commands inside a shell script like I suspected:

https://www.thethingsnetwork.org/forum/t/mosquitto-sub-piping-not-working-with-ttn-v2/4858

https://unix.stackexchange.com/questions/435413/using-jq-within-pipe-chain-produces-no-output

I have tried adding --unbuffered option to the jq command but this also did not work. I have not yet tried the option of sending the output of mosquitto_sub to a temp file and then calling that file from the shell script to pipe into jq. I ran out of time before night shift so did not get to try that yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678249094, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5AMECB7V326UYLNADSBZM3LANCNFSM4QDKJ3IA .

ztalbot2000 commented 4 years ago

i never asked how you are starting homebridge. From a service or the command line. my testing was done from the command line using DEBUG=* homebridge -D

The polling for "on" was set to 50, so then I do not need to access it from HomeKit.

i am still trying to get mosquitto_sub set up to my Sony TV.

ttyl, john

On Fri, Aug 21, 2020 at 11:12 AM John Talbot ztalbot2000@gmail.com wrote:

i tried assigning the json output you gave me to a variable called result and it worked. so could you try this too. there is still a real issue to figure out, but every step helps. The which was a check and in my case /tmp/out contains the path to mosquitto_sub.

On ) which mosquitto_sub > /tmp/out

result='{"statetype":"sourceswitch","sourceid":"HDMI1","sourcename":"HDMI1","is_signal":1,"is_lock":0,"hotel_mode":0,"displayname":"HDMI1"}';

if [ $(mosquitto_sub --cafile /home/pi/hisense.crt --tls-version

tlsv1.2 --insecure -h $ip -p $port -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.is_signal') = '1' ]; then if [ "$(echo ${result} | /usr/bin/jq '.is_signal')" = "1" ]; then

ttyl, John

On Fri, Aug 21, 2020 at 7:44 AM mitch7391 notifications@github.com wrote:

Just so it does not look like I am sitting around doing nothing while you fault find for me, I have been trying to google some solutions and learn a bit more as we go. I did come across this which I think was interesting and maybe it is an issue with issuing these commands inside a shell script like I suspected:

https://www.thethingsnetwork.org/forum/t/mosquitto-sub-piping-not-working-with-ttn-v2/4858

https://unix.stackexchange.com/questions/435413/using-jq-within-pipe-chain-produces-no-output

I have tried adding --unbuffered option to the jq command but this also did not work. I have not yet tried the option of sending the output of mosquitto_sub to a temp file and then calling that file from the shell script to pipe into jq. I ran out of time before night shift so did not get to try that yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678249094, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5AMECB7V326UYLNADSBZM3LANCNFSM4QDKJ3IA .

ztalbot2000 commented 4 years ago

that thread is definitely what we are seeing as I think I just proved. i'll see what I can do when I catch that mosquitto

On Fri, Aug 21, 2020 at 11:17 AM John Talbot ztalbot2000@gmail.com wrote:

i never asked how you are starting homebridge. From a service or the command line. my testing was done from the command line using DEBUG=* homebridge -D

The polling for "on" was set to 50, so then I do not need to access it from HomeKit.

i am still trying to get mosquitto_sub set up to my Sony TV.

ttyl, john

On Fri, Aug 21, 2020 at 11:12 AM John Talbot ztalbot2000@gmail.com wrote:

i tried assigning the json output you gave me to a variable called result and it worked. so could you try this too. there is still a real issue to figure out, but every step helps. The which was a check and in my case /tmp/out contains the path to mosquitto_sub.

On ) which mosquitto_sub > /tmp/out

result='{"statetype":"sourceswitch","sourceid":"HDMI1","sourcename":"HDMI1","is_signal":1,"is_lock":0,"hotel_mode":0,"displayname":"HDMI1"}';

if [ $(mosquitto_sub --cafile /home/pi/hisense.crt --tls-version

tlsv1.2 --insecure -h $ip -p $port -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.is_signal') = '1' ]; then if [ "$(echo ${result} | /usr/bin/jq '.is_signal')" = "1" ]; then

ttyl, John

On Fri, Aug 21, 2020 at 7:44 AM mitch7391 notifications@github.com wrote:

Just so it does not look like I am sitting around doing nothing while you fault find for me, I have been trying to google some solutions and learn a bit more as we go. I did come across this which I think was interesting and maybe it is an issue with issuing these commands inside a shell script like I suspected:

https://www.thethingsnetwork.org/forum/t/mosquitto-sub-piping-not-working-with-ttn-v2/4858

https://unix.stackexchange.com/questions/435413/using-jq-within-pipe-chain-produces-no-output

I have tried adding --unbuffered option to the jq command but this also did not work. I have not yet tried the option of sending the output of mosquitto_sub to a temp file and then calling that file from the shell script to pipe into jq. I ran out of time before night shift so did not get to try that yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678249094, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5AMECB7V326UYLNADSBZM3LANCNFSM4QDKJ3IA .

ztalbot2000 commented 4 years ago

there are many ways to fix this it seems. i don't know which way you tried unbuffered. if i caught the mosquitto I could try this. i like sudo apt-get install expect followed by the script change of mosquitto_sub .... | unbuffer -p jq '.is_signal'

thats unbuffer not unbuffered. let me know. i know your working so you can try this later. great thread you found! you are helping too!

ttfn, john

On Fri, Aug 21, 2020 at 11:30 AM John Talbot ztalbot2000@gmail.com wrote:

that thread is definitely what we are seeing as I think I just proved. i'll see what I can do when I catch that mosquitto

On Fri, Aug 21, 2020 at 11:17 AM John Talbot ztalbot2000@gmail.com wrote:

i never asked how you are starting homebridge. From a service or the command line. my testing was done from the command line using DEBUG=* homebridge -D

The polling for "on" was set to 50, so then I do not need to access it from HomeKit.

i am still trying to get mosquitto_sub set up to my Sony TV.

ttyl, john

On Fri, Aug 21, 2020 at 11:12 AM John Talbot ztalbot2000@gmail.com wrote:

i tried assigning the json output you gave me to a variable called result and it worked. so could you try this too. there is still a real issue to figure out, but every step helps. The which was a check and in my case /tmp/out contains the path to mosquitto_sub.

On ) which mosquitto_sub > /tmp/out

result='{"statetype":"sourceswitch","sourceid":"HDMI1","sourcename":"HDMI1","is_signal":1,"is_lock":0,"hotel_mode":0,"displayname":"HDMI1"}';

if [ $(mosquitto_sub --cafile /home/pi/hisense.crt --tls-version

tlsv1.2 --insecure -h $ip -p $port -P multimqttservice -u hisenseservice -t /remoteapp/mobile/broadcast/ui_service/state | jq '.is_signal') = '1' ]; then if [ "$(echo ${result} | /usr/bin/jq '.is_signal')" = "1" ]; then

ttyl, John

On Fri, Aug 21, 2020 at 7:44 AM mitch7391 notifications@github.com wrote:

Just so it does not look like I am sitting around doing nothing while you fault find for me, I have been trying to google some solutions and learn a bit more as we go. I did come across this which I think was interesting and maybe it is an issue with issuing these commands inside a shell script like I suspected:

https://www.thethingsnetwork.org/forum/t/mosquitto-sub-piping-not-working-with-ttn-v2/4858

https://unix.stackexchange.com/questions/435413/using-jq-within-pipe-chain-produces-no-output

I have tried adding --unbuffered option to the jq command but this also did not work. I have not yet tried the option of sending the output of mosquitto_sub to a temp file and then calling that file from the shell script to pipe into jq. I ran out of time before night shift so did not get to try that yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678249094, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5AMECB7V326UYLNADSBZM3LANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

i never asked how you are starting homebridge. From a service or the command line.

I am starting my homebridge through Oznu's hb-service in config-ui-x, I haven't been calling Homebridge to start each time if that is what you mean through. So, I have actually been doing my testing without it in debug mode; as I have too many accessories on Homebridge and it is very hard to debug one plug-in when it is in debug mode. Unless there is a way in config-ui-x to turn on debug mode for only one plug-in?

But like I said at this stage I have been mostly running it only through bash -x commands that call the shell script and trying to debug it that way. I have only tested it through Homekit and as a cmd4 switch when you have asked me to test certain things. Otherwise I have been only testing at the terminal level through bash; as if it does not work there, it will definitely not work in cmd4.

i don't know which way you tried unbuffered.

I had only tried the additional option from the jq manual to add --unbuffered after the command. I was eyeing off the solution you just mentioned with installing expect, but I ran out of time before work. So if you think that looks like a viable solution I will definitely give it a go after work :) well, considering it is last night shift before my break, maybe a few hours sleep after work and then I will take a look haha.

ztalbot2000 commented 4 years ago

I too am going to bed. I was unable to get mosquitto_sub to talk to my Sony. I know the psk, but psk-identity? I always used curl. Speaking of curl. Does this work for you?

curl -d http://192.168.0.156:8060/keypress/Power http://192.168.0.166:8060/keypress/Power

I had noticed someone with a Roku TV doing it. Just curious.

John

On Fri, Aug 21, 2020 at 1:17 PM mitch7391 notifications@github.com wrote:

i never asked how you are starting homebridge. From a service or the command line.

I am starting my homebridge through Oznu's hb-service in config-ui-x, I haven't been calling Homebridge to start each time if that is what you mean through. So, I have actually been doing my testing without it in debug mode; as I have too many accessories on Homebridge and it is very hard to debug one plug-in when it is in debug mode. Unless there is a way in config-ui-x to turn on debug mode for only one plug-in?

But like I said at this stage I have been mostly running it only through bash -x commands that call the shell script and trying to debug it that way. I have only tested it through Homekit and as a cmd4 switch when you have asked me to test certain things. Otherwise I have been only testing at the terminal level through bash; as if it does not work there, it will definitely not work in cmd4.

i don't know which way you tried unbuffered.

I had only tried the additional option from the jq manual to add --unbuffered after the command. I was eyeing off the solution you just mentioned with installing expect, but I ran out of time before work. So if you think that looks like a viable solution I will definitely give it a go after work :) well, considering it is last night shift before my break, maybe a few hours sleep after work and then I will take a look haha.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678399104, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5LLCLDH4AXRH6B6MDSB2TZ3ANCNFSM4QDKJ3IA .

ztalbot2000 commented 4 years ago

I believe I reproduced it. mosquitto_sub never quits. it seems to wait for more data. I'll see how to fix this.

ttfn, john

On Fri, Aug 21, 2020 at 4:17 PM John Talbot ztalbot2000@gmail.com wrote:

I too am going to bed. I was unable to get mosquitto_sub to talk to my Sony. I know the psk, but psk-identity? I always used curl. Speaking of curl. Does this work for you?

curl -d http://192.168.0.156:8060/keypress/Power http://192.168.0.166:8060/keypress/Power

I had noticed someone with a Roku TV doing it. Just curious.

John

On Fri, Aug 21, 2020 at 1:17 PM mitch7391 notifications@github.com wrote:

i never asked how you are starting homebridge. From a service or the command line.

I am starting my homebridge through Oznu's hb-service in config-ui-x, I haven't been calling Homebridge to start each time if that is what you mean through. So, I have actually been doing my testing without it in debug mode; as I have too many accessories on Homebridge and it is very hard to debug one plug-in when it is in debug mode. Unless there is a way in config-ui-x to turn on debug mode for only one plug-in?

But like I said at this stage I have been mostly running it only through bash -x commands that call the shell script and trying to debug it that way. I have only tested it through Homekit and as a cmd4 switch when you have asked me to test certain things. Otherwise I have been only testing at the terminal level through bash; as if it does not work there, it will definitely not work in cmd4.

i don't know which way you tried unbuffered.

I had only tried the additional option from the jq manual to add --unbuffered after the command. I was eyeing off the solution you just mentioned with installing expect, but I ran out of time before work. So if you think that looks like a viable solution I will definitely give it a go after work :) well, considering it is last night shift before my break, maybe a few hours sleep after work and then I will take a look haha.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678399104, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5LLCLDH4AXRH6B6MDSB2TZ3ANCNFSM4QDKJ3IA .

ztalbot2000 commented 4 years ago

The problem is neither with jq being unbuffered or mosquitto_sub being unbuffered either. mosquitto_sub. I found how to test mosquitto in https://stackoverflow.com/questions/26716279/how-to-test-the-mosquitto-server

So the fix was to use the -W option of mosquitto_sub to wait on your TV to respond and otherwise exit. For my testing I modifiéd your script for Get using a topic sample in the above thread. I then used mosquitto_pub to send the data you said you expect to receive. Low and behold it works !

I can send you my script if you'd like, but I think you can understand what is happening. It my not be a perfect solution though. If your TV does not respond, jq gets no data and my script failed.

Best of luck. Let me know how this solution works.

TTFN, John

On Fri, Aug 21, 2020 at 7:28 PM John Talbot ztalbot2000@gmail.com wrote:

I believe I reproduced it. mosquitto_sub never quits. it seems to wait for more data. I'll see how to fix this.

ttfn, john

On Fri, Aug 21, 2020 at 4:17 PM John Talbot ztalbot2000@gmail.com wrote:

I too am going to bed. I was unable to get mosquitto_sub to talk to my Sony. I know the psk, but psk-identity? I always used curl. Speaking of curl. Does this work for you?

curl -d http://192.168.0.156:8060/keypress/Power http://192.168.0.166:8060/keypress/Power

I had noticed someone with a Roku TV doing it. Just curious.

John

On Fri, Aug 21, 2020 at 1:17 PM mitch7391 notifications@github.com wrote:

i never asked how you are starting homebridge. From a service or the command line.

I am starting my homebridge through Oznu's hb-service in config-ui-x, I haven't been calling Homebridge to start each time if that is what you mean through. So, I have actually been doing my testing without it in debug mode; as I have too many accessories on Homebridge and it is very hard to debug one plug-in when it is in debug mode. Unless there is a way in config-ui-x to turn on debug mode for only one plug-in?

But like I said at this stage I have been mostly running it only through bash -x commands that call the shell script and trying to debug it that way. I have only tested it through Homekit and as a cmd4 switch when you have asked me to test certain things. Otherwise I have been only testing at the terminal level through bash; as if it does not work there, it will definitely not work in cmd4.

i don't know which way you tried unbuffered.

I had only tried the additional option from the jq manual to add --unbuffered after the command. I was eyeing off the solution you just mentioned with installing expect, but I ran out of time before work. So if you think that looks like a viable solution I will definitely give it a go after work :) well, considering it is last night shift before my break, maybe a few hours sleep after work and then I will take a look haha.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678399104, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5LLCLDH4AXRH6B6MDSB2TZ3ANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Hey John, sorry for the late reply! Pretty much wasted my first day off coming out of the night shift (don’t seem to bounce back from them like I did 5 years ago haha)...

The -W option with a 1s setting to my command worked amazingly. You might laugh but early on in the piece I was using the -k as I was thinking maybe it wasn’t keeping it alive long enough for it to be parsed in the shell script; turns out it was the other way around! So my understanding of what I would see it do in my terminal when I issued the command was that it would execute the output but would hold the subscription until a change of output was received.

I’m guessing shell doesn’t like that and it needs to see the mosquitto_sub command finish before it pipes to jq and the addition of -W makes it do exactly that after the allotted time. Am I correct in that assumption?

My simple switch now works, time to start fiddling around and making a more complicated TV accessory. I will keep you updated on my progress for interests sake and so if anyone else has a similar project in future they can see what I have done :)

ztalbot2000 commented 4 years ago

Hi Mitch,

I'm really glad it worked for you.. The -W is still odd in that the data is probably already outputted so we waste time before quitting and jq to take over. I can see why piping to a file would save those precious seconds. There is still the possibility of you trying curl as well. Either way you are now much farther off.

I did shifts for the first 7 years of my career. Kind of like putting in your dues. It does have its benefits, at times.

My Sony TV is a 55" 850D. I like it because it has google play built into it and I downloaded Khodi as an App and it really runs fast! Speaking of fast. I have an 8G Pi with 64Bit Raspbian booting straight from SSD. It is faster than my 5 year old Mac mini!

Oh well, Enjoy Cmd4. Do let me know how you make out. TTFN, John

On Sat, Aug 22, 2020 at 11:25 PM mitch7391 notifications@github.com wrote:

Hey John, sorry for the late reply! Pretty much wasted my first day off coming out of the night shift (don’t seem to bounce back from them like I did 5 years ago haha)...

The -W option with a 1s setting to my command worked amazingly. You might laugh but early on in the piece I was using the -k as I was thinking maybe it wasn’t keeping it alive long enough for it to be parsed in the shell script; turns out it was the other way around! So my understanding of what I would see it do in my terminal when I issued the command was that it would excite the output but would hold the subscription until a change of output was received.

I’m guessing shell doesn’t like that and it needs to see the mosquitto_sub command finish before it pipes to jq and the addition of -W makes it do exactly that after the allotted time. Am I correct in that assumption?

My simple switch now works, time to start fiddling around and making a more complicated TV accessory. I will keep you updated on my progress for interests sake and so if anyone else has a similar project in future they can see what I have done :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678724166, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX2DVOYFSAGAFR74R5LSCCD27ANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Yeah I was thinking to myself that because -W cannot be less than a second (I tried), it will slow the response down a little; oh well for the time being! Also I think I did try curl and that did not work as I do not believe it supports MQTT?

I know what you mean about the night shifts haha at least the money is worth it whilst I can do it!

Quick question for you John, I see you reference wakeonlan in the README file, but it looks like a copy and paste of the config from hoembridge-cmdswitch2; does cmd4 support wakeonlan at all? I just gave it a go and had no luck. I only ask as it could be a method for me to use to turn on the TV once it is off, as the TV turns off its MQTT Broker when it powers off and you cannot turn it back on again without the remote (no longer has a connection to the host). It looks like people in the Home Assistant forums have only been able to achieve this through WOL.

ztalbot2000 commented 4 years ago

Hmm, I don't remember writing about WOL. I will have a look.

Ttyl

On Sun, Aug 23, 2020 at 5:02 AM mitch7391 notifications@github.com wrote:

Yeah I was thinking to myself that because -W cannot be less than a second (I tried), it will slow the response down a little; oh well for the time being! Also I think I did try curl and that did not work as I do not believe it supports MQTT?

I know what you mean about the night shifts haha at least the money is worth it whilst I can do it!

Quick question for you John, I see you reference wakeonlan in the README file, but it looks like a copy and paste of the config from hoembridge-cmdswitch2; does cmd4 support wakeonlan at all? I just gave it a go and had no luck. I only ask as it could be a method for me to use to turn on the TV once it is off, as the TV turns off its MQTT Broker when it powers off and you cannot turn it back on again without the remote (no longer has a connection to the host). It looks like people in the Home Assistant forums have only been able to achieve this through WOL.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678748835, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX6GKKJENE6H6B7PWL3SCDLL3ANCNFSM4QDKJ3IA .

ztalbot2000 commented 4 years ago

So the wakeonlan was a cut and paste to show how cmdswitch2 did things. The next section shows how cmd4 does things. The Correlation is not so much equivalent. What I can do is create a script that does exactly what cmd4 expects for WOL and put that in Extras where PS4.sh is. This is a pretty good idea. A cmd4 ping.sh would also be nice. ,I'll get back to you on that.

TTFN, John

On Sun, Aug 23, 2020 at 5:31 AM John Talbot ztalbot2000@gmail.com wrote:

Hmm, I don't remember writing about WOL. I will have a look.

Ttyl

On Sun, Aug 23, 2020 at 5:02 AM mitch7391 notifications@github.com wrote:

Yeah I was thinking to myself that because -W cannot be less than a second (I tried), it will slow the response down a little; oh well for the time being! Also I think I did try curl and that did not work as I do not believe it supports MQTT?

I know what you mean about the night shifts haha at least the money is worth it whilst I can do it!

Quick question for you John, I see you reference wakeonlan in the README file, but it looks like a copy and paste of the config from hoembridge-cmdswitch2; does cmd4 support wakeonlan at all? I just gave it a go and had no luck. I only ask as it could be a method for me to use to turn on the TV once it is off, as the TV turns off its MQTT Broker when it powers off and you cannot turn it back on again without the remote (no longer has a connection to the host). It looks like people in the Home Assistant forums have only been able to achieve this through WOL.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678748835, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX6GKKJENE6H6B7PWL3SCDLL3ANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

I figured that might be the case, I think a long while back I assumed your plug-in took off from cmdswitch2 and therefore maybe included the wakeonlan command. Apparently my TV's app uses 'wake on lan magic packet' to turn the TV on and everything else is done via MQTT. No rush on the work as I am happy to make-do for the time being, but I am happy to hear it would be something that would benefit a lot of people :) thanks again John!

ztalbot2000 commented 4 years ago

Hi Mitch,

I submitted to GitHub some example scripts, including a wakeonlan. I have yet to publish to npm.

TTFN, John

On Sun, Aug 23, 2020 at 9:25 AM mitch7391 notifications@github.com wrote:

I figured that might be the case, I think a long while back I assumed your plug-in took off from cmdswitch2 and therefore maybe included the wakeonlan command. Apparently my TV's app uses 'wake on lan magic packet' to turn the TV on and everything else is done via MQTT. No rush on the work as I am happy to make-do for the time being, but I am happy to hear it would be something that would benefit a lot of people :) thanks again John!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678774312, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5QSA64GQ5W3YAUYZTSCEKERANCNFSM4QDKJ3IA .

ztalbot2000 commented 4 years ago

I hate when links don't work. They are hard to test when they are not there yet. I will fix ....

On Sun, Aug 23, 2020 at 8:36 PM John Talbot ztalbot2000@gmail.com wrote:

Hi Mitch,

I submitted to GitHub some example scripts, including a wakeonlan. I have yet to publish to npm.

TTFN, John

On Sun, Aug 23, 2020 at 9:25 AM mitch7391 notifications@github.com wrote:

I figured that might be the case, I think a long while back I assumed your plug-in took off from cmdswitch2 and therefore maybe included the wakeonlan command. Apparently my TV's app uses 'wake on lan magic packet' to turn the TV on and everything else is done via MQTT. No rush on the work as I am happy to make-do for the time being, but I am happy to hear it would be something that would benefit a lot of people :) thanks again John!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678774312, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5QSA64GQ5W3YAUYZTSCEKERANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Oh nice work John, that was really quick :) I can see them there in the extras folder and will have a read over, looks there is a fair bit there!

ztalbot2000 commented 4 years ago

Fixed the links. .. enough for tonight

On Sun, Aug 23, 2020 at 9:39 PM mitch7391 notifications@github.com wrote:

Oh nice work John, that was really quick :) I can see them there in the extras folder and will have a read over, looks there is a fair bit there!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678861009, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX7KCMXPKL52EHI6RUDSCHAEDANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Cheers John, enjoy your night!

mitch7391 commented 4 years ago

Hey John I have given it a little bit of a go turning it from a simple switch to the TV accessory and am a little bit confused by some of the parameters. I started with the simpler 'Television' type config and then started adding stuff from the 'TV_Combo' example you had there. So far I have the following in my config.json:

{ "type": "Television", "displayName": "My_TV", "active": "ACTIVE", "activeIdentifier": 1, "configuredName": "My_TV", "sleepDiscoveryMode": "ALWAYS_DISCOVERABLE", "linkedTypes": [ { "type": "InputSource", "displayName": "TV", "configuredName": "TV", "currentVisibilityState": "SHOWN", "inputSourceType": "TV", "isConfigured": "CONFIGURED", "identifier": 1, "name": "TV" }, { "type": "InputSource", "displayName": "HDMI1", "configuredName": "HDMI1", "currentVisibilityState": "SHOWN", "inputSourceType": "HDMI", "isConfigured": "CONFIGURED", "identifier": 2, "name": "HDMI1" } ], "polling": [ { "active": "ACTIVE", "interval": 50, "timeout": 4000 }, { "activeIdentifier": 1, "interval": 50, "timeout": 4000 } ], "stateChangeResponseTime": 1, "state_cmd": "bash /home/pi/HisenseTV.sh" },

I have read both the config samples (also the one with the red descriptions) but am still confused about a few parameters; isConfigured and currentVisibilityState mainly.

I think I have it mostly working but a little glitchy. I notice it doesn't like my Get Active when the TV is off (which means mosquitto_sub returns no value), when it was a switch accessory it was fine with recognizing no value as off, but doing the same for the TV accessory does not seem to work; I will have to think of a way around this.

Here is my new shell script for the TV accessory so far: https://pastebin.com/URBW3QHe

ztalbot2000 commented 4 years ago

Mitch. I have closed this as resolved. If you do need more help, just reply to this thread. Take care, John Talbot

mitch7391 commented 4 years ago

No worries, I have a fully working switch at this stage, but still some issues with the TV accessory that I am doing a bit of ‘trial and error’ testing on; but have had to park this for a few days myself so far.

I was wondering if you might be able to explain these parameters and how they should function or be used? isConfigured and currentVisibilityState.

I tired to google them and referenced your advice on a previous issue to read the descriptions in HAP-NodeJS; but that still did not clear it up for me.

ztalbot2000 commented 4 years ago

Hi Mitch,

I got your message and will look at it a bit later. I'd have to look up what those parks mean.

TTFN, John

Sent from Zarf’s iPad Air 2

On Aug 24, 2020, at 4:10 AM, mitch7391 notifications@github.com wrote:

 Hey John I have given it a little bit of a go turning it from a simple switch to the TV accessory and am a little bit confused by some of the parameters. I started with the simpler 'Television' type config and then started adding stuff from the 'TV_Combo' example you had there. So far I have the following in my config.json:

{ "type": "Television", "displayName": "My_TV", "active": "ACTIVE", "activeIdentifier": 1, "configuredName": "My_TV", "sleepDiscoveryMode": "ALWAYS_DISCOVERABLE", "linkedTypes": [ { "type": "InputSource", "displayName": "TV", "configuredName": "TV", "currentVisibilityState": "SHOWN", "inputSourceType": "TV", "isConfigured": "CONFIGURED", "identifier": 1, "name": "TV" }, { "type": "InputSource", "displayName": "HDMI1", "configuredName": "HDMI1", "currentVisibilityState": "SHOWN", "inputSourceType": "HDMI", "isConfigured": "CONFIGURED", "identifier": 2, "name": "HDMI1" } ], "polling": [ { "active": "ACTIVE", "interval": 50, "timeout": 4000 }, { "activeIdentifier": 1, "interval": 50, "timeout": 4000 } ], "stateChangeResponseTime": 1, "state_cmd": "bash /home/pi/HisenseTV.sh" },

I have read both the config samples (also the one with the red descriptions) but am still confused about a few parameters; isConfigured and currentVisibilityState mainly.

I think I have it mostly working but a little glitchy. I notice it doesn't like my Get Active when the TV is off (which means mosquitto_sub returns no value), when it was a switch accessory it was fine with recognizing no value as off, but doing the same for the TV accessory does not seem to work; I will have to think of a way around this.

Here is my new shell script for the TV accessory so far: https://pastebin.com/URBW3QHe

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

ztalbot2000 commented 4 years ago

hi Mitch,

There are so many parameters it's unbelievable. I could not find anything in the documented Hap spec for CurrentVisibilityState. What little documentation I have is duplicated in State.js from /usr/local/lib/node_modules/hap-nodejs/lib/gen/HomeKitTypes-Television.js and that it is either shown or Hidden.i think it refers to like an HDMI input isConfigured as there is something attached to it and currentVisibilityState meaning a specific HDMI port is being used, i.e. to a DVD player on HDMI1 is what the TV is showing, compared to HDMI2 that is set up to an XBox that is not being viewed at this time.

Your script i'll look at tomorrow.

night, john

On Fri, Aug 28, 2020 at 8:34 PM John Talbot ztalbot2000@gmail.com wrote:

Hi Mitch,

I got your message and will look at it a bit later. I'd have to look up what those parks mean.

TTFN, John

Sent from Zarf’s iPad Air 2

On Aug 24, 2020, at 4:10 AM, mitch7391 notifications@github.com wrote:



Hey John I have given it a little bit of a go turning it from a simple switch to the TV accessory and am a little bit confused by some of the parameters. I started with the simpler 'Television' type config and then started adding stuff from the 'TV_Combo' example you had there. So far I have the following in my config.json:

{ "type": "Television", "displayName": "My_TV", "active": "ACTIVE", "activeIdentifier": 1, "configuredName": "My_TV", "sleepDiscoveryMode": "ALWAYS_DISCOVERABLE", "linkedTypes": [ { "type": "InputSource", "displayName": "TV", "configuredName": "TV", "currentVisibilityState": "SHOWN", "inputSourceType": "TV", "isConfigured": "CONFIGURED", "identifier": 1, "name": "TV" }, { "type": "InputSource", "displayName": "HDMI1", "configuredName": "HDMI1", "currentVisibilityState": "SHOWN", "inputSourceType": "HDMI", "isConfigured": "CONFIGURED", "identifier": 2, "name": "HDMI1" } ], "polling": [ { "active": "ACTIVE", "interval": 50, "timeout": 4000 }, { "activeIdentifier": 1, "interval": 50, "timeout": 4000 } ], "stateChangeResponseTime": 1, "state_cmd": "bash /home/pi/HisenseTV.sh" },

I have read both the config samples (also the one with the red descriptions) but am still confused about a few parameters; isConfigured and currentVisibilityState mainly.

I think I have it mostly working but a little glitchy. I notice it doesn't like my Get Active when the TV is off (which means mosquitto_sub returns no value), when it was a switch accessory it was fine with recognizing no value as off, but doing the same for the TV accessory does not seem to work; I will have to think of a way around this.

Here is my new shell script for the TV accessory so far: https://pastebin.com/URBW3QHe

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/65#issuecomment-678977254, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX2CFVVCFP3VVIGSKVDSCIN5VANCNFSM4QDKJ3IA .

mitch7391 commented 4 years ago

Now that I think about it, looking at the State.js is what you had suggested in the closed entry I had found; for some stupid reason I took that as looking for the characteristics in the github for HAP-NodeJS... Now that I look over State.js, I can see it is essentially giving me the same information I found there. The characteristics have a very brief description that I would more so call a 'title' than description; like you said it only gives so much information and leaves you guessing still.

Your description just then is the assumption I have made over the last few days (so makes me a little more confident) in my guess work. Which means I can take a look at my mosquitto_sub outputs to see if I can find something to use that suits.

The biggest issue I have at the moment is that I cannot the TV accessory will not turn on when I try to issue the command from Homekit, it does work when I use bash -x HisenseTV.sh Set anything Active true from my terminal; meaning the command works but something with the accessory is wrong. If I turn the TV on with the remote, it displays feedback that it is on, my two 'inputs' and lets me change between them fine, and even turn the TV off all from Homekit. I have changed my method for determining the active state; but I had also changed this for my Switch accessory too and the Switch turns off and on the TV from Homekit with no issue. Here is the new method for determining if the TV is on or off (probably a little rough as I stole it from HA forums and tried to get it to work in my shell script, but it works!):

image

This above method means I know longer get errors when the TV is off (and the MQTT Broker is no longer contactable). My TV config is in the above comments and my new shell script I started used not long after my post 5 days ago.

https://pastebin.com/xHxMWZJ1

mitch7391 commented 4 years ago

There is no rush on helping John, just whenever you have free time or feel like looking over it. As I said, I have been a bit flat out myself and have not had too much time to look into it any further myself :) I have a working switch at the very least to turn the TV on and off or to get the active state for the time being (meaning when I climb into bed and realise I have left the TV on, I now don't have to get back up lol).

ztalbot2000 commented 4 years ago

I got a great smile knowing you can turn your TV on/off from bed 😀 That alone is gratitude enough

When I created CMD4 I was worried about Apple saying I copied their documentation. The State.js file is as close you are going to get to the real thing, without it being a direct copy. It took a long time to do. Your first issue got me back to looking at CMD4 in a while. I had stashed some code that I finally submitted with 2.4.0 and that was splitting the app into code/data for better testing purposes. So I do appreciate you getting me off my butt in that regard. I'm just starting breakfast. I can peek at your scripts afterwards. I'd still like to get mosquitto to respond immediately through redirection instead of the -W. That could be causing issues with multiple commands talking to the mosquitto server. You should run Homebridge in debug mode so that when you use your IOS device to ask your TV to do something, CMD4 prints to the console the exact command sent and any response it gets back. It's the only way to test from the GUI level.

TTFN, John

On Sat, Aug 29, 2020 at 8:03 AM mitch7391 notifications@github.com wrote:

There is no rush on helping John, just whenever you have free time or feel like looking over it. As I said, I have been a bit flat out myself and have not had too much time to look into it any further myself :) I have a working switch at the very least to turn the TV on and off or to get the active state for the time being (meaning when I climb into bed and realise I have left the TV on, I now don't have to get back up lol).

— You are receiving this because you modified the open/close state.

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

ztalbot2000 commented 4 years ago

Hi Mitch, I'm just getting started. you are farther than I getting my TV going ;-). So I'm not sure how all this stuff works together myself. I just added linked types a while ago for the purpose of doing what you are actually doing. I got side tracked with life. from your config.json file, I think only one Input source can be shown at a time. so while the TV on the first InputSource is configured and you are watching it, the second input source which you have labelled as HDMI1 is also configured, it is not shown at this time. your TV can only show one Input source at a time. I think that is the way it should go. as for your other question, try starting homebridge in debug mode as previously mentioned.

ttyl, John

mitch7391 commented 4 years ago

Glad I could give you a laugh John haha also glad to hear I have spurred you back into working on this plug-in; makes me not feel as bad for taking so much of your time!

Moving away from using the -W will be on my fine tuning list once I have the basics done; as I will be losing precious response time with this current method.

Nice feedback to hear about my progression so far, hopefully by the end we can have an awesome TV accessory each haha. I get what you are saying about the inputs, I just need to think of a way to get it to work as that almost sounds like ActiveIdentifier and CurrentVisibilityState are almost the same thing. I have been working some very long shifts with very little sleep lately, so my brain just is not working well lately to focus on this; I might have to wait a few more days before I give this a further go haha even focusing on what I wanted to reply to you about was a struggle...

ztalbot2000 commented 4 years ago

Your right. They do sound the same. Maybe you do have it correct. ActiveIdentifier is more like what I described. I'll try to work on this later. Maybe I can get my TV going too :-) I have too many things on the go. I was trying to get a replacement for 1Password that syncs across all my devices and does not cost a monthly fee.

You should maybe email me directly at ztalbot2000@gmail.com so our conversations don't get dispersed everywhere.

TTFN, John

On Sun, Aug 30, 2020 at 8:57 AM mitch7391 notifications@github.com wrote:

Glad I could give you a laugh John haha also glad to hear I have spurred you back into working on this plug-in; makes me not feel as bad for taking so much of your time!

Moving away from using the -W will be on my fine tuning list once I have the basics done; as I will be losing precious response time with this current method.

Nice feedback to hear about my progression so far, hopefully by the end we can have an awesome TV accessory each haha. I get what you are saying about the inputs, I just need to think of a way to get it to work as that almost sounds like ActiveIdentifier and CurrentVisibilityState are almost the same thing. I have been working some very long shifts with very little sleep lately, so my brain just is not working well lately to focus on this; I might have to wait a few more days before I give this a further go haha even focusing on what I wanted to reply to you about was a struggle...

— You are receiving this because you modified the open/close state.

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

mitch7391 commented 4 years ago

Fair point John, we have been getting off topic on occasion. I will switch over to emailing you privately and then once we have some successes I will post those in here for future people to use :)