reading data from json and update virtual sensor http poller

Moderator: leecollings

Post Reply
Sprokkie
Posts: 13
Joined: Friday 22 June 2018 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

reading data from json and update virtual sensor http poller

Post by Sprokkie »

Hi all,

i want to read the value from a server and display that value in Domotiqz

if i sned this command with forefox: http://172.16.100.207:8080/rest/v1/real ... /DP_665943
i got the response :
{
"name" : "Buiten Temperatuur",
"value" : 9.0,
"type" : "Numeric",
"path" : "/",
"time" : 1542295853053,
"xid" : "DP_665943",
"deviceName" : "Boiler",
"renderedValue" : "9.0 °C",
"unit" : "",
"status" : "ok"
}

I used this example modified it in de lua folder:

Code: Select all

-- Example of JSON parser handling data with the following structure
--{
--  "id": 13,
--  "name": "outside",
--  "temperature": 12.50,
--  "tags": ["France", "winter"]
--}

-- A test with curl would be : curl -X POST -d "@test.json" 'http://192.168.1.17:8080/json.htm?type=command&param=udevices&script=example_json.lua'

-- Retrieve the request content
s = request['content'];

-- Update some devices (index are here for this example)
local id = domoticz_applyJsonPath(s,'.30')
local s = domoticz_applyJsonPath(s,'.value')
domoticz_updateDevice(30,'',s)
it does not work :(
in the log from domotiqz i got this error:

018-11-15 16:50:05.930 Error: CLuaHandler (updateDevice from LUA) : Incorrect parameters type
2018-11-15 16:50:08.507 Error: CLuaHandler (applyJsonPath from LUA) : Invalid Json data received
2018-11-15 16:50:08.507 Error: CLuaHandler (applyJsonPath from LUA) : Invalid Json data received

Dont know what i am doing wrong

another question how do i see what the http poller receives

tia
Sprokkie
hansake
Posts: 4
Joined: Sunday 09 September 2018 19:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Sweden
Contact:

Re: reading data from json and update virtual sensor http poller

Post by hansake »

I have the same problem with the function applyJsonPath when trying to get weather data from WeeWX
using the script: https://www.domoticz.com/forum/viewtopic.php?t=23791

The log shows:

Code: Select all

...
2019-07-04 12:47:39.816 Error: CLuaHandler (applyJsonPath from LUA) : Invalid Json data received
2019-07-04 12:47:39.817 Error: CLuaHandler (updateDevice from LUA) : Incorrect parameters type
2019-07-04 12:47:39.817 Error: CLuaHandler: /home/pi/domoticz/scripts/lua_parsers/weewx_json.lua:45: attempt to concatenate local 'barometer' (a nil value)
Any suggestions how to get this to work?

Regards
Hans-Åke
hansake
Posts: 4
Joined: Sunday 09 September 2018 19:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Sweden
Contact:

Re: reading data from json and update virtual sensor http poller

Post by hansake »

To get weather data from WeeWX to Domoticz I instead created a DzVents event script.
See: https://github.com/hansake/WeeWX_to_Domoticz

Regards
Hans-Åke
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest