Reading data from device

Moderator: leecollings

Post Reply
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Reading data from device

Post by PatrickGoosen »

Hi everybody,

I'm having problems reading the data from my weatherstation, I can see the device and with a json command from the browser it gives my all the data I need but getting it from lua is not working.

Can someone please help me?

Kind regards,
Patrick

The error I'm getting is: EventSystem: in Tuindata: [string "local Tuin_Temperatuur_idx = 251 ..."]:14: attempt to index a nil value (field 'Tuindata')

The device is: 236 RFXLink 2301 0 Tuindata Temp + Humidity WTGR800 10.3 C, 68 %

The json command is: http://192.168.178.5:8080/json.htm?type=devices&rid=236
and returns:
Spoiler: show
{
"ActTime" : 1585907850,
"AstrTwilightEnd" : "22:22",
"AstrTwilightStart" : "05:05",
"CivTwilightEnd" : "20:53",
"CivTwilightStart" : "06:33",
"DayLength" : "13:10",
"NautTwilightEnd" : "21:36",
"NautTwilightStart" : "05:51",
"ServerTime" : "2020-04-03 11:57:30",
"SunAtSouth" : "13:43",
"Sunrise" : "07:08",
"Sunset" : "20:18",
"app_version" : "2020.1 (build 11836)",
"result" :
[
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 100,
"CustomImage" : 0,
"Data" : "10.3 C, 69 %",
"Description" : "",
"DewPoint" : "4.86",
"Favorite" : 0,
"HardwareID" : 16,
"HardwareName" : "RFXLink",
"HardwareType" : "RFLink Gateway USB",
"HardwareTypeVal" : 46,
"HaveTimeout" : false,
"Humidity" : 69,
"HumidityStatus" : "Wet",
"ID" : "2301",
"LastUpdate" : "2020-04-03 11:57:22",
"Name" : "Tuindata",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" :
[
0
],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "WTGR800",
"Temp" : 10.300000000000001,
"Timers" : "false",
"Type" : "Temp + Humidity",
"TypeImg" : "temperature",
"Unit" : 0,
"Used" : 0,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "236",
"trend" : 2
}
],
"status" : "OK",
"title" : "Devices"
}
This is the script:
Spoiler: show
local Tuin_Temperatuur_idx = 251
local Tuin_Vochtigheid_idx = 252

commandArray = {}
time = os.date("*t")
if((time.min % 1)==0)then

function round(num, idp) -- Credits go to Martin Rourke, I used his function.
local mult = 10^(idp or 1)
return math.floor(num * mult + 0.5) / mult
end

-- Split data
sWeatherTemp, sWeatherHumidity = otherdevices_svalues['Tuindata']:match("([^;]+);([^;]+)")

sWeatherTemp = tonumber(sWeatherTemp)
commandArray[1]={['UpdateDevice'] = Tuin_Temperatuur_idx .. '|0|' .. tostring(sWeatherTemp)}

sWeatherHumidity = tonumber(sWeatherHumidity)
commandArray[2]={['UpdateDevice'] = Tuin_Vochtigheid_idx .. '|' .. (sWeatherHumidity) .. '|0'}

end

return commandArray
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Reading data from device

Post by bewo »

Hi Patrick,

your weatherstation sends the data to an "real" domoticz device over RFXcom and your aim is to split the data and write it in two dummy devices... Is this right?

If yes, can you please post the output of:

Code: Select all

commandArray = {}

print(otherdevices_svalues['Tuindata'])

return commandArray
If no, please clarify... :)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

This is what I got.

lua: test.lua:3: attempt to index global 'otherdevices_svalues' (a nil value)
stack traceback:
test.lua:3: in main chunk
[C]: ?

And it's rfxlink by the way.

Device: 236 RFXLink 2301 0 Tuindata Temp + Humidity WTGR800 11.8 C, 50 %
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Reading data from device

Post by bewo »

So that's the same error as you wrote in your first post. That's spooky....

Can you post an screenshot form the device in state-table? (Under events, first index tab)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

This is the data:
Image

And the message above comes with every variable I try.
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Reading data from device

Post by bewo »

Sorry for the stupid question: Are you trying this in the domoticz event editor?

I've tried in all ways. The runtime error you posted above isn't shown there. If i try over CLI i'll get the error. Imho Domoticz doesn't offer the variables to the native lua instance...
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

I created test.lua in /home/pi/domoticz/scripts/lua and ran it with sudo lua test.lua.
Can we move to whatsapp or something, that goes quicker.
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Reading data from device

Post by bewo »

Ok - there's the problem. Give me just an second. I'll post an script for you.
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Reading data from device

Post by bewo »

Sorry for the delay - had to do some other work. :)

Here's an script for you. In the domoticz event editor just make an new lua script with device as type of trigger, insert my lines and i guess it works. :D

Code: Select all

-- Script for seperating temperature and humidity in several dummy-devices

-- Devices:
WheaterStation = 'Tuindata'
Dummy_Temperature = 'Tuin Temperatuur'
Dummy_Humidity = 'Tuin Vochtigheid'

-- Nothing to change after this line... :-)
commandArray = {}

if devicechanged[WheaterStation] then

    -- Split data
    Temperature, Humidity = otherdevices_svalues[WheaterStation]:match("([^;]+);([^;]+)")
    
    -- Update Temperature-Device
    if Temperature ~= otherdevices_svalues[Dummy_Temperature] then
        commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[Dummy_Temperature]..'|0|'..Temperature}
    end
    
    -- Update Humidity-Device
    if Humidity ~= otherdevices[Dummy_Humidity] then
        commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[Dummy_Humidity]..'|'..tonumber(Humidity)..'|0'}
    end


end

return commandArray 

Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

I Will try thanks so far.
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

IT WORKS! Thank you very much.
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Reading data from device

Post by bewo »

No problem, you're welcome. :D
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

Cheering too soon...
It updated but not anymore.

252 2020-04-17 03:23:47 Tuin - Vochtigheid 57 57/0
251 2020-04-17 03:52:17 Tuin - Temperatuur 9.30 0/9.30
236 2020-04-17 12:05:19 Tuindata 13.2;54;1 0/13.2;54;1

Any tips?
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Reading data from device

Post by bewo »

Any errors or outputs in the log?
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

Sorry my fault. It still works. Typo.
PatrickGoosen
Posts: 10
Joined: Wednesday 24 October 2018 15:27
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Purmerend
Contact:

Re: Reading data from device

Post by PatrickGoosen »

It stopped again, no idea why? No logentries nothing. Any ideas?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest