statusPattern question
Closed this issue · 1 comments
Describe the bug
This is probably more of a documentation question than a bug, but I have an enhancement request as well. I'm having no luck with setting the statusPattern
. Maybe there could be an additional example in the documentation. I'm hoping that I have everything in the right place etc. and I just don't have the query right.
Expected behavior
Given the following body response for a statusUrl
{
"id": "aaaa-8888-444-a99-58sdfsd",
"children": [],
"users": [
{
"id": "f6b-02-46-b8-941e28b"
}
],
"devices": [
{
"id": "a-d0-4-a5-444",
"macAddress": "90e"
}
],
"userRoles": [
{
"userId": "fc4-0032-46-b-94ff8b",
"roles": [
"owner"
]
}
],
"subscription": {
"id": "b5-6d-42-a8-2a1",
"isActive": true,
"status": "unknown",
"providerInfo": {}
},
"address": "",
"city": "",
"state": "a",
"country": "us",
"postalCode": "94",
"timezone": "US/Pacific",
"gallonsPerDayGoal": 0,
"occupants": 0000,
"stories": 1,
"isProfileComplete": true,
"hasPastWaterDamage": true,
"showerBathCount": 200,
"toiletCount": 200,
"nickname": "9 Way",
"irrigationSchedule": {
"isEnabled": true
},
"systemMode": {
"target": "away"
},
"locationType": "sfh",
"residenceType": "primary",
"waterSource": "utility",
"locationSize": "lte_2000_sq_ft",
"waterShutoffKnown": "unsure",
"plumbingType": "copper",
"indoorAmenities": [
"clotheswasher",
"dishwasher",
"icemaker_ref",
"bathtub"
],
"outdoorAmenities": [
"fountain"
],
"plumbingAppliances": [
"re_pump",
"tankless"
],
"waterUtility": " Utilities",
"notifications": {
"pending": {
"infoCount": 0,
"warningCount": 0,
"criticalCount": 0,
"alarmCount": [],
"info": {
"count": 0,
"devices": {
"count": 0,
"absolute": 0
}
},
"warning": {
"count": 0,
"devices": {
"count": 0,
"absolute": 0
}
},
"critical": {
"count": 0,
"devices": {
"count": 0,
"absolute": 0
}
}
}
},
"areas": {
"default": [
{
"id": "2e-01-49-81-2d8ca",
"name": "Attic"
},
{
"id": "3bd2b6",
"name": "Basement"
},
{
"id": "8c56ba0",
"name": "Garage"
},
{
"id": "2087ea80d27",
"name": "Main Floor"
},
{
"id": "cf79690",
"name": "Upstairs"
}
],
"custom": []
},
"class": {
"key": "unit",
"level": 0
},
"account": {
"id": "bc6b2375-6cfd-422d-a528-234b2aa24ca1"
}
}
I need like something like the following, If "target":"home"
or "target":"sleep"
then switch is ON. I imagine that should look like:
"statusPattern": "{/.*\"target\".*\"(home|sleep)\".*/}"
To Reproduce
Steps to reproduce the behavior:
Version (output of npm list -g homebridge homebridge-http-switch
)
- homebridge: 1.1.1
- homebridge-http-switch: v0.5.30
Configuration
{
"bridge": {
"name": "Homebridge Synology",
"username" : "*****",
"port": *****
"pin" : "*****"
},
"accessories": [
{
"accessory": "PowerlossIFTTTNotifier",
"name": "PowerlossIFTTTNotifier",
"IFTTTkey : "*****",
"IFTTTservice: "*****",
"IFTTTvalue2": "Homebridge started at",
"IFTTTvalue3": false
},
{
"accessory": "Synology",
"name": "Pigpen",
"ip" : "*****",
"mac" : "*****",
"port": "5001",
"secure": true,
"account" : "*****",
"password" : "*****",
"version": 6,
"timeout": *****
"disabled": [
""
],
"doPolling": true,
"pollingInterval": 120
},
{
"accessory": "neurio",
"name": "neurio",
"location" : "*****",
"username" : "*****",
"password" : "*****",
"options": {
"ttl": 30,
"verboseP": false
}
},
{
"name": "Garage Door",
"username" : "*****",
"password" : "*****",
"accessory": "Chamberlain"
},
{
"accessory": "HTTP-SWITCH",
"name": "Flo",
"switchType": "stateful",
"pullInterval": 5000,
"debug": true,
"statusPattern": "true",
"onUrl" : "*****",
"url" : "https://...",
"method": "POST",
"headers": {
"authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCfWTVU",
"Content-Type": "application/json"
},
"body": {
"target": "home"
}
},
"offUrl": {
"url" : "https://...",
"method": "POST",
"headers": {
"authorization": "TVU",
"Content-Type": "application/json"
},
"body": {
"target": "away"
}
},
"statusUrl": {
"url" : "https://...",
"method": "GET",
"headers": {
"authorization": "eyJhbGciOiJIUzI1NiIsVU",
"Content-Type": "application/json"
},
"statusPattern": "{/.*\"target\".*\"home\".*/}"
}
},
{
"accessory": "HTTP-SWITCH",
"name": "pigpen temp warning",
"switchType": "stateless",
"timeout": 1000,
"onUrl" : "*****",
"method": "POST",
"debug": false
},
{
"accessory": "HTTP-SWITCH",
"name": "Arming error",
"switchType": "stateless",
"timeout": 1000,
"onUrl" : "*****",
"method": "POST",
"debug": false
},
{
"accessory": "DummySwitch",
"name": "iPad charged",
"stateful": true
},
{
"accessory": "DummySwitch",
"name": "iPhone charged",
"stateful": true
},
{
"accessory": "AutomationCalendar",
"name": "AutomationCalendar",
"latitude" : ***,
"longitude" : ***,
},
{
"accessory": "Schedule",
"name": "Hourly",
"cron": "*/90 0-8,21-23 * * *"
}
],
"platforms": [
{
"name": "Config",
"port": 8581,
"auth": "form",
"theme": "navi-blue",
"tempUnits": "f",
"lang": "auto",
"sessionTimeout": *****
"log": {
"method": "null"
},
"accessoryControl": {
"debug": true
},
"platform": "config"
},
{
"platform": "Nest",
"name": "Nest",
"access_token" : "****",
"fanDurationMinutes": 15
},
{
"platform": "TuyaWebPlatform",
"name": "Smart Life",
"options": {
"username" : "*****",
"password" : "*****",
"countryCode": "1",
"platform": "smart_life",
"pollingInterval": 120
}
},
{
"platform": "WeatherPlus",
"units": "us",
"interval": 5,
"stations": [
{
"nameNow": "Current",
"service": "openweathermap",
"key": "******",
"locationGeo": [
*****
-121.96
],
"locationCity" : "*****",
"language": "en",
"compatibility": "both",
"forecast": [
0
],
"conditionCategory": "detailed",
"now": true,
"extraHumidity": false,
"hidden": [
"Air Pressure",
"Observation Station",
"Observation Time",
"Snow"
],
"tresholdCloudCover": 30,
"tresholdUvIndex": 4,
"tresholdWindSpeed": 10
}
]
}
]
My questions:
- Is the regex matching only if the entire response matches?
- is the regex matching matching if the string occurs anywhere in the response?
Additional context
So I might be getting ahead of myself because I obviously don't follow how the regex is working here, but it would be amazing if stead of regex the plugin supported query the nodes. in this case, .node .systemMode
would return exactly the right value to test rather than a RegEx.
So it looks like I found the problem. statusPattern
should not be inside the statusUrl
as I had it.
I will leave this open as I think the documentation could be improved. Also, for consideration of the request to support parssing by keynames instead of regex