Open daniarv opened 6 years ago
You are on the right track, you need a regex mapper and a static mapper.
The regex mapper should regexp out the "secstatus" :
To achieve this, you will need something like this in your mappers section:
"mappers": [
{
"type": "regex",
"parameters": {
"regexp": "\"secstatus\" : (\\d)",
"capture": "1"
}
},
{
"type": "static",
"parameters": {
"mapping": {
"0": "3",
"1": "0",
"2": "1"
}
}
}
]
Give it a try.
Hi,
Thank you some much, now it's working as expected. I also tried to modify the code to read text with spaces and I got it to work by just changing to this:
"regexp": "\"Status\" : \"(.*)\"",
Thank you for a great plugin!
I'm glad it worked out! Just out of curiosity, what sort of security device is returning such a JSON status?
I'm using it together with Domoticz. I also use the homebridge plugin "eDomoticz" but that plugin can't trigger the security device in homekit, only arm/disarm. Then I found your plugin which do exactly what I want :)
I wasn't even aware that you could trigger the alarm from inside homekit. In the "Home" app on my phone I only get stay arm, away arm, night arm and disarm as possible states (but not triggered).
Well, in Domoticz I use a dummy alert sensor. So when i arm my system in Domoticz I also write a value to this alert sensor and the same for disarm, arm home, arm night. But I also write a value to this alert sensor when the alarm is triggered in Domoticz. Your plugin can then read this value and convert it to 4 (triggered) and it will show as Triggered in the home app.
Oh I see! Thanks for sharing :) After your request I am actually considering a proper JSON parser mapper so that you don't have to use a regexp to query a JSON value... there are more elegant solutions to do that.
Hi Codetwice,
How would I parse this json output?
{"Name":"HomeSeer Devices","Version":"1.0","Devices":[{"ref":266,"name":"Areas Secure","location":"RaspberryIO","location2":"TexecomConnect","value":1,"status":"On","device_type_string":"RaspberryIO","last_change":"\/Date(1525265141999)\/","relationship":4,"hide_from_view":false,"associated_devices":[258],"device_type":{"Device_API":4,"Device_API_Description":"Plug-In API","Device_Type":0,"Device_Type_Description":"Plug-In Type 0","Device_SubType":0,"Device_SubType_Description":""},"device_image":"","UserNote":"","UserAccess":"Any","status_image":"/images/HomeSeer/status/on.gif","voice_command":"","misc":4864}]}
Thanks Dan
As I still haven't implemented a JSON parser, you should try it with a regex. Is it the "value":1 part that denotes the status? What other values can there be, which state is which?
Thanks for your fast reply.
This url output just tells Outputs "value":1 when alarm is Armed and "value":0 When alarm is Disarmed. I guess I use these for the readCurrentState and readTargetState urls (Once I get the JSON bit done)
The url to arm and disarm is the same as it runs an event on my HS3 Server.
Hope this make sense :)
Try it with a regexp mapper and a static mapper combined. The regexp mapper will extract the 0 or 1 after "value" and the static mapper will map your 0 to 3 (disarmed) and your 1 to 0 (armed). This mappers block in the config should do the trick:
"mappers": [
{
"type": "regex",
"parameters": {
"regexp": "\"value\"\:(\\d)"
}
},
{
"type": "static",
"parameters": {
"mapping": {
"0": "3",
"1": "0"
}
}
}
]
Hi,
I'm having problem to read out the status from the following JSON output:
{ "secstatus" : 2, "status" : "OK", "title" : "GetSecStatus" }
The "secstatus" can have the following values:
0 = disarmed 1 = armed home 2 = armed away
I have tried with the static mapper and regex in many combinations but it won't get the "secstatus" value. It will only print the full input.
Do you know how to do this?