Replacing SiteSensor Plugin (Vera) with MSR
-
@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.
-
Fair enough (although I'm certain that capacity will come once MSR variables get exposed via the API).
-
toggledbitsreplied to cw-kid on Mar 26, 2021, 3:13 PM last edited by toggledbits Mar 26, 2021, 11:14 AM
@cw-kid said in Replacing SiteSensor Plugin (Vera) with MSR:
no data is being returned / stored
Sheesh. I'll admit I'm a little on edge this morning because we had a major storm roll through last night with some nasty lightning (and a tornado very close to us) and it apparently killed my daily-use laptop (cheap, old, no big loss, just a distraction to recover but they were almost two-for-a-dollar on sleezeBay), so forgive me, but...
There have been no fewer than 10 posts since the above quoted post, and despite my admonition in bold text yesterday in this very thread, not one mention of what may lie in
reactor.log
. -
-
Notice the
[
that starts the displayed value... it's an array. The{
that follows tells you there's an object as the first element of the array. So you need to pluck the first element out of the array, then dereference through it to the key you want, likecovidstats[0].critical
. -
@toggledbits said in Replacing SiteSensor Plugin (Vera) with MSR:
covidstats[0].critical
That works thanks, my global expressions are now being populated with data.
I just added covidstats[0]. to all of them in the rule.
-
How about this data for Carbon from the National Grid ?
I want to pick out "forecast" and "index" data.
(object) {"data":[{"regionid":3,"dnoregion":"NPG North East","shortname":"North East England","postcode":"YO1","data":[{"from":"2021-03-27T13:00Z","to":"2021-03-27T13:30Z","intensity":{"forecast":34,"index":"very low"},"generationmix":[{"fuel":"biomass","perc":24.6},{"fuel":"coal","perc":0},{"fuel":"imports","perc":2.2},{"fuel":"gas","perc":0.2},{"fuel":"nuclear","perc":35.4},{"fuel":"other","perc":0},{"fuel":"hydro","perc":4.5},{"fuel":"solar","perc":6.3},{"fuel":"wind","perc":26.9}]}]}]}
Thanks
-
LibraSunwrote on Mar 27, 2021, 2:25 PM last edited by LibraSun Mar 27, 2021, 10:51 AM
You can take not-terribly-human-readable blobs like that over to a JSON Pretty Print website (such as https://jsonformatter.org/json-pretty-print), paste it in and hit the "Outline" button, to see how the data looks in its underlying structure.
This allows you to quickly pinpoint the blob.key.subkey.data item you need to pull from in MSR.Traversing the tree from upper-left to lower-right, I see the first instance of "forcecast" lives inside an overall object
{}
(I'm namingresponse
), then the first item (i.e. element0
) of an array[]
withindata
, then inside another array within another key calleddata
, then a key calledintensity
, and finally the key you want,forecast
, yielding:
response.data[0].data[0].intensity.forecast
-
Remember that openLuup’s Test Lua window, gives you the pretty() function to do the same...
local x = luup.devices[2] print(pretty(x))
Gives:
{ category_num = 0, description = " openLuup", device_num_parent = 0, device_type = "openLuup", embedded = false, hidden = false, id = "", invisible = false, ip = "", mac = "", pass = "", room_num = 0, subcategory_num = 0, udn = "uuid:0058c0cb-c730-209a-50ab-6c88b470a8fd", user = "" }
-
cw-kidreplied to LibraSun on Mar 27, 2021, 2:45 PM last edited by cw-kid Mar 27, 2021, 10:47 AM
They don't make it easy to work all this out do they.
"cointensity" is the name of my expression within the rule that first stores all the data pulled down from the HTTP request etc.
So for my in-line substitution I have tried this, which doesn't work.
${{ cointensity.response.data(0).data(0).intensity.forecast }}
I also tried:
${{ cointensity.data(0).data(0).intensity.forecast }}
and a few other variations as well.
I want to pass the "forecast" data to a Global Expression called "currentcarbonintensity"
-
I misled you a bit. MSR uses lexpjs, which references array elements in square brackets
[]
not the parentheses I first wrote (I'll edit my response, above).Go with
cointensity.data[0].data[0].intensity.forecast
-
LibraSunwrote on Mar 27, 2021, 2:51 PM last edited by LibraSun Mar 27, 2021, 10:55 AM
(Also, I prefer to simply create another variable and set its value to
cointensity.data[0].data[0].intensity.forecast
and then reference THAT variable in my${{ }}
substitution. Why? Because this gives MSR a chance to tell me exactly where my expression is going wrong.)If you follow this scheme in your workflow, you can entirely avoid having to use
[Set Variable]
so often, since the dependent variables will all "set themselves" immediately.For example, a change to
response
will automatically update the values in any variable(s) defined byresponse.stuff
orresponse.stuff.still.more.stuff
(caveat: as long as those variables appear belowresponse
in your list of Expressions!). -
Think I need a Vera plugin Dev.
I've tried to create a modified GenericIO device with four variables but its not working.
My MSR rule is sending out the data to each variable in Vera OK
But I can't seem to get that data to display on the front of the device in the web GUI.
Also for the Home Remote dashboard app, I'd need the generic sensor device and its data fully exposing to the SDATA stream. As Home Remote uses that for integration in to Vera etc.
So close, but I don't think I'm going to be able to properly create these types of devices in Vera myself.
EDIT:
Got it working now, I was using the wrong ServiceID in my MSR rule to set the variables.
Now I just need to figure out how to get this data in to the Vera SDATA output stream for Home Remote to see.
This is all I am seeing in SDATA currently:
{ "name": "Covid-19 Stats", "altid": "", "id": 703, "category": 0, "subcategory": -1, "room": 8, "parent": 0, "configured": "0", "light": "4325315" },
"light" is showing "4325315" which is the Confirmed number of Covid Cases, so that's a start, I need the other variables exposing to the SDATA stream some how.
EDIT2: I've added more <stateVariable> sections in to the S_GenericSensor2.xml file and now I can see all four variables data in the SDATA output stream, so I should now be able to add this device in to Home Remote and see all the data.
{ "name": "Covid-19 Stats", "altid": "", "id": 703, "category": 0, "subcategory": -1, "room": 8, "parent": 0, "variable2": "3768434", "variable3": "630", "variable4": "126515", "variable1": "4325315", "configured": "0" }
EDIT3: I now have a tile on a dashboard page in the Home Remote app.
So as a proof of concept this works.
Just need an easier way to create these virtual devices in Vera.
Someone on the Vera forum suggested taking a look at the MultiString plugin.
-
It's moments like this that I'm grateful for online Forums where the open exchange of ideas and experience works to everyone's advantage, without fear of reprisal from those "in charge".
44/91