A lua script for pms7003 is incorrect

Moderator: leecollings

Post Reply
zhuyuanxue
Posts: 1
Joined: Sunday 15 December 2019 13:17
Target OS: -
Domoticz version:
Contact:

A lua script for pms7003 is incorrect

Post by zhuyuanxue »

commandArray = {}

if devicechanged['Dust'] then

local device = otherdevices_svalues["Dust"]
print(device)

local pm1, pm25, pm10

_,_,pm1, pm25, pm10 = string.find(device, "(.+);(.+);(.+)")

print(pm1) --show temp in LOG
print(pm25) --show humidity in LOG
print(pm10) --show humstat in LOG,


commandArray[1] = {['UpdateDevice'] = 10 .. '|0|' .. pm25}
commandArray[2] = {['UpdateDevice'] = 11 .. '|0|' .. pm10}

end
return commandArray


It doesn't work.
Can someone help me?
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: A lua script for pms7003 is incorrect

Post by bewo »

Hi zhuyuanxue,

you split your string and write it in your variables as string.
In my opinion the sensor would like to be updated with a number. And your IDX you can set in string section, or use otherdevices_idx[] instead.
So, this should work:

Code: Select all


commandArray = {}

device = otherdevices_svalues["Dust"]
print(device)

local pm1, pm25, pm10

_,_,pm1, pm25, pm10 = string.find(device, "(.+);(.+);(.+)")

print(pm1) --show temp in LOG
print(pm25) --show humidity in LOG
print(pm10) --show humstat in LOG,


if devicechanged['Dust'] then
	commandArray[1] = {['UpdateDevice'] = '10|0|'..tonumber(pm25)}
	commandArray[2] = {['UpdateDevice'] = '11|0|'..tonumber(pm10)}
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 :)
Post Reply

Who is online

Users browsing this forum: Droll and 1 guest