Right now, the Lua script, updt_unit.lua, also listed below, uses the "/json.htm?type=settings" API to set the user variable according to the value of "TempUnit" : 0 (for °C) or "TempUnit": 1 (for °F). It is triggered when the system starts and manually with a virtual sensor. I have to remember to activate the virtual switch whenever the temperature display units are changed, which I am sure to forget to do. Presumably the two scripts could be combined, but would increase the execution time by whole 250 ms per sensor update.

So finally here are my questions:
- Is there a quick way to find out which units are used for displaying temperatures?
- Is there a dzVents trigger available for when the temperature unit setting is modified?
- Is there a better way to update the humidity status in the first place?
Michel
humid_status.lua:
Code: Select all
--[[
Fix up humidity status of "Temp + Humidity" and "Temp + Humidity + Baro" type sensors
Add their idx in the devices list below
Tested with temp+humidity sensors with idx 206 and 208 and temp+humidity+Baro sensor with idx 207
User variable 'TemperatureUnit' must be 'C' or 'F' indicating unit used to display temperature values
Tested in Domoticz 2023.1, Build f9b9ac774, and dzVents Version: 3.1.8
]]
return
{
on =
{
devices =
{
206, 207, 208
},
},
data = {
updating = { initial = 0 }
},
logging = {
level = domoticz.LOG_ERROR, -- change LOG_DEBUG to LOG_ERROR when script functions
marker = 'fix_humid',
},
execute = function(dz, item)
dz.log('item '..item.name..', type: '..item.deviceType..', idx: '..item.id)
if dz.data.updating == 0 then
dz.data.updating = 1
dz.log('updating item')
local temp = item.temperature
if dz.variables('TemperatureUnit').value == 'F' then
dz.log('Converting '..temp..'°F')
temp = dz.utils.toCelsius(temp)
dz.log(' to '..temp..'°C')
end
if string.match(item.deviceType, 'Baro') then
dz.log('item.updateTempHumBaro')
item.updateTempHumBaro(temp, item.humidity, dz.HUM_COMPUTE, item.pressure, item.forecast)
else
dz.log('item.updateTempHum')
item.updateTempHum(temp, item.humidity, dz.HUM_COMPUTE)
end
elseif dz.data.updating == 1 then
dz.log('not updating item')
dz.data.updating = 0
end
end
}
updt_unit.lua:
Code: Select all
return {
on = {
system = { 'start' },
devices = { 'Update TemperatureUnit' },
httpResponses = { 'result' }
},
execute = function(dz, item)
if (item.isSystemEvent) or (item.isDevice) then
dz.openURL({
url = dz.settings['Domoticz url'].."/json.htm?type=settings",
method = 'GET',
callback = 'result'
})
end
if item.isHTTPResponse and item.isJSON then
local unit = 'F'
if item.json.TempUnit == 0 then
unit = 'C'
end
dz.variables('TemperatureUnit').set(unit)
end
end
}