Replacing SiteSensor Plugin (Vera) with MSR
-
cw-kidreplied to toggledbits on Mar 25, 2021, 2:30 PM last edited by cw-kid Mar 25, 2021, 10:42 AM
In the "Request Headers" field in the "Set Reaction" I have tried the following:
Accept: application/json
and tried:
Content-Type: application/json
It allows me to save the rule but when I go back in to the rule that field is empty again and its not collecting the response data in to my empty expression / variable.
-
So there are two separate issues here:
-
First, we need to figure out if the UI is correctly storing the headers or not, and if the problem is merely that it is not restoring/displaying them correctly when you go back into the editor. The check for that is to go into the reaction, add the headers, and save. Then, open the rule status view and it will show you the rule ID underneath the rule condition status and expressions. Go to your
reactor/storage/rules
directory, and grab the same-named file (with.json
suffix) and post it here. Let's see what's being stored. -
Look at the logs to see where the reaction is running and what the request is doing. There may be errors logged.
It's entirely possible that the problem is 1, 2, or even both.
-
-
I cannot upload files to this forum it seems.
I have uploaded the rule to my One Drive here
-
OK. There's definitely two broken things in the handling of headers, so go ahead and open a PR for this. No need to post the rule there (again); I've got it and have the issue in hand, but unfortunately, it's not just a UI issue.
-
-
OK so lets say I now have a variable in MSR that contains some data pulled down from a HTTP Request to some online API somewhere.
How can I send that value / information to a Generic IO Sensor in Vera ?
I know how to create a GenericIO device in Vera and I know how to send data to it from a simple HTTP command, for example this command will send the text "Hello World"
http://Vera-IP/port_3480/data_request?id=lu_variableset&DeviceNum=128&serviceId=urn:micasaverde-com:serviceId:GenericSensor1&Variable=CurrentLevel&Value=Hello World
And here is the device in Vera:
But how to create a rule to send the contents of an MSR variable (expression) ?
-
I'm going to assume the data was returned in JSON format? In which case MSR treats that like an object {}, whose keys can be referenced with dot notation.
For example, if your variablerespData
stored the response {animal:"cat", clothing:"suit", food:"chow"} and you want to send the current value of the "chow" key therein, simply reference that value withrespData.chow
.One hurdle you may have to overcome, since the data is being fetched and stored in Rule A, but you want to reference the results in Rule B, is that you'd then have to either (a) store respData as a Global Expression, or (b) create a blank Expression in Rule B, and tell Rule A to [Set Variable] on it.
-
@cw-kid said in Replacing SiteSensor Plugin (Vera) with MSR:
But how to create a rule to send the contents of an MSR variable (expression) ?
In case you revised your question, or I misinterpreted it earlier, here goes:
It sounds like you want to send data from MSR to a plug-in / virtual device / sensor over on Vera. Before you begin, go to that "device" > Advanced > Variables and determine which of its variables is intended to receive the data.
Click "EDIT" next to that variable, and look for its complete "service" name in the window; copy that string for use back in MSR.
Close that window on Vera, then head back over to MSR.
In MSR, you will want an [ENTITY ACTION] in the Set Reaction. Choose the target device as the 'Entity' and choose "x_vera_device.set_variable" as the action.
Fill out the three fields, where "service:" and "variable:" come from the string you copied earlier. For "value:" either type a constant (numeric or "text"), or a variable name properly clad in curly brackets ( e.g. ${{respData}} ) so the value gets substituted next time the Rule triggers.
Hope this helps!!
-
Its working. I now have my current WAN IP address being sent from MSR to a virtual device (Generic IO Sensor) on Vera.
So now know how to send any data stored in an expression / variable from MSR to a device on Vera !
-
-
Try lowercase "uk" the way they show in the API docs, perhaps?
accept: application/json
Response should be in the form:
[ { "country": "UK", "code": "GB", "confirmed": 4319128, "recovered": 3748042, "critical": 683, "deaths": 126445, "latitude": 55.378051, "longitude": -3.435973, "lastChange": "2021-03-25T18:23:06+01:00", "lastUpdate": "2021-03-26T14:15:03+01:00" } ]
-
Not a coder, but have been messing about with Vera's Generic IO Sensor device and managed to create a new instance that can accept multiple variables.
So if these HTTP request headers start working, I should be able to push some Covid stats to this "Generic Sensor" in Vera as a test.
Does something like this kind of device for displaying data already exist somewhere?
-
@cw-kid said in Replacing SiteSensor Plugin (Vera) with MSR:
Does something like this kind of device for displaying data already exist somewhere?
Yes, the SiteSensor plug-in ( also by @toggledbits ) for Vera.
-
@cw-kid said in Replacing SiteSensor Plugin (Vera) with MSR:
My expression in the rule says "null" and no data is being brought down.
If it's any consolation, their site seems to be throwing a 500 error when I try to visit https://covid19-api.com/country?name=uk&format=json in my browser. How about yours?
-
cw-kidreplied to LibraSun on Mar 26, 2021, 2:23 PM last edited by cw-kid Mar 26, 2021, 10:31 AM
@librasun said in Replacing SiteSensor Plugin (Vera) with MSR:
If it's any consolation, their site seems to be throwing a 500 error when I try to visit https://covid19-api.com/country?name=uk&format=json in my browser. How about yours?
Same for me also.
However try their CURL command in a terminal window, that works and brings back data OK
-
cw-kidreplied to LibraSun on Mar 26, 2021, 2:25 PM last edited by cw-kid Mar 26, 2021, 10:29 AM
@librasun said in Replacing SiteSensor Plugin (Vera) with MSR:
Yes, the SiteSensor plug-in ( also by @toggledbits ) for Vera.
But aren't we trying to "replace" that plugin
Some decent Generic IO Sensor virtual device we could create and send data too directly from MSR would be nice.
EDIT: I've just noticed my tweaked GenericIO device does not appear correctly in the Vera mobile app but only on the UI7 web GUI.
-
@cw-kid said in Replacing SiteSensor Plugin (Vera) with MSR:
I've just noticed my tweaked GenericIO device does not appear correctly in the Vera mobile app but only on the UI7 web GUI.
Yes, for this reason we can never truly abandon SiteSensor. Why reinvent the wheel, anyway?
But it does beg the question: Why do you need a generic sensor on your Vera when it could "live" on MSR? After all, is it not just a placeholder for data? -
@librasun said in Replacing SiteSensor Plugin (Vera) with MSR:
Why do you need a generic sensor on your Vera when it could "live" on MSR?
So I can add that device in to the Home Remote dashboard app also.
If it's only on MSR I don't know how to connect Home Remote to MSR directly.
30/91