Skip to content

Example to make a LUA script to mix temperature humidity barometer on the same sensor

Smanar edited this page Jul 28, 2019 · 18 revisions

Create a virtual device with "Temperature/humidity/barometer" as type. The device ID is 75 in this exemple.

commandArray = {}

function round(value, digits)
    if not value or not digits then
        return nil
    end
        local precision = 10^digits
        return (value >= 0) and
          (math.floor(value * precision + 0.5) / precision) or
          (math.ceil(value * precision - 0.5) / precision)
end

--Mixed sensor for Humidity/Temperature/Pression
if devicechanged['deCONZ - pression'] or devicechanged['deCONZ - Temperature'] or devicechanged['deCONZ - Humidity'] then
	print ('Update Mixed sensor')
	--Get all values
	h = otherdevices_humidity['deCONZ - Humidity']..';'..otherdevices_svalues['deCONZ - Humidity']
	t = tostring(round(tonumber(otherdevices_temperature['deCONZ - Temperature']),1))
	p = otherdevices_svalues['deCONZ - pression']
	--Set new value
	commandArray['UpdateDevice'] = '75|0|'..t..';'..h..';'..p
	
end

return commandArray

"75" is the Idx of the created sensor.
"deCONZ - Humidity" is humidity device.
"deCONZ - Temperature" is temperature device.
"deCONZ - Pression" is barometer device.

If you want to hide the 3th first devices, you can add a '$' in front of their name, they will not be shown in the switches or utility tab.

I don't know why but otherdevices_barometer['yourdevice'] haven't worked on my Domoticz version.

Better solution

Or you have a better alternative, a script in DZevent make by papoo, all is automatic, you just need to change devices name and create a custom device with the same name.

The plugin make 3 devices :

  • shower temperature
  • shower humidity
  • shower barometer

Rename them to :

  • $temperature shower
  • $humidity shower
  • $barometer shower

And make a virtual device THB called Shower .
Script url : Domoticz Scripts