ztalbot2000 / homebridge-cmd4

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

[Bug] Switch no longer respecting state_cmd #99

Closed machineglow closed 3 years ago

machineglow commented 3 years ago

Hi,

I have a switch controlled by state_cmd that no longer working after various updates. I upgraded homebridge and cmd4 over the last few weeks hoping this would get fixed but it's still not working. I must be doing something wrong. Strange thing is, it was working great before hand and I haven't changed/modified the state_cmd script.

I have a simple switch that's controlled by a state_cmd script that queries something (airplay state) and spits back 1 or 0 depending on whether something is airplaying.

It was working for a while but a recent update/change broke it somehow. The script still spits out 1 or 0 but the switch in the home app seems to be set independently and doesn't respect the state_cmd script output. I have a feeling there was a change to the json or the way the script was called and I'm just not aware of it.

Here's the config.json:

            "platform": "Cmd4",
            "name": "Cmd4",
            "allowTLV8": false,
            "outputConstants": false,
            "restartRecover": true,
            "fetch": "Cached",
            "accessories": [
                {
                    "type": "Switch",
                    "displayName": "Playroom AirPlaying",
                    "on": "FALSE",
                    "name": "Playroom AirPlaying",
                    "Manufacturer": "Apple Inc.",
                    "Model": "AirPort10,115",
                    "SerialNumber": "C86NQKFFFFFF",
                    "polling": true,
                    "interval": 10,
                    "timeout": 10000,
                    "state_cmd_prefix": "bash",
                    "state_cmd": "/var/homebridge/Cmd4Scripts/AirplayState.sh"
                },

Here's the script:

#!/bin/bash
# Get & Set both return the current AirPlay status, as AirPlay cannot be turned on or off by script
if [[ "$1" = "Get" ]] || [[ "$1" = "Set" ]]; then
echo $(dig -p 5353 -t ptr _airplay._tcp.local @192.168.X.XXX 2>&1 | grep -oP 'flags=0x.*?\b' | sed 's/flags=0xc04/1/' | sed 's/flags=0x404/0/')
exit 0
fi
exit -1

Here's the script in action when I stop airplay.:

$ ./AirplayState.sh Get
1
$ ./AirplayState.sh Get
1
$ ./AirplayState.sh Get
1
$ ./AirplayState.sh Get
0
$ ./AirplayState.sh Get
0
$ ./AirplayState.sh Get
0
$ ./AirplayState.sh Get
0

Environment:

Thanks!!

ztalbot2000 commented 3 years ago

Hi,

If fetch is set to cached, no script is called. Polled is probably what you want.

TTFN, John

On Mon, Mar 1, 2021 at 8:31 PM machineglow notifications@github.com wrote:

Assigned #99 https://github.com/ztalbot2000/homebridge-cmd4/issues/99 to @ztalbot2000 https://github.com/ztalbot2000.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/99#event-4393061785, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX64LWS7CA373ZOKODDTBQ5VJANCNFSM4YNXMQLQ .

ztalbot2000 commented 3 years ago

Fetch:Always - for every characteristic get from device. Fetch:Cached- For every characteristic get from cache. Fetch:Polled- Get from cache all characteristics, except those that are polled.

On Mon, Mar 1, 2021 at 8:33 PM John Talbot ztalbot2000@gmail.com wrote:

Hi,

If fetch is set to cached, no script is called. Polled is probably what you want.

TTFN, John

On Mon, Mar 1, 2021 at 8:31 PM machineglow notifications@github.com wrote:

Assigned #99 https://github.com/ztalbot2000/homebridge-cmd4/issues/99 to @ztalbot2000 https://github.com/ztalbot2000.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/99#event-4393061785, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX64LWS7CA373ZOKODDTBQ5VJANCNFSM4YNXMQLQ .

machineglow commented 3 years ago

Thanks!. That seemed to have worked. Not sure how it worked before. if fetch cached is basically like fetch always except for polled characteristics, haven't I explicitly defined my switch as polled?

edit: nm, i think i understand it now... Not sure how it was working before but oh well.. =/

ztalbot2000 commented 3 years ago

Hi, I'll close this as it's working again. The three rules I listed above hold true. Believe me, I struggled a lot with this too. Your statement,"if fetch cached is basically like fetch always except for polled characteristics" I might have thought so at one time, but it is problematic for a very specific case of Current/Target characteristics. A set of a Target characteristic has to return immediately the Current value. If so it would be the wrong Cached characteristic value. Hence the three rules of:

Fetch:Always - for every characteristic get from device. Fetch:Cached- For every characteristic get from cache. Fetch:Polled- Get from cache all characteristics, except those that are polled.

Question, not really related. Are you using Homebridge-Config-UI-X? They are not showing my CHANGELOG and other documentation properly. Clicking inline links closes the window. I put a bug report in with them. I was just wondering as you had said you were waiting for things to resolve.

I'll close this now as resolved but we can still chat.

ttfn, John