The Vera Community forums have moved!

Advanced => Programming => Plugins & Plugin Development => Topic started by: rigpapa on August 24, 2017, 08:32:49 am

Title: New Plugin: SiteSensor
Post by: rigpapa on August 24, 2017, 08:32:49 am
I had need to probe a few local and remote web services from my Vera, and use the responses to trigger scenes. I got tired of pasting my code snippets around, so I wrapped them into a plugin I call SiteSensor.

SiteSensor probes a remote web site or service and can look for a matching pattern in the response, or request and parse a JSON response and put selected values through simple expressions.

It's now released in the plugin store, and documentation (with examples) is here: http://www.toggledbits.com/sitesensor/ (http://www.toggledbits.com/sitesensor/)

It runs on UI7 and openLuup, and is available in the Alt App Store as well.


REVISION HISTORY
2019-03-17: Version 1.10 released. This version principally adds the option for additional (>8) expressions on JSON requests, and can export expression values to virtual sensors. openLuup users will need to source and install additional files to support virtual devices, as openLuup does not include the suite of standard Vera sensor device definitions.

2018-07-29: Version 1.9 released. Changes handling of ArmedTripped and LastTrip to Vera semantics, which is to say, doesn't touch them anymore, and relies on Vera or openLuup to provide updates when needed.

2018-06-24: Version 1.8 released to AltAppStore and Vera Plugin Marketplace (expected availability 6/25). See changelog (https://github.com/toggledbits/SiteSensor/blob/master/CHANGELOG.md).

2018-02-11: Version 1.5 released. This is a maintenance release only, officially publishing a fix for a luaxp problem that caused dot-notation traversal of data to fail in some instances.

2018-02-05: Version 1.4 released. This version contains the following fixes and enhancements:
Title: Re: New Plugin: SiteSensor
Post by: akbooer on August 24, 2017, 09:29:02 am
It runs on UI7 and openLuup. I'll be releasing it in the Alternate App Store shortly.

Ah, excellent. Seems like a more capable enhancement to the ping sensor.

Thanks for planning the AltAppStore distribution!  I'll try it when it's there.
Title: Re: New Plugin: SiteSensor
Post by: parkerc on August 27, 2017, 01:30:04 pm
Hi @rigpapa

Looks like a great plugin, very versatile thanks so much for sharing..

The Recipe idea is great, as that is where people will get sucked into using it, can I make a suggestion - could you maybe list just the names of the recipes you already have (there's 3 currently on your site)
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on August 27, 2017, 03:46:49 pm
@parkerc -- absolutely!... but be a little more specific so I manage your expectations... where do you want me to list them?
Title: Re: New Plugin: SiteSensor
Post by: parkerc on August 29, 2017, 05:02:38 pm
@parkerc ... where do you want me to list them?

What's normally best - is to just edit/update your very first post (at the top/above) as that'll be the first thing most people read when they come to check out your plugin via this forum.

Keep that first post high-level, by just appending the name and a brief explanation of the recipe- and if needed make reference (via a link) to any future/specific responses within your thread where youve perhaps gone into detail on a how to build a particular recipe etc.

Hope that helps..
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on August 29, 2017, 08:32:45 pm

What's normally best [snip]

Hope that helps..

Absolutely!
Title: Re: New Plugin: SiteSensor
Post by: Spanners on August 30, 2017, 08:10:41 pm
This is a way cool plug in.

I'm currently using it to alert me when Overclockers Australia posts their weekly funny pics. :)

Looking forward to seeing if/how you implement POST queries and perhaps authentication in Lua. I'm using curl in my unifi sensor and I'd like to replace it with Lua.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on November 25, 2017, 06:56:15 am
Works great on the vera but somehow on openluup, I am not able to get to the settings page. The control panel on openluup stays empty. The AltUI on the vera works...
Title: Re: New Plugin: SiteSensor
Post by: akbooer on November 25, 2017, 10:12:12 am
Perhaps there is useful diagnostic information in the logs ...?
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on November 25, 2017, 10:45:36 am
Works great on the vera but somehow on openluup, I am not able to get to the settings page. The control panel on openluup stays empty. The AltUI on the vera works...

Did you install from the Vera store or the Alternate App Store?
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on November 25, 2017, 12:21:13 pm
I tried both, and got the same result. Also tried to update the plugin after installing it, which made me end up with the GitHub version. The Alt Store says it is version 1.2.
The vera has version 1.3.
Title: Re: New Plugin: SiteSensor
Post by: akbooer on November 25, 2017, 12:57:37 pm
I loaded from AltAppStore and got v1.3, as expected.  The GitHub version, unspecified from the openLuup plugins page, should be the same. 

I get both Control and Settings tab on the device page, but I don't know what to do next...!

What openLuup and AltUI versions are you running?
Title: Re: New Plugin: SiteSensor
Post by: akbooer on November 25, 2017, 01:08:58 pm
but I don't know what to do next...

...so I followed the first example in the docs, and now I know my external IP!

All working just fine.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on November 25, 2017, 01:18:18 pm
There was a bug in the AltAppStore configuration for the plugin... my match pattern for GitHub was PHP-ish, not Lua-ish (%w in PHP != %w in Lua), so it was excluding the two JavaScript files that drive the UI. I didn't see it in testing because I had previously manually uploaded those files to my openLuup tree during development, so they were already there. Your experience, obviously, was going to very different, so apologies for not catching that earlier!

That was only in the 1.2 version configuration in the AltAppStore. It is fixed in the 1.3 version of the plugin in the AltAppStore.

Edit/postscript: I could not get the AltAppStore to update to v1.3 using the AltUI "Update" button to save my life. But, going back to the store, finding the plugin, and hitting the "AltUI" install button did the trick. Paging @amg0!
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on November 26, 2017, 06:29:12 am
Yup,
It is working now. Thank you!
Title: Re: New Plugin: SiteSensor
Post by: parkerc on December 25, 2017, 01:13:25 pm
Hi @rigpapa

I was just wondering - could your plugin work with the Ring Doorbell ? Here?s some information on what is communicated.

http://www.kidder.io/2017/07/04/ring-doorbell-api/
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on December 26, 2017, 02:27:39 pm
The linked page describes the interface between the doorbell and Ring's servers. While you could mimic the doorbell's requests to Ring, I'm not sure it would get you much, as the most interesting things to do here seem to revolve around initiating the SIP connection between the doorbell (as originator) and the server (as gateway), and if initiated by SiteSensor on the Vera, the usual originator (doorbell) likely would not be in a state where it would know to complete the connection.

I'm not a Ring user yet. I got my wife one for Christmas, so in a couple of days I surely will be. Maybe once that happens, I can try it and see what surprises come out of it.
Title: Re: New Plugin: SiteSensor
Post by: tomtcom on December 26, 2017, 03:45:48 pm
The linked page describes the interface between the doorbell and Ring's servers. While you could mimic the doorbell's requests to Ring, I'm not sure it would get you much, as the most interesting things to do here seem to revolve around initiating the SIP connection between the doorbell (as originator) and the server (as gateway), and if initiated by SiteSensor on the Vera, the usual originator (doorbell) likely would not be in a state where it would know to complete the connection.

I'm not a Ring user yet. I got my wife one for Christmas, so in a couple of days I surely will be. Maybe once that happens, I can try it and see what surprises come out of it.

Thanks, I have a lot of interest too as a Ring user. Vera's official stance is they won't integrate half of the device meaning Ring won't expose the video portion and Vera stopped talking about it. Many said it did not matter (including myself) as we wouldn't use Vera for video but a real integration of the events such as the door bell ringing and the motion notification. Those can easily trigger scenes and everyone would use the video from the Ring app itself.
Title: Re: New Plugin: SiteSensor
Post by: parkerc on December 26, 2017, 04:45:33 pm
Agree with @tomtcom

Being able to capture and use motion information would be good, so much so that I  had been using the Home Assistant app/setup to benefit from their integration with Ring.

There seems to be a number of people who reverse engineered the api and this one is in Php - https://github.com/jeroenmoors/php-ring-api/blob/master/ring.php

It would be cool to get sole form of basic integration with Ring for Vera.
Title: Re: New Plugin: SiteSensor
Post by: Don Phillips on December 26, 2017, 08:08:38 pm
I use Blue Iris to trigger motion from 4 cameras to Vera. Does Ring work with Blue Iris? I would think so.
Title: Re: New Plugin: SiteSensor
Post by: Nameless on December 26, 2017, 11:03:47 pm
I use Blue Iris to trigger motion from 4 cameras to Vera. Does Ring work with Blue Iris? I would think so.

Ring does not work with Blue Iris currently. A good video doorbell has yet to become available with that software. Hikvision makes one, but it rates very poor on the Blue Iris forum.
Title: Re: New Plugin: SiteSensor
Post by: Don Phillips on December 27, 2017, 08:55:14 pm
I use Blue Iris to trigger motion from 4 cameras to Vera. Does Ring work with Blue Iris? I would think so.

Ring does not work with Blue Iris currently. A good video doorbell has yet to become available with that software. Hikvision makes one, but it rates very poor on the Blue Iris forum.

Hmm. Their website indicates it is a Wi-Fi device.  I would think Blue Iris could find it and stream its feed through its interface. I did notice its operating temperature range is -5F to 120F.  For an outdoor device, I would expect -20F to 140F.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on December 29, 2017, 03:29:54 pm
It appears that the device protocol is SIP for establishing video chat sessions, like a video-capable VoIP phone. It is effectively a one-button VoIP phone that can only dial one number, the Ring mother ship. Unless BlueIris supports SIP (the version 4.something I have does not), I don't see how it could use Ring as a camera. Again, my experience with the device is very limited, but based on the specs of each, I don't see how they'd connect.
Title: Re: New Plugin: SiteSensor
Post by: tomtcom on December 29, 2017, 07:07:39 pm
It appears that the device protocol is SIP for establishing video chat sessions, like a video-capable VoIP phone. It is effectively a one-button VoIP phone that can only dial one number, the Ring mother ship. Unless BlueIris supports SIP (the version 4.something I have does not), I don't see how it could use Ring as a camera. Again, my experience with the device is very limited, but based on the specs of each, I don't see how they'd connect.

Thanks rigpapa. So based on the link provided what about responses on motion events and ringing of the bell? Perhaps eliminating the video component all together. We would always use the Ring app but in Vera, I'd like to hook the motion/ringing activities as devices that could launch scenes.
Title: Re: New Plugin: SiteSensor
Post by: Don Phillips on December 29, 2017, 08:15:14 pm
It appears that the device protocol is SIP for establishing video chat sessions, like a video-capable VoIP phone. It is effectively a one-button VoIP phone that can only dial one number, the Ring mother ship. Unless BlueIris supports SIP (the version 4.something I have does not), I don't see how it could use Ring as a camera. Again, my experience with the device is very limited, but based on the specs of each, I don't see how they'd connect.

Thanks for the information. Will look for other solutions in the future.
Title: Re: New Plugin: SiteSensor
Post by: rearden on February 01, 2018, 06:00:04 pm
Thank you for this plugin.  It seems to be quite useful.  I am using it to pull data from my local Emoncms on a raspberry pi.  It pulls watts from an Input.  I have solar panels and want to know when I am exporting power so I can turn on additional loads and turn them off when my power import exceeds a value.  I will use the vera as a coarse power diverter.

So far I have SiteSensor pulling back the watts value and it will trigger when watts exceeds a specified value.  Is there a way to expose the response.value so that it can be used in a scene?  Right now when I go to write a scene, it only gives me variations of armed/disarmed and tripped/not tripped as the trigger condition.  I need to trigger scenes based on the value exceeding X (turn on) and run a different scene when the value is less than Y (turn off).  X and Y are not the same (because turning on a load changes the trigger value) and I need something more than a hard inequality.

Rearden
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 02, 2018, 05:22:37 pm
OK, I can fairly easily expand on SiteSensor's scene options to make this easier. I'm getting ready to an update this weekend, which would publish Monday if Vera stays to their usual schedule.

For the moment, I recommend making an additional SiteSensor device (go to My Apps, click on Details where SiteSensor is listed, and click the "Create another" button. Have one instance trigger when watts > X, and the other trigger when watts < Y. Then have your "high watts" scene trigger from the first instance going into triggered state, and your "low watts" scene trigger when the second instance goes into triggered state.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 04, 2018, 12:14:45 pm
Just confirming, version 1.4 has gone into the approval queue with Vera, and they should approve it shortly. This will provide additional scene/notification/PLEG trigger options based on the 8 user-definable expressions. See the first post in this thread for full release notes.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on February 04, 2018, 11:32:16 pm
Updated the plugin and now it is failing to evaluate a json

See the log
Code: [Select]
Response HTTP status 200, body={"val":8,"ack":true,"ts":1517804967381,"q":0,"from":"system.adapter.mihome-vacuum.0","lc":*********,"_id":"mihome-vacuum.0.info.state","type":"state","common":{"name":"Vacuum state","type":"number","read":true,"max":30,"states":{"1":"Unknown 1","2":"Sleep no Charge","3":"Sleep","5":"Cleaning","6":"Returning home","7":"Manuell mode","8":"Charging","10":"Paused","11":"Spot cleaning","12":"Error?!"}},"native":{}}

20:29:34: Failed to execute `response.val', { message="Invalid reference", type="evaluation", source=

I would use a reference to evaluate response.val which is the first value but it keeps on returning a nill value. There seems to be a typo in the code where the ' became a `

Apparently the shortcut expression with only one term after the "response" no longer works. I have had to use the response['var'] expression
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 05, 2018, 07:04:04 am
The odd quote mark is just me going old school Unix in the error message. Showing my age I guess. The problem is that the structure of your data is making luaxp mistake the table for one of its atoms, and it doesn't want that there. Your solution is the correct one--change the reference form to a quoted identifier--for the moment. I'll tighten up luaxp today and post an updated library. Thanks for the report.
Title: Re: New Plugin: SiteSensor
Post by: ustredna on February 07, 2018, 03:51:39 pm
i have the same problem....
21:48:21: Requesting JSON data
21:48:21: GET http://www.stokercloud.dk/dev/getjsondriftdata.php?mac=hampl, headers={  }
21:48:21: Response HTTP status 200, body={"501":"38.3 &deg;C flow","502":"0 % Power","503":"22 &deg;C Shaft","504":"0 kW Power","505":"73.7 kg Hopper","506":"0 Lx Light","507":"Stopped clock ","508":"07/02-2018 21:47:58","521":"0 &deg;C Return","522":"0 liter/hour Flow","524":"0 &deg;C External temperature","525":"47 &deg;C Temperature DHW","526":"16.5 % Actual oxygen","527":"0 % Target oxygen","528":"750 Gram auger/6 min","530":"18.683 kg Today","531":"0 kg/m2 Today","532":"0 &deg;C Smoke temp.","533":"65 &deg;C Target boiler temp.","534":"56 &deg;C Target DHW temp.","542":" ","584":"Nitra ","585":"100 % humidity","586":"1011 hPa pressure","587":"3.1 m/s wind speed","588":"http://openweathermap.org/img/w/50n.png ","589":"1 &deg;C air temperature","591":"10 null","592":"0.0 &deg;C T5","alarm":"0"}

21:48:21: Failed to execute `response."507"', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval #1: response."507"=(nil)nil
21:48:21: Failed to execute `response."504"', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval #2: response."504"=(nil)nil
21:48:21: Failed to execute `response."501"', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval #3: response."501"=(nil)nil
21:48:21: Failed to execute `response."506"', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval #4: response."506"=(nil)nil
21:48:21: Failed to execute `response."505"', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval #5: response."505"=(nil)nil
21:48:21: Failed to execute `response."525"', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval #6: response."525"=(nil)nil
21:48:21: Failed to execute `response."alarm"', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval #7: response."alarm"=(nil)nil
21:48:21: Failed to execute `response."alarm" = 1', { location=10, type="evaluation", source="LuaXP", message="Invalid subreference" }
21:48:21: Eval trip expression: response."alarm" = 1=(nil)nil
21:48:21: Next activity in 60 seconds


before 3 days working fine, but now with errors.
Query is ok but expression error...

is any solution ???????

please help

Peter
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 07, 2018, 05:19:41 pm
Try the response["507"] form
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on February 09, 2018, 09:49:28 pm
Updated to the latest github on openluup and I am having another problem. it looks like you have a naming problem with the controlpanel function. It is called "SiteSensor.controlPanel" in the json file while that function does not exists in the js file. There the function is only called "controlPanel" so I am getting this error:

Code: [Select]
an error occurred while displaying the javascript tab. devid: 0-20 err:SiteSensor.controlPanel is not a function. (In 'SiteSensor.controlPanel(20)', 'SiteSensor.controlPanel' is undefined)
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 10, 2018, 07:46:53 am
It's an exported function of the module, so it is addressed by its module name. I suspect you don't have the latest UI7 JS file. You need to install both files. The UI7 file is used both for UI7 and ALTUI.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on February 10, 2018, 12:01:02 pm
Hmm it looks like it was a browser cache problem. Tried from another computer and I am not seeing the same error.
Title: Re: New Plugin: SiteSensor
Post by: s4nup on February 15, 2018, 09:07:48 am
Hi

Had this working correctly, but am also now getting the "Query OK, but 1 expressions failed" error message

This is the output of my HTTP Request:

{"cleanMissionStatus":{"cycle":"none","phase":"charge","expireM":0,"rechrgM":0,"error":0,"notReady":0,"mssnM":20,"sqft":154,"initiator":"alexa","nMssn":40},"pose":{"theta":162,"point":{"x":213,"y":-31}},"bin":{"present":true,"full":false},"batPct":100}

My query is:
response.cleanMissionStatus.cycle to which the response is currently : none

My Trip expression is response.cleanMissionStatus.cycle = "none" to which i am getting the following in the log:
Code: [Select]
14:05:02: Failed to execute `response.cleanMissionStatus.cycle = "none"', { location=35, __source="luaxp", message="Invalid assignment", type="evaluation" }
14:05:02: Eval trip expression: response.cleanMissionStatus.phase="charge"=(nil)nil

As i said, this was working correctly before, but now its not. What am i doing wrong??
Title: Re: New Plugin: SiteSensor
Post by: tomtcom on February 15, 2018, 06:30:46 pm
The linked page describes the interface between the doorbell and Ring's servers. While you could mimic the doorbell's requests to Ring, I'm not sure it would get you much, as the most interesting things to do here seem to revolve around initiating the SIP connection between the doorbell (as originator) and the server (as gateway), and if initiated by SiteSensor on the Vera, the usual originator (doorbell) likely would not be in a state where it would know to complete the connection.

I'm not a Ring user yet. I got my wife one for Christmas, so in a couple of days I surely will be. Maybe once that happens, I can try it and see what surprises come out of it.

Thanks, I have a lot of interest too as a Ring user. Vera's official stance is they won't integrate half of the device meaning Ring won't expose the video portion and Vera stopped talking about it. Many said it did not matter (including myself) as we wouldn't use Vera for video but a real integration of the events such as the door bell ringing and the motion notification. Those can easily trigger scenes and everyone would use the video from the Ring app itself.

Hi Rigpapa, in the post above you said you got your wife a Ring for Christmas. With sitesensor work moving along, I'm wondering how I could assist in helping to test if we could capture the motion events for use in Vera or if someone has rang the bell? We do not need the video in Vera but the ability to tie into the events to trigger actions on like turning on a light when Ring has motion.

Thanks!
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 15, 2018, 07:06:31 pm
There seem to be other better integrations in the works, and I've been busy with some other plugins, so I haven't taken the time yet to look and don't have a ton of motivation to do so at the moment. I'm kind of hoping that Vera themselves does something, or we end up with a solution through other channels that are gaining traction (IFTTT or MQTT?).
Title: Re: New Plugin: SiteSensor
Post by: tomtcom on February 15, 2018, 08:57:52 pm
There seem to be other better integrations in the works, and I've been busy with some other plugins, so I haven't taken the time yet to look and don't have a ton of motivation to do so at the moment. I'm kind of hoping that Vera themselves does something, or we end up with a solution through other channels that are gaining traction (IFTTT or MQTT?).

Thanks but I haven't heard of any others. Vera said no to the ring because they couldn't get the video portion and the Wink plugin has been withdrawn. IFTTT beta has also been no activity for months from the Vera side.

If you know of anything else, please let me know and I'll investigate.
Title: Re: New Plugin: SiteSensor
Post by: s4nup on February 16, 2018, 09:13:15 am
Any guidance to the following??

Thanks
Hi

Had this working correctly, but am also now getting the "Query OK, but 1 expressions failed" error message

This is the output of my HTTP Request:

{"cleanMissionStatus":{"cycle":"none","phase":"charge","expireM":0,"rechrgM":0,"error":0,"notReady":0,"mssnM":20,"sqft":154,"initiator":"alexa","nMssn":40},"pose":{"theta":162,"point":{"x":213,"y":-31}},"bin":{"present":true,"full":false},"batPct":100}

My query is:
response.cleanMissionStatus.cycle to which the response is currently : none

My Trip expression is response.cleanMissionStatus.cycle = "none" to which i am getting the following in the log:
Code: [Select]
14:05:02: Failed to execute `response.cleanMissionStatus.cycle = "none"', { location=35, __source="luaxp", message="Invalid assignment", type="evaluation" }
14:05:02: Eval trip expression: response.cleanMissionStatus.phase="charge"=(nil)nil

As i said, this was working correctly before, but now its not. What am i doing wrong??
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 16, 2018, 09:15:38 am
Your trip expression is actually being an assignment, not a comparison. Use the "==" operator rather than single "=".
Title: Re: New Plugin: SiteSensor
Post by: tunnus on February 28, 2018, 12:11:02 pm
Was wondering if this plugin could be used to get electricity price data from a site (https://www.nordpoolgroup.com/Market-data1/Dayahead/Area-Prices/FI/Hourly/?dd=FI&view=table) and then use the data in PLEG?

Another option would be to use lua code, but not sure how it would be done. A draft below

Code: [Select]
local https = require("ssl.https")
local ltn12 = require("ltn12")
-- 5 Second timeout
https.TIMEOUT = 5
 
  local response_body = {}
  local request_body = ''
 
  local r, c, h = https.request{
    url = 'https://https://www.nordpoolgroup.com/Market-data1/Dayahead/Area-Prices/FI/Hourly/?dd=FI&view=table',
    method = "GET",
    headers = {
      ["Content-Length"] = string.len(request_body),
      ["Content-Type"] = "application/x-www-form-urlencoded"
    },
    source = ltn12.source.string(request_body),
    sink = ltn12.sink.table(response_body)
  }
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 28, 2018, 02:03:18 pm
Not directly in the form given at the URL in your code (which contains an error--two https protocol specs in a row). There is an API you can sign up for, here: https://www.nordpoolgroup.com/TAS/api/ (https://www.nordpoolgroup.com/TAS/api/)

...but... the day-ahead API call (which is free, apparently) comes back in XML, and SiteSensor currently does plain text and JSON only, no XML as yet. I would be happy to look at XML parsing though, but it's not something I can commit to supporting tomorrow, or likely even next week.

If we could get JSON, then SiteSensor could do what you want immediately (grab the data, pass it to PLEG). That API just doesn't do JSON for that data.

Title: Re: New Plugin: SiteSensor
Post by: akbooer on February 28, 2018, 02:26:55 pm
There's a simple xml coder/encoder as part of openLuup.  If you've got an example of the response XML, then I could see if it's up to the job.

Or if that's not the issue, just say so!
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 28, 2018, 03:03:37 pm
No, the issue is that the output of that parser is usable for us programmers but a nightmare for anyone else, and I'm pretty sure that most users will not have an easy go figuring out how to map the resulting data into an expression that gets them the values they want reliably. That then, makes it turn into a support nightmare for me.
Title: Re: New Plugin: SiteSensor
Post by: akbooer on February 28, 2018, 04:19:54 pm
So why not translate XML -> Lua -> JSON?

Take, for example, a possibly familiar bit of XML:
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
    <specVersion>
        <major>1</major>
        <minor>0</minor>
    </specVersion>
    <device>
        <deviceType>urn:schemas-toggledbits-com:device:SiteSensor:1</deviceType>
        <staticJson>D_SiteSensor1.json</staticJson>
        <friendlyName>Site Sensor</friendlyName>
        <manufacturer>rigpapa</manufacturer>
        <manufacturerURL>http://www.toggledbits.com/sitesensor/</manufacturerURL>
        <modelDescription>Site Sensor</modelDescription>
        <modelName>Site Sensor</modelName>
        <handleChildren>0</handleChildren>
        <Category_Num>12</Category_Num>
        <serviceList>
          <service>
            <serviceType>urn:schemas-toggledbits-com:service:SiteSensor:1</serviceType>
            <serviceId>urn:toggledbits-com:serviceId:SiteSensor1</serviceId>
            <SCPDURL>S_SiteSensor1.xml</SCPDURL>
          </service>
          <service>
            <serviceType>urn:schemas-micasaverde-com:service:SecuritySensor:1</serviceType>
            <serviceId>urn:micasaverde-com:serviceId:SecuritySensor1</serviceId>
            <SCPDURL>S_SecuritySensor1.xml</SCPDURL>
          </service>
          <service>
            <serviceType>urn:schemas-micasaverde-com:service:HaDevice:1</serviceType>
            <serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId>
            <SCPDURL>S_HaDevice1.xml</SCPDURL>
          </service>
        </serviceList>
        <implementationList>
          <implementationFile>I_SiteSensor1.xml</implementationFile>
        </implementationList>
    </device>
</root>

this simple bit of code:
Code: [Select]
local xml = require "openLuup.xml"
local json = require "openLuup.json"

local lua = xml.decode(x)
print (pretty(lua))

local j = json.encode (lua)
print (j)

produces this Lua:
Code: [Select]
{root = {
device = {
Category_Num = "12",
deviceType = "urn:schemas-toggledbits-com:device:SiteSensor:1",
friendlyName = "Site Sensor",
handleChildren = "0",
implementationList = {implementationFile = "I_SiteSensor1.xml"},
manufacturer = "rigpapa",
manufacturerURL = "http://www.toggledbits.com/sitesensor/",
modelDescription = "Site Sensor",
modelName = "Site Sensor",
serviceList = {service = {{
SCPDURL = "S_SiteSensor1.xml",
serviceId = "urn:toggledbits-com:serviceId:SiteSensor1",
serviceType = "urn:schemas-toggledbits-com:service:SiteSensor:1"
},{
SCPDURL = "S_SecuritySensor1.xml",
serviceId = "urn:micasaverde-com:serviceId:SecuritySensor1",
serviceType = "urn:schemas-micasaverde-com:service:SecuritySensor:1"
},{
SCPDURL = "S_HaDevice1.xml",
serviceId = "urn:micasaverde-com:serviceId:HaDevice1",
serviceType = "urn:schemas-micasaverde-com:service:HaDevice:1"
}}},
staticJson = "D_SiteSensor1.json"
},
specVersion = {
major = "1",
minor = "0"
}
}}

and then this JSON:
Code: [Select]
{"root":{
    "device":{
      "Category_Num":"12",
      "deviceType":"urn:schemas-toggledbits-com:device:SiteSensor:1",
      "friendlyName":"Site Sensor",
      "handleChildren":"0",
      "implementationList":{"implementationFile":"I_SiteSensor1.xml"},
      "manufacturer":"rigpapa",
      "manufacturerURL":"http://www.toggledbits.com/sitesensor/",
      "modelDescription":"Site Sensor",
      "modelName":"Site Sensor",
      "serviceList":{"service":[{
          "SCPDURL":"S_SiteSensor1.xml",
          "serviceId":"urn:toggledbits-com:serviceId:SiteSensor1",
          "serviceType":"urn:schemas-toggledbits-com:service:SiteSensor:1"
        },{
          "SCPDURL":"S_SecuritySensor1.xml",
          "serviceId":"urn:micasaverde-com:serviceId:SecuritySensor1",
          "serviceType":"urn:schemas-micasaverde-com:service:SecuritySensor:1"
        },{
          "SCPDURL":"S_HaDevice1.xml",
          "serviceId":"urn:micasaverde-com:serviceId:HaDevice1",
          "serviceType":"urn:schemas-micasaverde-com:service:HaDevice:1"
        }]},
      "staticJson":"D_SiteSensor1.json"
    },
    "specVersion":{
      "major":"1",
      "minor":"0"
    }
  }}

...and you're back to what you need?
Title: Re: New Plugin: SiteSensor
Post by: rearden on February 28, 2018, 04:21:56 pm
Thank you for the changes!  It has taken a while for me to get back around to this.  First my Vera did not want to update, but now it has the changes.  I have created some scenes which change state based upon response.value > X and will see how they work.  What are the drawbacks or how can I have it query things more frequently than 60sec?  I am querying my own EmonPi inside my LAN.  I don't what to overload things, but more frequent than 1 min would be nice.

rearden

OK, I can fairly easily expand on SiteSensor's scene options to make this easier. I'm getting ready to an update this weekend, which would publish Monday if Vera stays to their usual schedule.

For the moment, I recommend making an additional SiteSensor device (go to My Apps, click on Details where SiteSensor is listed, and click the "Create another" button. Have one instance trigger when watts > X, and the other trigger when watts < Y. Then have your "high watts" scene trigger from the first instance going into triggered state, and your "low watts" scene trigger when the second instance goes into triggered state.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 28, 2018, 04:41:59 pm
The hard lower limit is 60 seconds right now; even if you go in and edit the state variable (Interval) directly, it will still constrain the delay back to 60 seconds. I can change that for a future release. I'll do a quick change and point you to the file, so you can upload it to your Vera. Give me a few minutes...
Title: Re: New Plugin: SiteSensor
Post by: tunnus on March 02, 2018, 02:58:48 am
maybe a wrong thread to ask, but... does anyone know why online Lua compilers do not seem to support socket commands?

if I have
Code: [Select]
local http = require("socket.http")

then e.g. ideone.com gives
Code: [Select]
lua5.3: prog.lua:3: module 'socket.http' not found:
no field package.preload['socket.http']
no file '/usr/local/share/lua/5.3/socket/http.lua'
no file '/usr/local/share/lua/5.3/socket/http/init.lua'
no file '/usr/local/lib/lua/5.3/socket/http.lua'
...
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on April 12, 2018, 12:45:24 pm
As I am finding more and more applications for this plugin on openluup, I have a suggestion/feature request:
Could one or two "value.expression" values be shown on the device below device state on the device page?
Right now it displays "Last query succeeded!" on the device page and nothing at all on the frontpage of ALTUI.
I would like to be able to select which value to show on both the front page and the device page.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 12, 2018, 01:11:35 pm
That's so funny. I just posted the latest version to AltAppStore today along with your request for VirtualSensor, and was thinking exactly the same thing. I think I can spudge that in and post it before I leave for vacation. Stay tuned.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 12, 2018, 03:04:50 pm
OK. If you install the "Github.stable" version from the AltAppStore, you'll get the value of the first (#1) expression on the dashboard card. You can fancy it up with strings, formatting, and concatencation... for example, my test site, which grabs the current weather, uses this expression: response.weather[1].description)+" "+format("%.0f", response.main.temp * 9 / 5 - 459.67)+"&deg;" and so the dashboard card is currently displaying clear sky 73?.

There's a full write-up of LuaXP's (the expression parser) syntax and function library on my web site: https://www.toggledbits.com/luaxp
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on April 12, 2018, 06:14:58 pm
Works great! Thank you.
Maybe something specific to ALTUI though. It is not showing on the "Favorite" dashboard, the homepage of ALTUI which shows only your favorite devices. I see a few apps which are showing variables there. Would be great if that same text could also be shown on that page.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 13, 2018, 10:35:01 am
It is showing for me. Maybe a hard refresh/cache flush on your browser?
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on April 13, 2018, 12:24:30 pm
I tried on various browser after a cache reset with the same result. See attached... This is odd. I can see it on the device page but not here
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 13, 2018, 01:13:43 pm
Hmm. I'm not super-familiar with AltUI. On my system, Favorites is the same as the device list, just a subset of devices. There's also this thing called "My Home" that shows some devices as well, although on mine they are not the devices marked as favorites, and some have values and some do not, but the presentation is different from yours. Screen shots attached.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on April 13, 2018, 01:46:21 pm
Ohh I see, we were talking about different things. These work for me and are under the "device" menu. What I am referring to is the frontpage which you get to when you first open the browser to the ALTUI page. There you would only see favorite devices. You can access it by clicking on the ALTUI logo on the top left. You would typically only see the weather widget but if you set some devices as favorites you will see them there too. The favorites seem to be stored in the browser cache though.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 13, 2018, 02:06:04 pm
Ha! I'd never noticed that, because up until today, I had never marked any devices as "Favorite" in AltUI. I do see it now.

Let me poke around.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 13, 2018, 03:26:09 pm
OK. Update to the latest Github.stable. That was an interesting distraction. Definitely not the easiest part of AltUI to work in; there are a lot of style side-effects to the box model/inherited css being used there. Side-effect of those draggable widgets, it seems. I'm not going to spend a lot of time working around it, but what's there should suffice. Actually looks much better on my phone than on my desktop.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on April 13, 2018, 03:54:09 pm
Good enough for my purpose. It takes out the icon and replaces it with the string...
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 13, 2018, 04:56:37 pm
It's all or nothing. If you implement the function, AltUI puts the title in the box, but leaves the rest up to the function. And it does nasty things like set a ginormous default font size (62px on my desktop, 42 on my phone), and that widget CSS, that just make formatting it in there nightmare. Just the fact that the icons in the default presentation are over-scaled to a larger size (makes them kind of blurry and ugly) and there's quite a bit of hard-coding for certain device types, makes me think this is something that was done early on but hasn't revisited in a while. The function isn't even documented in his current plugin guide; I found it by reading his code.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on April 13, 2018, 05:45:53 pm
Thank you. Pretty happy with the outcome actually. See attached
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on April 13, 2018, 06:10:54 pm
Looks good! And thanks for introducing me to a feature I had completely missed!
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on April 25, 2018, 06:04:44 pm
Alright new question here. I have been playing with the returned expression and am trying to apply a global function to one of the returned variables within the expression field but it does not appear to work. I tried to add the function (rounding of the number) to the LuaXP file which I assume is being used for evaluation but it did not work either.

How would you allow the use of global variables and functions in the expression field?

Edit: nevermind. I looked at the luaxp code and found that the round function is natively there... my bad
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on May 11, 2018, 06:02:19 pm
Glad you found your answer. I've been out of the country for a month, sorry I couldn't reply quickly enough for a pointer to save you time. I'll work at making the function library documentation more easily accessible.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on May 24, 2018, 07:08:30 pm
Hey rigpapa, a minor thing but on ALTUI, the icon for the Sitesensor in the altAppstore shows up as http://apps.mios.com/http://www.toggledbits.com/sitesensor/assets/sitesensor-default.png which of course is not valid. I suspect it is a problem when switching between the mios repo to github when updating plugin version. It might be a simple fix in the alt app store as well.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on May 24, 2018, 07:10:53 pm
Thanks for letting me know! I'll check it out...
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on May 27, 2018, 02:51:53 pm
@rafale77 Hmmm. I'm not seeing an issue with the icon in my installation, nor do I see a problem with the URL in the AltAppStore config for the plugin. Am I looking in the right place for what you're describing?
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on May 27, 2018, 05:43:10 pm
Interesting. I am seeing the problem only on the "Plugin" screen where it lists all my installed plugins on my openLuup installation. Not in the AltAppStore. I wonder where this url is stored.
Title: Re: New Plugin: SiteSensor
Post by: jswim788 on May 27, 2018, 07:58:49 pm
Note that even if you get the link corrected in the AppStore, you need to either uninstall and reinstall the plugin in openLuup or you need to edit the user_data.json to correct it.  I made a mistake with my icon location in the AppStore and fixed it, but the plugin list wasn't getting updated.  Editing the user_data.json was easy enough for me in this case.

I don't know how your icon link got messed up, but I know I managed to do that myself.
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on May 27, 2018, 08:19:18 pm
I just checked and nope, it's not in the user_data.json. The url is not stored there.
Title: Re: New Plugin: SiteSensor
Post by: jswim788 on May 27, 2018, 10:24:31 pm
Maybe we are talking about something else, but every one of the plugins in my user_data.json has an Icon: line which has either a file location or a URL in openLuup.  Sample picture attached.  But maybe you are referring to something else?  Or the plugin is missing this field entirely?
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on May 27, 2018, 11:51:25 pm
What I meant was that this field has the correct URL in the user_data file. It is not where the problem is. I have no idea where that wrong URL is coming from and where it is read.
Title: Re: New Plugin: SiteSensor
Post by: jswim788 on May 28, 2018, 01:38:42 am
What I was trying to point out is that if @rigpapa or anyone else has fixed the wrong URL in the AppStore since you installed it, your plugin won't be updated unless you delete and reinstall it or edit the user_data.json.  And that may or may not be the problem you are seeing - just mentioning it.
Title: Re: New Plugin: SiteSensor
Post by: akbooer on May 28, 2018, 03:30:45 am
What I was trying to point out is that if @rigpapa or anyone else has fixed the wrong URL in the AppStore since you installed it, your plugin won't be updated unless you delete and reinstall it or edit the user_data.json.  And that may or may not be the problem you are seeing - just mentioning it.

Absolutely correct, see...
http://forum.micasaverde.com/index.php/topic,84980.msg388187.html#msg388187
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on May 28, 2018, 03:57:39 am
I see, I got it fixed by stopping openLuup and manually editing the json file. It was just the https problem. I was looking for the invalid "apps.mios" url which I could not find which is what confused me.
Title: Re: New Plugin: SiteSensor
Post by: Buxton on June 09, 2018, 08:02:41 pm
I'm getting a startup error in the openLuup startup log.

Code: [Select]
2018-06-09 15:56:15.047   openLuup.chdev:: [string ""]:39: unexpected symbol near '}'
2018-06-09 15:56:15.047   luup.create_device:: [86] D_SiteSensor1.xml / I_SiteSensor1.xml / D_SiteSensor1.json

There were no errors during installation from the altApp store.  Current sitesensor is 1.6.  The program is installed and the UI appears functional, however, I tried to create a link to the https://api.sunrise-sunset.org as outlined in your blog post, but the plugin does not seem to respond. 

The values you suggested for this particular link were input into each field, (there are some misnamed fields in the blog description) and after a luup reload, the values persist, however the plugin does not appear to produce any result. 

I set to true constants for debug, altUI, and openLuup at the top of the sitesensor lua file.  After doing so and with a luup reload, I can see that setting the armed switch in the UI for the sensor creates a log entry, as does toggling log requests.  However there is still no visible action and the UI on the control tab reads tripped, without any of the other fields in the UI displaying information.

Hope all that helps.

edit  Request Timeout: should be 60, not 28000 and Request Interval should be listed --set for 28000
"Re-Evaluate Trip Expression" should be "Re-evaluate the expressions" and should read to set to a minute not seconds.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on June 09, 2018, 08:51:13 pm
Changing the debug constant will add more logging info. The two lines you posted don't help much. Post more log, or better yet, email it to me (email address on my profile).

Don't need to change isALTUI or isOpenLuup, these are managed by detection at startup.

You might ask @akbooer about the startup error. Although it's near the SiteSensor plugin load, and without more context, it's hard to discern what's going on there, but off-hand it doesn't look like a SiteSensor issue. And the fact that you say its logging things when you try to arm/disarm/etc. suggests the plugin started and you've got at least a somewhat running device.

It would also help to run this request and send me the output with the logs:

Code: [Select]
http://your-openluup-ip:3480/data_request?id=lr_SiteSensor&action=status
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on June 09, 2018, 09:18:08 pm
Oh, and if you are running the recent OpenLuup update with the new XML parser,  you need to install the "stable" version of SiteSensor.
Title: Re: New Plugin: SiteSensor
Post by: Buxton on June 09, 2018, 09:32:34 pm
Yes, I'm running the test version of openLuup with the new XML parser.   Where is the "stable" version of SiteSensor?


Also getting a 501 error to the status command.

"No handler for data_request?id=lr_SiteSensor"
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on June 09, 2018, 10:08:54 pm
If you go to the AltAppStore, you can choose the "stable" branch to install. See how that goes first.

Edit: correct from mobile
Title: Re: New Plugin: SiteSensor
Post by: Buxton on June 09, 2018, 11:25:51 pm
OK, installed the stable version (1.7 per the UI) and there are no error messages per the install, however, I'm still seeing the same error in the startup log.  There's also no change in behavior, however, I'm now seeing status updates in the openLuup log; these updates were not in the log while using version 1.6.  Here's a sample of the current log status:
Code: [Select]
2018-06-09 20:07:58.102   openLuup.http:: GET /luvd/D_SiteSensor1.xml HTTP/1.1 tcp{client}: 0x3dd553c8
2018-06-09 20:07:58.102   openLuup.http:: request completed (1671 bytes, 1 chunks, 0 ms) tcp{client}: 0x3dd553c8

I'm pretty sure the startup error message refers to this plugin as the time signatures are identical and the previous plugin loads and operates correctly.  BTW, out of ten plugins loaded, this is the only one giving me trouble....  Will see if AK can provide some debugging direction for "openLuup.chdev".
Title: Re: New Plugin: SiteSensor
Post by: akbooer on June 10, 2018, 03:06:22 am
It's actually the loader module which needs DEBUG set to true.  If it's a new enough version it should create a file, DUMP_..., of the problem device.  The latest testing branch should actually report those two startup log lines in correct order (swapped in earlier versions.)  The error message itself comes from the Lua interpreter, so I can't improve on that.

Let me know if you need more.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on June 10, 2018, 09:27:43 am
@buxton, I do most of my development under openLuup, and it's working fine in my current environment, but I haven't upgraded to AK's latest and greatest. I've got other stuff on my agenda today but I'll try to get time to upgrade my install and look at it. Are you able to run that status query now that you're on 1.7?
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on June 10, 2018, 06:24:08 pm
@Buxton: version 1.7 works fine for me on the current testing branch of openLuup. I don't get any startup errors, and following the recipe on my web site for the civil twilight configuration works as described.
Title: Re: New Plugin: SiteSensor
Post by: Buxton on June 10, 2018, 07:26:17 pm
OK.  I'll have to look closer at what's going on here then as it looks like the problem must be on my end (and it usually is :D).  The function that's conveying the error is "local function assemble_device_from_files (devNo, device_type, upnp_file, upnp_impl, json_file)" in the loader.lua module.

AK makes some observations about device files at the head of the function......

I'm not sure how to set a breakpoint in ZBS for a variable watch (upnp_impl == I_SiteSensor1.xml) as that's the only way I can imagine tracking this down.

As an aside, I typically see this  interpreter error when I spaceout and use "=" instead of "==",  a habit from using other languages  :)
Title: Re: New Plugin: SiteSensor
Post by: Buxton on June 10, 2018, 07:40:33 pm
I just updated openLuup to the most recent testing version and now sitesensor works!  Truly sorry for the trouble. I dislike wasting folk's time on such things.

I did do an update prior to trying to track down this error, but apparently something must have corrupted as the testing version of openLuup has the same id# as before.  Odd though that this was the only plugin effected.  Anyway, all is good.  Your code is beyond awesome BTW.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on June 10, 2018, 08:34:57 pm
@buxton, that's good news! Just a reminder, double-check your plugin config for the civil twilight and make sure you have a long request interval (the post recommends 28800), and use the "Re-evaluate" flag set to "Every minute." This is an important point to not spam the server with queries for results that only change daily. Must be good netizens! :)
Title: Re: New Plugin: SiteSensor
Post by: Buxton on June 10, 2018, 10:00:35 pm
Yep, all is good.  I would correct your blogpost though as the request interval is mistaken for request time out.....  I can see how someone would swap the values causing real havoc.
Title: Re: New Plugin: SiteSensor
Post by: ellisb on September 02, 2018, 03:39:56 am
Hi all, I have been using SiteSensor for a few months and love it. I have been reading the  JSON data for my homes battery however after an update from the manufacturer the location of the JSON file went from http to https with a self-signed certificate. SiteSensor then stopped working. I now have the following error below. I used python to make the same request and get a '<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1045)>'.

This makes me think the Vera is not trusting the batteries site. How do I make the Vera trust it again?

Thanks all
Brain

08:34:06: SiteSensor: Requesting JSON data
08:34:06: SiteSensor: "GET" "https://192.168.0.15/api/system_status/soe", headers={  }
08:34:06: SiteSensor: Response HTTP status nil, body=
08:34:06: SiteSensor: Eval #1: "response.percentage"=("table"){ __type="null" }
08:34:06: SiteSensor: Failed to execute `""', { message="Missing expected operand", __source="luaxp", type="evaluation" }
08:34:06: SiteSensor: Eval trip expression: ""=("nil")nil
08:34:06: SiteSensor: Next activity in 40 seconds

Title: Re: New Plugin: SiteSensor
Post by: rigpapa on September 02, 2018, 07:57:35 am
Hi all, I have been using SiteSensor for a few months and love it. I have been reading the  JSON data for my homes battery however after an update from the manufacturer the location of the JSON file went from http to https with a self-signed certificate. SiteSensor then stopped working. I now have the following error below. I used python to make the same request and get a '<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1045)>'.

This makes me think the Vera is not trusting the batteries site. How do I make the Vera trust it again?


They appear to be using an unsigned certificate on their interface. Not bad, not great, but also should not be a problem. The default configuration for the ssl.https module is to not verify the peer certificate, so you should not be getting this error. Sit tight a bit. I'm going to poke around in my test environment.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on September 02, 2018, 08:49:53 am
Hi all, I have been using SiteSensor for a few months and love it. I have been reading the  JSON data for my homes battery however after an update from the manufacturer the location of the JSON file went from http to https with a self-signed certificate. SiteSensor then stopped working. I now have the following error below. I used python to make the same request and get a '<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1045)>'.

This makes me think the Vera is not trusting the batteries site. How do I make the Vera trust it again?


They appear to be using an unsigned certificate on their interface. Not bad, not great, but also should not be a problem. The default configuration for the ssl.https module is to not verify the peer certificate, so you should not be getting this error. Sit tight a bit. I'm going to poke around in my test environment.

OK. On three different Veras of mine, all three running different firmware, the verified default option is don't check the peer certificate (seen in /usr/lib/lua/ssl/https.lua), and that's confirmed by testing on each against several sites. I can't reproduce the error you're getting. But, clearly there is something different going on for you, so I'd like to have you install the attached version of L_SiteSensor1.lua that explicitly sets the SSL options (doesn't rely on defaults), and see if we can get the behavior to change.

Download this file, and then upload it to your Vera with the "Reload Luup after upload" box checked. Once the upload/reload finishes, go into the SiteSensor's control panel, make sure log capture is on, and toggle the "armed" state of your SiteSensor to force it to do a request, and let me know what it says.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on September 06, 2018, 12:40:08 pm
Hi all, I have been using SiteSensor for a few months and love it. I have been reading the  JSON data for my homes battery however after an update from the manufacturer the location of the JSON file went from http to https with a self-signed certificate. SiteSensor then stopped working. I now have the following error below. I used python to make the same request and get a '<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1045)>'.

This makes me think the Vera is not trusting the batteries site. How do I make the Vera trust it again?


They appear to be using an unsigned certificate on their interface. Not bad, not great, but also should not be a problem. The default configuration for the ssl.https module is to not verify the peer certificate, so you should not be getting this error. Sit tight a bit. I'm going to poke around in my test environment.

OK. On three different Veras of mine, all three running different firmware, the verified default option is don't check the peer certificate (seen in /usr/lib/lua/ssl/https.lua), and that's confirmed by testing on each against several sites. I can't reproduce the error you're getting. But, clearly there is something different going on for you, so I'd like to have you install the attached version of L_SiteSensor1.lua that explicitly sets the SSL options (doesn't rely on defaults), and see if we can get the behavior to change.

Download this file, and then upload it to your Vera with the "Reload Luup after upload" box checked. Once the upload/reload finishes, go into the SiteSensor's control panel, make sure log capture is on, and toggle the "armed" state of your SiteSensor to force it to do a request, and let me know what it says.


@ellisb, any luck?
Title: Re: New Plugin: SiteSensor
Post by: markoe on February 17, 2019, 04:06:11 am
Was wondering if this plugin could be used to get electricity price data from a site (https://www.nordpoolgroup.com/Market-data1/Dayahead/Area-Prices/FI/Hourly/?dd=FI&view=table) and then use the data in PLEG?

Another option would be to use lua code, but not sure how it would be done. A draft below

Code: [Select]
local https = require("ssl.https")
local ltn12 = require("ltn12")
-- 5 Second timeout
https.TIMEOUT = 5
 
  local response_body = {}
  local request_body = ''
 
  local r, c, h = https.request{
    url = 'https://https://www.nordpoolgroup.com/Market-data1/Dayahead/Area-Prices/FI/Hourly/?dd=FI&view=table',
    method = "GET",
    headers = {
      ["Content-Length"] = string.len(request_body),
      ["Content-Type"] = "application/x-www-form-urlencoded"
    },
    source = ltn12.source.string(request_body),
    sink = ltn12.sink.table(response_body)
  }

Hi tunnus

I am after excatly the same ... get the hourly electricity prices and then use those in order to benefit the low price hours. Did you manage to get the you system working . This xml parsing is too mutch for my programing skills :-)
Title: Re: New Plugin: SiteSensor
Post by: rafale77 on February 18, 2019, 02:19:01 am
rigpapa: One suggestion, Would it be possible for you to make the number of parsed data a user option? I am thinking about using SiteSensor as a bridge plugin to connect to hubitat through its RestAPI on openLuup and would like a single call to parse a much greater number of responses than 8.
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on February 18, 2019, 08:07:17 am
rigpapa: One suggestion, Would it be possible for you to make the number of parsed data a user option? I am thinking about using SiteSensor as a bridge plugin to connect to hubitat through its RestAPI on openLuup and would like a single call to parse a much greater number of responses than 8.

Of course, that number is rather arbitrary and there's little reason not to do more. I've got a number of irons in the fire at the moment, but I'll see what I can do.
Title: Re: New Plugin: SiteSensor
Post by: questusa on March 07, 2019, 07:25:28 pm
I have a web-enabled device which reports water temperature on its web page.
I need to grub that value and assign to virtual sensor.

Developers provided API to get that temperature in JSON file, so I need your app to get that file by using CURL, then parse it and give me the value.

cmd command looks like this:
curl -d "api_key=b05bad1826f1a1910935b777918eec702be395d5&command=get_water_temperature" -X POST http://192.168.1.104/Api
as an output I get this:
{"type":"success","msg":"36.59"}

So I need that value 36.59 as a variable for my sensor.

Developers also provided Python script, which works fine as well (outside of my Vera):
#!/opt/local/bin/python2.7

import requests
import json

url = 'http://192.168.1.104/api'

api_key = "b05bad1826f1a1910935b777918eec702be395d5"

payload = {
    'api_key': api_key,
    'command': 'get_water_temperature'
}

# POST with form-encoded data
r = requests.post(url, data=payload)

# Response, status etc
r.text
r.status_code

try:
    data = json.loads(r.text)
    print data['msg']
except:
    print "Error parsing data"

_____________________________________________
Could you please help me to get needed variable?

Thank you very much!!!
Title: Re: New Plugin: SiteSensor
Post by: rigpapa on March 07, 2019, 09:14:45 pm
I have a web-enabled device which reports water temperature on its web page.
I need to grub that value and assign to virtual sensor.

Developers provided API to get that temperature in JSON file, so I need your app to get that file by using CURL, then parse it and give me the value.

cmd command looks like this:
curl -d "api_key=b05bad1826f1a1910935b777918eec702be395d5&command=get_water_temperature" -X POST http://192.168.1.104/Api
as an output I get this:
{"type":"success","msg":"36.59"}

So I need that value 36.59 as a variable for my sensor.

<snip>

Could you please help me to get needed variable?

Thank you very much!!!

Unfortunately, SiteSensor does not currently do POST queries, and it's not something I have the time at the moment to add.

The most straightforward alternate way to go would be to use your working curl command in Lua. You can use this to set a value on a virtual sensor:

Code: [Select]
local p = io.popen( 'curl -d "api_key=b05bad1826f1a1910935b777918eec702be395d5&command=get_water_temperature" -X POST http://192.168.1.104/Api' )
local responseText = p:read("*a")
p:close()
local json = require "dkjson"
local data = json.decode( responseText )
local currTemp = data.msg
luup.variable_set( "urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", currTemp, virtualSensorDeviceNum )

Put in the device number of your virtual sensor in the variable_set call (last argument). You can run that code periodically, either as scene Lua (in a scene, put the code in just as shown) that you trigger on a schedule, or in startup Lua by launching/creating a repeating timer/delay process:

Code: [Select]
-- Put this in startup Lua
function updateWaterTemp()
    -- Put all the code from above here...
    -- then add the following:
    luup.call_delay( 'updateWaterTemp', 60 ) -- 60 second repetition
end
updateWaterTemp() -- Call the function to get the ball rolling.

Warning: This is all pseudo-ish code, untested. The spirit is there. Unfortunately, I'm not able at the moment to set up a test jig and make sure it all works exactly as shown, but this should be close enough to let you take it the last mile.
Title: Re: New Plugin: SiteSensor
Post by: questusa on March 07, 2019, 10:36:48 pm
Thanks!!! AWESOME!!! It works!!!

This is the working code:

local p = io.popen( "curl -d 'api_key=b05bcd1826f1a1810935b677918eec702be395d5&command=get_water_temperature' -X POST http://192.168.1.28/Api" )
local responseText = p:read("*a")
p:close()
local json = require "dkjson"
local data = json.decode(responseText)
local currTemp = data.msg
local Ftemp = currTemp * 9 / 5 + 32
luup.variable_set( "urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature" ,Ftemp, 324)
return true
Title: Re: New Plugin: SiteSensor
Post by: af20902 on March 09, 2019, 12:29:31 pm
Hi Rigpapa,

I sent you a note on a Paypal contribution, but I'm not sure if you got to see that note, so I'll repeat it here. In addition to more than 8 variables as some others have requested, I'd like to be able to call a SiteSensor refresh from luup. I tried issuing commands to disable and then re-enable the SiteSensor, but that didn't cause an update to happen. When I disable/enable in the GUI it immediately updates, but not when I toggle that from code in a scene. I last tried this a few weeks ago, so if you've changed the behavior in a recent update let me know so I can try it again.

The reason this would be useful for me is that I use SiteSensor to get the status of my thermostat from the Lennox iComfort site every 2 minutes. (This thermostat can't be queried locally... only via their web site's API)  I've had some cases where a command to change a thermostat setting fails to apply even though the curl command comes back with a successful response. As a result I always immediately pull the current status after issuing any command to verify the command was received. This requires me to have all the code to query the site and parse the JSON response inside each related scene. I have scenes to set the Away mode, cancel the Away mode, turn the temp down at night, turn the temp up in the morning, turn the temp down a degree, turn it up a degree, etc., so I have this code repeated a bunch of times.

It would be much cleaner if I could just ask Site Sensor to refresh and then look at the variable that Site Sensor has updated to verify the command worked. Also the way I'm doing it now there is no relationship between my update and the time of the next refresh by Site Sensor. If I could force the plugin to refresh I'm assuming that would reset the interval so that SiteSensor wouldn't query the API again until the interval had passed which would reduce the number of calls to the API.

Thanks again for all the great plugins.