Closed Scream4Life closed 7 years ago
Unfortunately I do not know SecvestIP at all. Do I understand you correctly, is the problem that the device is sending back the string "Mode=
Right. The string Mode= is to much and I'm not sure weather the Secvests "set" and "unset" is a useful phrase for showing the current state. Some kind of translation is needed.
Well, I guess you will have to modify the source a little bit to get those strings translated. In index.js there is a getState() method. Line 113 is this:
var state = parseInt(responseBody);
This is the line that reads the response and transforms it to a code HomeKit understands. Which is not much of a translation, it just parses it as a number. You will have to change this part of the script. Instead of parsing the body as an integer, you will have to check if it looks anything like 'Mode=something' and based on the 'something' part you will have to set the state to the corresponding number (0 to 5).
If you need help with this code just let me know and I'll write it up for you quick.
Thanks for your offer. Indeed any help would be appreciated, since I'm not very familiar with coding. The messages from the alarmsystem are
Mode=Set or Mode=Unset
Again, thank you for your help.
So, here is a piece of code you should try: On line 113 of index.js you currently find this:
var state = parseInt(responseBody);
Replace this line with the following lines:
var mapping = {
'Mode=Set': 1,
'Mode=Unset': 3
};
var state = responseBody in mapping ? mapping[responseBody] : parseInt(responseBody);
This will translate Mode=Set to value of 1, Mode=Unset to value of 3. You may want to extend the mapping with more values if you figure out what your security device returns when it has been alarmed, or when it is in different away modes (it has 3 distinct one, see the main page of this project for the values).
Thank you so far. It seems that EVE shows the status correctly, when I start my scene to activate or deactivate the alarm (not sure if that was before the same). Home app does not, I guess because it can only show these on off situations and not your 4 states, right? I'm not able to launch the homebridge with the ReadCurrentState, ReadTargetState properties. Maybe this should do the trick. When launching it I get the same error as in another (solved) issue is documented, on which you recommended to use the read property instead of readCurrent/TargetState.
[7/28/2016, 5:08:20 PM] Loading x accessories...
[7/28/2016, 5:08:20 PM] [Home security] Initializing Http-SecuritySystem accessory...
/usr/local/lib/node_modules/homebridge-http-securitysystem/index.js:32
url: config.urls.read.url,
^
TypeError: Cannot read property 'url' of undefined
at Object.HttpSecuritySystemAccessory (/usr/local/lib/node_modules/homebridge-http-securitysystem/index.js:32:25)
at Server._loadAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:244:29)
at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:72:38)
at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)
at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
Another weird thing is that when I set the alarm in the SecvestApp, and request the status in EVE, the homebridge shows State is currently NaN
Can you give me the error as you get it? The one you pasted in is from the issue we solved last year. Back then the property was still 'read' but it has been changed to 'readTargetState' and 'readCurrentState' since. Posting your current config would also help. Don't forget to remove the pass ;)
This is my error when using the readCurrent/TargetStates. `[2017-6-11 11:53:53] [Alarmanlage] Initializing Http-SecuritySystem accessory... /usr/local/lib/node_modules/homebridge-http-securitysystem/index.js:32 url: config.urls.read.url, ^
TypeError: Cannot read property 'url' of undefined
at Object.HttpSecuritySystemAccessory (/usr/local/lib/node_modules/homebridge-http-securitysystem/index.js:32:25)
at Server._loadAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:265:29)
at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:81:38)
at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)
at Object.
and this is my config
{ "accessory": "Http-SecuritySystem", "name": "Alarmanlage", "auth": { "username": "abc", "password": "abc", "immediately": true }, "http_method": "GET", "urls": { "stay": { "url": "http://ip:port/setMode.cgi?Mode=Set&Source=Webpage", "body": "Anwesend" }, "away": { "url": "http://ip:port/setMode.cgi?Mode=Set&Source=Webpage", "body": "Abwesend" }, "night": { "url": "http://ip:port/setMode.cgi?Mode=Set&Source=Webpage", "body": "Nacht" }, "disarm": { "url": "http://ip:portsetMode.cgi?Mode=Unset&Source=Webpage", "body": "Aus"}, "readCurrentState": { "url": "http://ip:port/getMode.cgi?Source=Webpage", "body": "" }, "readTargetState": { "url": "http://ip:port/getMode.cgi?Source=Webpage", "body": "" } } },
When I use read instead of readCurrent/TargeState homebridge starts correctly but posts [2017-6-11 12:02:25] [Alarmanlage] Getting target state [2017-6-11 12:02:25] [Alarmanlage] Getting current state [2017-6-11 12:02:25] [Alarmanlage] State is currently NaN [2017-6-11 12:02:25] [Alarmanlage] State is currently NaN
from time to time
Hm to me it looks like you are not running the latest version of homebridge-http-securitysystem. The latest version does not rely on "read" any more. Can you try updating it?
Just tried sudo npm uninstall -g homebridge-http-securitysystem and sudo npm install -g homebridge-http-securitysystem as well as sudo npm update -g homebridge-http-securitysystem...did your "var state" tweek above...nothing changed
Well, I managed the update of the index.js now by hand and the readCurrent/TargetState configurations work as well in my config. It seems that the home app still doesn't show up the correct state and I still got these messages from homebridge
[2017-6-11 13:24:16] [Alarmanlage] Getting target state [2017-6-11 13:24:16] [Alarmanlage] Getting current state [2017-6-11 13:24:16] [Alarmanlage] State is currently NaN [2017-6-11 13:24:16] [Alarmanlage] State is currently NaN
This is my config
{
"accessory": "Http-SecuritySystem",
"name": "Alarmanlage",
"username": "abc",
"password": "abc",
"immediately": true,
"http_method": "GET",
"urls": {
"stay": { "url": "http://ip:port/setMode.cgi?Mode=Set&Source=Webpage", "body": "" },
"away": { "url": "http://ip:port/setMode.cgi?Mode=Set&Source=Webpage", "body": "" },
"night": { "url": "http://ip:port/setMode.cgi?Mode=Set&Source=Webpage", "body": "" },
"disarm": { "url": "http://ip:port/setMode.cgi?Mode=Unset&Source=Webpage", "body": ""},
"readCurrentState": { "url": "ip:port/getMode.cgi?Source=Webpage", "body": "" },
"readTargetState": { "url": "ip:port/getMode.cgi?Source=Webpage", "body": "" }
}
},
And here is your getState function from the index.js
getState: function(url, body, callback) {
if (!url) {
callback(null);
}
this.httpRequest(url, body, function(error, response, responseBody) {
if (error) {
this.log('GetState function failed: %s', error.message);
callback(error);
} else {
var mapping = {
'Mode=Set': 2,
'Mode=Unset': 3,
'Mode=Alarm': 4
};
var state = responseBody in mapping ? mapping[responseBody] : parseInt(responseBody);
this.log("State is currently %s", state);
callback(null, state);
}
}.bind(this));
},
Any idea?
I'll have to check up on why npm didn't update it to latest when you told it so. Anyways, I'll need some more debug output to tell what's wrong. Can you please put the following line into index.js, just before the line with "var mapping..." (so that it's still in the same else clause but before the definition of the mapping):
this.log("getState response was [%s]", responseBody);
Then ask for the state and tell me what your logs say.
This is the result
[2017-6-11 17:46:58] [Alarmanlage] Getting target state [2017-6-11 17:46:58] [Alarmanlage] Getting current state [2017-6-11 17:46:58] [Alarmanlage] getState response was [Mode=Unset ] [2017-6-11 17:46:58] [Alarmanlage] State is currently NaN [2017-6-11 17:46:58] [Alarmanlage] getState response was [Mode=Unset ] [2017-6-11 17:46:58] [Alarmanlage] State is currently NaN
Maybe this gives a more detailed view on what's coming from the alarm system
Ah there is a new line char after Mode=Unset! Try trimming the response body when getting the translation from the map: At the same spot where you previously added that log line, add this: responseBody = responseBody.trim();
I think this will remove the newline from the response.
Awesome...that one did the trick! Thank you very much helping me with my dumb Alarm. Wish you all the best with your work here.
For your information, I added a feature that allows you to map responses to the HomeKit states using the config.js. Check out the develop branch for it, it will allow you to do this mapping without you having to change the plugin itself (just use the static mapper).
That is a great update. But how do I handle the trim function of the response body in the config?
That is a great update. But how do I handle the trim function of the response body in the config?
Solved it by putting \n behind my Mode=Set / Mode=Unset strings.
Hi, my SecvestIP works almost perfectly with this plugin with these settings:
...but I have problems reading or to be more precise translating the current status. The SecvestIP delivers as result of the URL call above "Mode=Unset". Is there somehow a way to translate the result to the plugin, so that the real status is shown to homekit?