We have moved at community.getvera.com

Author Topic: New Plugin: SiteSensor  (Read 9155 times)

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: New Plugin: SiteSensor
« Reply #90 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.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: New Plugin: SiteSensor
« Reply #91 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.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: New Plugin: SiteSensor
« Reply #92 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?
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline markoe

  • Full Member
  • ***
  • Posts: 137
  • Karma: +4/-3
Re: New Plugin: SiteSensor
« Reply #93 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 :-)

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: New Plugin: SiteSensor
« Reply #94 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.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: New Plugin: SiteSensor
« Reply #95 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.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline questusa

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: New Plugin: SiteSensor
« Reply #96 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!!!

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: New Plugin: SiteSensor
« Reply #97 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.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline questusa

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: New Plugin: SiteSensor
« Reply #98 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
« Last Edit: March 08, 2019, 02:37:58 am by questusa »

Offline af20902

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: New Plugin: SiteSensor
« Reply #99 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.