Page 1 of 1

A lua script for pms7003 is incorrect

Posted: Sunday 15 December 2019 13:22
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?

Re: A lua script for pms7003 is incorrect

Posted: Monday 13 January 2020 14:47
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