Closed rykermorgan closed 5 years ago
Based on the Killed: true, it looks like the timeout is too short. You are essentially only allowing 1 second for your script to run. Give it a try and let me know how it works out.
Target position is not polled. Try adding a timeout for it as well. or set the default timeout. I have been working with this area lately and will give this a go myself. I cannot get back to you until tomorrow. I did just push out 2.1 though this morning.
ttfn, John Talbot
hi,
investigating further. The state_cmd: "python ~/.homebridge ... The Tilda character is expanded by the shell. Usually it is not expanded from scripts. This should be just .homebridge/.... You define statusFault:10. if you look at State.js, you will see that this should be 0 or 1. you did not send me back_door_state.py so I replaced it with node ... State.js and using your config.json file, everything worked. my index.js is the new 2.1 I pushed this morning though.
I hope all this helps
Closed for previous solution.
hi,
I just found a major bug in the 2.0 release. I just pushed 2.1.1. Please let me know if it resolves your issues.
@ztalbot2000 I updated to the latest release 2.1.1
I think I've got it working now. The biggest thing I wanted was notifications for when doors are opening and closing so I could also put automation around it (instead of the status only updating when I open the home app and trigger the script while it's "updating".
I still encounter an issue whenever I try to add parameters to "polling". If I just set it to "polling": true
then I don't run into any issues.
Also, whenever I add statusActive
to any config, I get an Active Status in homekit that reports back as "No". And Eve Elegato throws me a warning saying the device is inactive and to consult the user manual for the device. Whenever I remove that param, it fixes that problem, but I don't understand enough to know how that might affect polling.
below is my config.json for two Contact Sensors (I switched it over from a Door sensor):
{
"platform": "Cmd4",
"name": "Cmd4",
"accessories":
[
{
"type": "ContactSensor",
"name": "front_door",
"contactSensorState": 1,
"statusFault": 0,
"statusTampered": 0,
"polling": true,
"fakegato":{"eve":"door",
"status": "contactSensorState",
"storage": "fs",
"storagePath": ".homebridge/FakegatoStorage"
},
"stateChangeResponseTime": 3,
"state_cmd": "python .homebridge/Cmd4Scripts/front_door_state.py"
},
{
"type": "ContactSensor",
"name": "back_door",
"contactSensorState": 0,
"statusFault": 0,
"statusTampered": 0,
"polling": true,
"fakegato":{"eve":"door",
"status": "contactSensorState",
"storage": "fs",
"storagePath": ".homebridge/FakegatoStorage"
},
"stateChangeResponseTime": 3,
"state_cmd": "python .homebridge/Cmd4Scripts/back_door_state.py"
}
]
}
In your example config, it looks like Open is equal to 0 and Closed is equal to 1. Whenever I implemented the script this way I was getting the opposite of reality. So I switched to Open = 1 and Closed = 0, and it seems to be working fine. I'm not sure if that affects the Fakegato history negatively with the way I have it set up.
Here is my script for back_door_state.py (front_door_state.py is the same just checking a different device id):
#!/home/pi/berryconda3/bin/python
import sys
from august.api import Api
from august.authenticator import (
Authenticator, AuthenticationState, ValidationResult)
import requests
user_name = '<YOUR PHONE #>'
password = '<YOUR PASSWORD>'
use_session = True
combine_status = True
api = Api(timeout=20)
authenticator = Authenticator(api, "phone", user_name, password,
access_token_cache_file=".august.conf")
authentication = authenticator.authenticate()
locks = api.get_operable_locks(authentication.access_token)
front_lock_status = api.get_lock_status(authentication.access_token,'BF4F854D9E9B4786A9FA3A8833AAE09A')
front_door_status = api.get_lock_door_status(authentication.access_token,'BF4F854D9E9B4786A9FA3A8833AAE09A')
back_lock_status = api.get_lock_status(authentication.access_token,'41C161F1D5DB4C30948CE8184C8438F1')
back_door_status = api.get_lock_door_status(authentication.access_token,'41C161F1D5DB4C30948CE8184C8438F1')
open = "LockDoorStatus.OPEN"
closed = "LockDoorStatus.CLOSED"
def backDoorState():
if str(back_door_status) == open:
print(1)
elif str(back_door_status) == closed:
print(0)
backDoorState()
# def frontDoorState():
# if str(front_door_status) == open:
# print(0)
# elif str(front_door_status) == closed:
# print(1)
#
# frontDoorState()
I've also want Fakegato to log history data, which is seems to be doing (see sample below), but it doesn't populate the history into Eve Elegato—the Eve app just shows "No Data".
{
"firstEntry": 0,
"lastEntry": 718,
"usedMemory": 718,
"refTime": 579072658,
"initialTime": 1557379858,
"history": [
"noValue",
{
"time": 1557379858,
"setRefTime": 1
},
{
"time": 1557379858,
"status": 0
},
{
"time": 1557379862,
"status": 0
},
{
"time": 1557379865,
"status": 0
},
{
"time": 1557379869,
"status": 0
},
{
"time": 1557379891,
"status": 0
},
{
"time": 1557379895,
"status": 0
}
]
}
Thanks for all the info. I have been really looking into making cmd4 better and will seriously look further into your problem.
TTFN, John
On Thu, May 9, 2019 at 12:27 PM rykermorgan notifications@github.com wrote:
@ztalbot2000 https://github.com/ztalbot2000 I updated to the latest release 2.1.1
I think I've got it working now. The biggest thing I wanted was notifications for when doors are opening and closing so I could also put automation around it (instead of the status only updating when I open the home app and trigger the script while it's "updating".
I still encounter an issue whenever I try to add parameters to "polling". If I just set it to "polling": true then I don't run into any issues.
Also, whenever I add statusActive to any config, I get an Active Status in homekit that reports back as "No". And Eve Elegato throws me a warning saying the device is inactive and to consult the user manual for the device. Whenever I remove that param, it fixes that problem, but I don't understand enough to know how that might affect polling.
below is my config.json for two Contact Sensors (I switched it over from a Door sensor):
{ "platform": "Cmd4", "name": "Cmd4", "accessories": [ { "type": "ContactSensor", "name": "front_door", "contactSensorState": 1, "statusFault": 0, "statusTampered": 0, "polling": true, "fakegato":{"eve":"door", "status": "contactSensorState", "storage": "fs", "storagePath": ".homebridge/FakegatoStorage" }, "stateChangeResponseTime": 3, "state_cmd": "python .homebridge/Cmd4Scripts/front_door_state.py" }, { "type": "ContactSensor", "name": "back_door", "contactSensorState": 0, "statusFault": 0, "statusTampered": 0, "polling": true, "fakegato":{"eve":"door", "status": "contactSensorState", "storage": "fs", "storagePath": ".homebridge/FakegatoStorage" }, "stateChangeResponseTime": 3, "state_cmd": "python .homebridge/Cmd4Scripts/back_door_state.py" } ] }
In your example config, it looks like Open is equal to 0 and Closed is equal to 1. Whenever I implemented the script this way I was getting the opposite of reality. So I switched to Open = 1 and Closed = 0, and it seems to be working fine. I'm not sure if that affects the Fakegato history negatively with the way I have it set up.
Here is my script for back_door_state.py (front_door_state.py is the same just checking a different device id):
!/home/pi/berryconda3/bin/python
import sys from august.api import Api from august.authenticator import (
Authenticator, AuthenticationState, ValidationResult)
import requests
user_name = '<YOUR PHONE #>'
password = '
' use_session = True
combine_status = True
api = Api(timeout=20)
authenticator = Authenticator(api, "phone", user_name, password,
access_token_cache_file=".august.conf")
authentication = authenticator.authenticate()
locks = api.get_operable_locks(authentication.access_token)
front_lock_status = api.get_lock_status(authentication.access_token,'BF4F854D9E9B4786A9FA3A8833AAE09A')
front_door_status = api.get_lock_door_status(authentication.access_token,'BF4F854D9E9B4786A9FA3A8833AAE09A')
back_lock_status = api.get_lock_status(authentication.access_token,'41C161F1D5DB4C30948CE8184C8438F1')
back_door_status = api.get_lock_door_status(authentication.access_token,'41C161F1D5DB4C30948CE8184C8438F1')
open = "LockDoorStatus.OPEN"
closed = "LockDoorStatus.CLOSED"
def backDoorState():
if str(back_door_status) == open: print(1) elif str(back_door_status) == closed: print(0)
backDoorState()
def frontDoorState():
if str(front_door_status) == open:
print(0)
elif str(front_door_status) == closed:
print(1)
#
frontDoorState()
I've also want Fakegato to log history data, which is seems to be doing (see sample below), but it doesn't populate the history into Eve Elegato—the Eve app just shows "No Data".
{
"firstEntry": 0,
"lastEntry": 718,
"usedMemory": 718,
"refTime": 579072658,
"initialTime": 1557379858,
"history": [
"noValue", { "time": 1557379858, "setRefTime": 1 }, { "time": 1557379858, "status": 0 }, { "time": 1557379862, "status": 0 }, { "time": 1557379865, "status": 0 }, { "time": 1557379869, "status": 0 }, { "time": 1557379891, "status": 0 }, { "time": 1557379895, "status": 0 }
]
}
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/23#issuecomment-490974143, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSBCX3CCOBLHEP7H3IYNDLPURGIXANCNFSM4HLKSF5A .
@ztalbot2000 the work you've done so far is amazing! It gives me much more flexibility to create Homekit accessories by leveraging APIs for items that don't have Homekit support or a dedicated HomeBridge plugin. But I also love that I can create "devices" with a script 👍 so keep up the good work.
Hi,
Thanks for sending the scripts and the comments.
I have a couple of concerns. The first I raised before was there is no exit status of your script. What this means is that while your script prints out the values, The process still does not know if it existed successfully. Add this line to the end of your python script or wherever you expect it to complete. exit(0)
This is not the big problem though. Scripting is tricky, especially when you run it from the command line and it works, but put it in a cron or have it run by another process. The big gotcha is that when you run a script from the command line it has access to all your environmental variables. From cron or another process it does not.
There are two ways this is being called. 1) from your command line as .homebridge/Cmd4Scripts/front_door_state.py
These are two separate locations for python. One is in your path and the other is in /home/pi/berryconda3/bin A cron or another process would not see the one in /home/pi/berryconda/bin because you called it with python which is whatever is in the default path.
The easy fix may be just to remove the FIRST word 'python' from the state_cmd. Since your script has the #! at the top and if it is executable, then all would be okay. If that does not work, try running bash from the command line so it only gets the default PATH and environmental variables. bash --no_profile --norc Then try and run the state_cmd as you have it in your config.json file. By getting the PATH and environmental variables out of the way, you may see other problems. You do still need a proper exit code though, no matter what.
Let me know how you make out, John Talbot
On Fri, May 10, 2019 at 1:50 PM rykermorgan notifications@github.com wrote:
@ztalbot2000 https://github.com/ztalbot2000 the work you've done so far is amazing! It gives me much more flexibility to create Homekit accessories by leveraging APIs for items that don't have Homekit support or a dedicated HomeBridge plugin. But I also love that I can create "devices" with a script 👍 so keep up the good work.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/23#issuecomment-491375805, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSBCX3YH65ZXWS47O5CCBTPUWYXZANCNFSM4HLKSF5A .
I just submitted 2.1.2. I added 2700+ unit tests that bullet proof any typos that could arise. The code also shrinks significantly. Let me know if you are still having problems. I have not heard back from you.
ttfn, John Talbot
On Sat, May 11, 2019 at 11:57 AM John Talbot ztalbot2000@gmail.com wrote:
Hi,
Thanks for sending the scripts and the comments.
I have a couple of concerns. The first I raised before was there is no exit status of your script. What this means is that while your script prints out the values, The process still does not know if it existed successfully. Add this line to the end of your python script or wherever you expect it to complete. exit(0)
This is not the big problem though. Scripting is tricky, especially when you run it from the command line and it works, but put it in a cron or have it run by another process. The big gotcha is that when you run a script from the command line it has access to all your environmental variables. From cron or another process it does not.
There are two ways this is being called. 1) from your command line as .homebridge/Cmd4Scripts/front_door_state.py
- from the first line in the file python is run from /home/pi/berryconda3/bin/python 2) python .homebridge/Cmd4Scripts/front_door_state.py
These are two separate locations for python. One is in your path and the other is in /home/pi/berryconda3/bin A cron or another process would not see the one in /home/pi/berryconda/bin because you called it with python which is whatever is in the default path.
The easy fix may be just to remove the FIRST word 'python' from the state_cmd. Since your script has the #! at the top and if it is executable, then all would be okay. If that does not work, try running bash from the command line so it only gets the default PATH and environmental variables. bash --no_profile --norc Then try and run the state_cmd as you have it in your config.json file. By getting the PATH and environmental variables out of the way, you may see other problems. You do still need a proper exit code though, no matter what.
Let me know how you make out, John Talbot
On Fri, May 10, 2019 at 1:50 PM rykermorgan notifications@github.com wrote:
@ztalbot2000 https://github.com/ztalbot2000 the work you've done so far is amazing! It gives me much more flexibility to create Homekit accessories by leveraging APIs for items that don't have Homekit support or a dedicated HomeBridge plugin. But I also love that I can create "devices" with a script 👍 so keep up the good work.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/23#issuecomment-491375805, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSBCX3YH65ZXWS47O5CCBTPUWYXZANCNFSM4HLKSF5A .
I’ll have to grab the update a little later today.
I added the exit(0) to the end of my python scripts, but it doesn’t seem like it really changed much. It actually seems like it broke polling. It didn’t give me any errors, but the notifications I was getting when doors opened and closed were suddenly very very delayed. I’ll have to play with that a little bit more.
Otherwise, the commands are running fine. I haven’t tried adding specific
characteristics/parameters back to polling. Whenever I did before,
everything broke. Right now I just have polling set to true
.
The fakegato history for the door contact sensors still doesn’t show up. There is plenty of data in the files, but Eve shows nothing. It has a loading bar, but shows “No data” once done. Maybe I’m not passing the right data into it so it doesn’t know how to read it? I’ve got history working for a humidity sensor, but not the contact sensors. If you are able to derive as to why the contact sensors might not be working based on the scripts and config.json I posted already, that’d be cool, but it’s not really a deal breaker for me.
I get a "No Response" error in the Home app whenever I add polling to my config.json for either a door or a motinon sensor.
I've implemented polling on a Door as it is outlined in the Cmd4 Extras config.json:
It works just fine without polling. But whenever I add polling it breaks.
Here's the homebridge log for when I add polling...seems like the script fails to execute whenever I add polling, but this same error isn't present when I remove polling: