Closed FezVrasta closed 1 year ago
Hi,
The Get/Set DeviceName and action is sent by Cmd4. Your config.json should read:
{ "type": "Switch", "displayName": "Apple TV Power", "on": false, "polling": true, "state_cmd": "bash /volume1/homebridge/appletv_powerstate.sh" },
If you set "debug":true, then you would see that for an "on" event, Cmd4 would execute your shell command with the following arguments (Already filled in) for a "Get" event
bash /volume1/homebridge/appletv_powerstate.sh Get "Apple TV Power" On
For a "Set" event Cmd4 would execute:
bash /volume1/homebridge/appletv_powerstate.sh Set "Apple TV Power" On 1
// or
bash /volume1/homebridge/appletv_powerstate.sh Set "Apple TV Power" On 0
You do not need a queue. Queue is primarily for devices which can only accept one command at a time, primarily write commands for devices that take a long time to respond. I wrote it for the AdvantageAir.
Boolean characteristic values for "on" should be true/false as per config.json rules, though Cmd4 will translate them for you.
If you want to have more specific polling you would do:
{ "type": "Switch", "displayName": "Apple TV Power", "on": false, "polling": {
"characteristic": "on", "timeout": 3000, "interval": 5
}.
"state_cmd": "bash /volume1/homebridge/appletv_powerstate.sh"
},
where: timeout is in milliseconds interval is in seconds
You should check your script by executing it from the terminal command prompt first
bash /volume1/homebridge/appletv_powerstate.sh Set "Apple TV Power" On 1
bash /volume1/homebridge/appletv_powerstate.sh Set "Apple TV Power" On 0
rc=bash /volume1/homebridge/appletv_powerstate.sh Get "Apple TV Power" On
echo $rc
I hope this helps. Everything I wrote here is standard shell programming. Specifically passing arguments to a shell script.
As a hint to new shell script users, I would suggest setting your device name to 'Apple_TV_Power" as arguments can be tricky with spaces in them.
Take care,
John
On Sat, Dec 10, 2022 at 3:57 AM Federico Zivolo @.***> wrote:
Assigned #134 https://github.com/ztalbot2000/homebridge-cmd4/issues/134 to @ztalbot2000 https://github.com/ztalbot2000.
— Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/134#event-8004112541, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5P5WL4BBHTUKMVV3DWMRAYBANCNFSM6AAAAAAS2EPVMQ . You are receiving this because you were assigned.Message ID: @.***>
Thanks for the answer, but I still don't understand how up set it up as Contact Sensor?
Hi,
Sorry about that. You would change the device type:
{ "type": "ContactSensor", "displayName": "SomeContactSensor", "contactSensorState": "CONTACT_NOT_DETECTED", "polling": {
"characteristic": "contactSensorState", "timeout": 3000, "interval": 5
}.
"state_cmd": "bash /volume1/homebridge/appletv_powerstate.sh"
},
You will find the required and optional characteristics there.
CONTACT_NOT_DETECTED evaluates to zero and CONTACT_DETECTED is 1
Cmd4 will then execute something like:
bash /volume1/homebridge/appletv_powerstate.sh Set "SomeContactSensor" contactSensorState 1
ttyl,
John
On Sat, Dec 10, 2022 at 8:00 AM Federico Zivolo @.***> wrote:
Thanks for the answer, but I still don't understand how up set it up as Contact Sensor?
— Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/134#issuecomment-1345259949, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5YREJLM2RPXJX3GMTWMR5HHANCNFSM6AAAAAAS2EPVMQ . You are receiving this because you were mentioned.Message ID: @.***>
If you are still having issues, just reply to this closed ticket
Describe Your Problem:
I have a switch that I'd like to convert to contact sensor. But I can't figure out how to do it reading the docs. I always get errors about trying to read properties of undefined.
Could you help me please?
[Link to Logs:]()
Paste of Logs:
Cmd4 Config:
Screenshots:
Environment: