Hi Rigapapa,
I am using your twilight recipe with the sitesensor plugin. The local time offset is incorrectly returned as -4 hours in expression 3 & 4. The timezone offset is clearly -3 hours in the get function. Can you have a look why this is happening?
Click the green “Download or clone” button and choose Download ZIP;
Save the ZIP file somewhere;
UnZIP the file;
Upload the unzipped contents using the uploader at Apps > Develop apps > Luup files. Be sure to turn off the “Restart after upload” checkbox until the last file, and then turn it back on for the last file. If you forget, no worries, just check the box and upload the file again.
Hard-refresh your browser (CTRL-F5 for Chrome/Win, SHIFT-F5 for Firefox/Win, CMD+SHIFT+R for most Mac browsers)
Hi Rigpapa!
I am trying to use Site Sensor to extract data from my Weather Underground PWS with their new free API for contributors.
I can get Site Sensor to successfully obtain the data in JSON format with the following URL:
What I am having trouble with is coming up with the correct expressions for reading the JSON values for stationID:, humidity:, temp:, windSpeed:, pressure:, and precipTotal.
I am working from your recipe for openweathermap. Can you provide any guidance on one of the expressions? With one working example, I should be able to get the idea for the rest.
Thanks,
Jeff
I’ll be happy to help, but I need to see the actual raw JSON output. Please post, putting three backticks (``` ASCII 96) on lines by themselves both before and after.
Perfection! OK. The challenge that makes this just a bit harder than a straight reference to each subkey is that observations is an array (of just one element, but an array nonetheless), so to get at the data inside, you have to go through the array. SiteSensor puts the entire response under a key called response, so the first element of the observations array can be accessed using response.observations[1] or first( response.observations ).
From there, you can hit the elements directly: response.observations[1].humidity for example.
The current temperature, barometric pressure, and wind speed are all under a subkey called imperial, so you get them by doing response.observations[1].imperial.temp, etc.
If you want the sensor to trip on a value or range, you can build that into the trip expression. For example, if you want the sensor to trip when the temp drops below 35F, we just build an expression that results in boolean true: response.observations[1].imperial.temp < 35
Does the first expression in Site Sensor have to be response.observations[1] or can it be a direct call for the response.observations[1].imperial.temp or does the array have to be loaded with the response.observations[1] before the other responses can be called?
Each expression must begin with response.observations[1], and from there you add a dot and the next subkey name…
response.observations[1].humidity
response.observations[1].neighborhood
response.observations[1].imperial.temp
response.observations[1].imperial.windSpeed
etc.
Also note that case is important. Look at your JSON to get the correct spelling/case for the key.
That is the problem. No matter what I try I get an error. It looks like the table has null entries.
For example:
If expression 2 is: response.GlobalQuote{‘01. symbol’}
The log shows:
17:24:15: SiteSensor: Requesting JSON data
17:24:15: SiteSensor: Set up for HTTPS request, verify=“none”, protocol=nil, options=nil
17:24:15: SiteSensor: “GET” “https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=.dji&apikey=”, headers={ }
17:24:15: SiteSensor: Eval #1: “response.GlobalQuote”=(“table”){ __type=“null” }
17:24:15: SiteSensor: Failed to parse expression `“response.GlobalQuote{‘01. symbol’}”', { location=21, __source=“luaxp”, message=“Invalid operator”, type=“compile” }
17:24:15: SiteSensor: Eval #2: “response.GlobalQuote{‘01. symbol’}”=(“nil”)nil
Tried that a few a few others.
I have used your app with other websites and it works fine.
For some reason, this one has issues.
Is the period in the json code an issue?
Here are some more results:
12:52:10: SiteSensor: Requesting JSON data
12:52:10: SiteSensor: Set up for HTTPS request, verify=“none”, protocol=nil, options=nil
12:52:10: SiteSensor: “GET” “https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=.dji&apikey=”, headers={ }
12:52:10: SiteSensor: Eval #1: “response.Global_Quote”=(“table”){ __type=“null” }
12:52:10: SiteSensor: Eval #2: “response[‘Global Quote’]”=(“table”){ __type=“null” }
12:52:10: SiteSensor: Eval #3: “response.GlobalQuote”=(“table”){ __type=“null” }
12:52:10: SiteSensor: Failed to parse expression `“response[‘Global Quote’][‘01. symbol’]”', { location=25, __source=“luaxp”, message=“Invalid operator”, type=“compile” }
12:52:10: SiteSensor: Eval #4: “response[‘Global Quote’][‘01. symbol’]”=(“nil”)nil