-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAir Status.lua
More file actions
39 lines (33 loc) · 1.3 KB
/
Air Status.lua
File metadata and controls
39 lines (33 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
return {
on = {
timer = { 'every minute' }
},
logging = {
-- level = domoticz.LOG_DEBUG,
level = domoticz.LOG_FORCE,
marker = "Air Status"
},
execute = function(domoticz, timer)
domoticz.helpers.cmdDetached('py -3 "/scripts/air.py"', 'airStatus', 'airStatus.json')
local result = domoticz.helpers.readLocalFile('airStatus.json')
if (result == nil) then
domoticz.log("No file.", LOG_ERROR)
return
end
domoticz.log("raw: "..result, LOG_DEBUG)
local jsonValeur = domoticz.utils.fromJSON(result)
if (jsonValeur == nil) then
domoticz.log("No valid json.", LOG_ERROR)
return
end
local battery = jsonValeur.battery
local temperature = jsonValeur.temperature
local humidity = jsonValeur.humidity
local co2 = jsonValeur.co2
local pm25 = jsonValeur.pm25
local tvoc = jsonValeur.tvoc
if domoticz.devices('CO2').svalues ~= co2 then domoticz.devices('CO2').update(0, co2) end
if domoticz.devices('PM25').svalues ~= pm25 then domoticz.devices('PM25').update(0, pm25) end
if domoticz.devices('TVOC').svalues ~= tvoc then domoticz.devices('TVOC').update(0, tvoc) end
end
}