After some advice, I created a script yesterday to pull the data from all my sensors, I have 5 in various rooms, and populate a dummy sensor called "Inside Temp". So I have a single temp of to show the current average inside temps. I have averaged this out over the last 30mins.
I am using Xiaomi Temp\Humidity sensors, and I am averaging both values, I created a data set with history of Temp and Humidity, and whenever I see an update to one of the temp devices it is added to the data set. I use a single device to pull "Humidity Status" from, as I can't average a string.
The issue I am seeing is that sometimes I see the temp devices update twice within microseconds of each other.
Code: Select all
2017-08-24 10:55:11.232 (Home Gateway) Temp (Master Bed Temp)
2017-08-24 10:55:11.239 (Home Gateway) Humidity (Master Bed Humidity)
2017-08-24 10:55:15.900 (Home Gateway) Temp (Living Room Temp)
2017-08-24 10:55:15.902 (Home Gateway) Humidity (Living Room Humidity)
2017-08-24 10:55:15.904 (Home Gateway) Temp (Living Room Temp)
2017-08-24 10:55:15.905 (Home Gateway) Humidity (Living Room Humidity)
My script.
Code: Select all
local OUTPUT_DEVICE = "Inside Temp" -- The Device to write the averages to
local STATUS_DEVICE = "Living Room Temp" -- Device to pull humidity status from (as we can't average a string)
local LOGGING = false
return {
active = true,
on = {
devices = {
"Living Room Temp",
"Master Bed Temp",
"Kids Room Temp",
"Guest Room Temp",
"Study Temp",
},
},
data = {
temperatures = { history = true, maxHours = 12 },
humiditys = { history = true, maxHours = 12 }
},
logging = {
level = domoticz.LOG_ERROR,
marker = "Tempz"
},
execute = function(domoticz, sensor)
-- define output devices
local output = domoticz.devices(OUTPUT_DEVICE)
-- add new data
domoticz.data.temperatures.add(sensor.temperature)
domoticz.data.humiditys.add(sensor.humidity)
-- half hour average
local temp_average = domoticz.helpers.round(domoticz.data.temperatures.avgSince('00:30:00'), 1)
local humid_average = domoticz.data.humiditys.avgSince('00:30:00')
local humid_status = domoticz.devices(STATUS_DEVICE).humidityStatus
-- Convert status to dzVentz format
if (humid_status == "Comfortable") then
humid_out = "1"
elseif (humid_status == "Dry") then
humid_out = "2"
elseif (humid_status == "Wet") then
humid_out = "3"
else
humid_out = "0"
end
local humid_status = domoticz.devices(STATUS_DEVICE).humidityStatus
if LOGGING then domoticz.log("Half Hourly Averages - Temp: " .. temp_average .. ". Himidity: " .. humid_average .. ". Status: " .. humid_status .. " " .. humid_out) end
output.updateTempHum(temp_average, humid_average, humid_out)
end
}
Wob