Compute Humidity  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Compute Humidity

Post by Piacco »

Hello,

For the humidity outside i use a DHT22 sensor.

In the wiki of DzVents i've read that DzVents can compute the status (HUM_NORMAL, HUM_COMFORTABLE, HUM_DRY, HUM_WET).
But how can i use the function HUM_COMPUTE?
Or have i write a function by myself, like this example?

Code: Select all

if humidity < 30 then
             hum_stat = 0
          elseif humidity >= 30 and humidity < 45 then
              hum_stat = 1
          elseif humidity >= 45 and humidity < 70 then 
              hum_stat = 2
          elseif humidity >= 70 then
               hum_stat = 3
  end   
I would be glad if someone can explain this to me :D

Greetings,

Piacco
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Compute Humidity  [Solved]

Post by waaren »

Piacco wrote: Friday 04 December 2020 8:51 In the wiki of DzVents i've read that DzVents can compute the status (HUM_NORMAL, HUM_COMFORTABLE, HUM_DRY, HUM_WET).
I would be glad if someone can explain this to me :D
Humidity status can be computed with below pseudo code. So if both humidity and temperature are known, dzVents (version >= 3.0.15) can do that for devicetypes temp+hum and devicetypes temp+hum+baro and will do that if you leave the status parameter out or set it to domoticz.HUM_COMPUTE.

For hum only type devices dzVents cannot do that because it does not know what temperature to use. So for these types you have to do that in your own script (See function at the bottom of this post) or ignore the temperature and only use HUM_DRY, HUM_WET and HUM_NORMAL.

Code: Select all

humidity <= 30 >> DRY
humidity >= 70 >> WET
humidity between 35 and 65 and temperature between 22 and 26 >> COMFORTABLE
else >> NORMAL

Code: Select all

function humidityStatus (temperature, humidity)
	local temperature = tonumber(temperature)
	local humidity = tonumber(humidity)
        local dz = dz or domoticz

	if humidity <= 30 then return dz.HUM_DRY
	elseif humidity >= 70 then return dz.HUM_WET
	elseif  humidity >= 35 and
			humidity <= 65 and
			temperature >= 22 and
			temperature <= 26 then return dz.HUM_COMFORTABLE
	else return dz.HUM_NORMAL end
end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Compute Humidity

Post by Piacco »

Maybe a stupid question, but how do I get the humidity status from the function humidityStatus into the device?

Code: Select all

function humidityStatus (temperature, humidity)
	local temperature = tonumber(temperature)
	local humidity = tonumber(humidity)
        local dz = dz or domoticz

	if humidity <= 30 then return dz.HUM_DRY
	elseif humidity >= 70 then return dz.HUM_WET
	elseif  humidity >= 35 and
			humidity <= 65 and
			temperature >= 22 and
			temperature <= 26 then return dz.HUM_COMFORTABLE
	else return dz.HUM_NORMAL end
end

dz.devices('Vochtigheid-badkamer').updateHumidity(humidity, ????)
willemd
Posts: 631
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Compute Humidity

Post by willemd »

https://www.domoticz.com/wiki/DzVents:_ ... ity_sensor

status can be domoticz.HUM_NORMAL, HUM_COMFORTABLE, HUM_DRY, HUM_WET

(in your case use dz instead of domoticz)
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Compute Humidity

Post by Piacco »

The problem is that I don't know how to use the return state of the function, how can i use the return state to update my sensor?

Now i'm use this code to determine the status,

Code: Select all

if humidity < 30 then
             hum_stat = 2
          elseif humidity >= 30 and humidity < 45 then
              hum_stat = 0
          elseif humidity >= 45 and humidity < 70 then 
              hum_stat = 1
          elseif humidity >= 70 then
               hum_stat = 3
          end  
           
dz.devices('Vochtigheid-badkamer').updateHumidity(humidity, hum_stat)
willemd
Posts: 631
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Compute Humidity

Post by willemd »

Not sure about dzvents exactly but in most programming languages ypu would assign the return status of the function to a variable,
like this:
hum_stat=humidityStatus(temperature,humidity)
(as-if the function itself is the return value)

and then you can use that variable to update the device with:
dz.devices('Vochtigheid-badkamer').updateHumidity(humidity, hum_stat)

Or do it directly without a variable in between:
dz.devices('Vochtigheid-badkamer').updateHumidity(humidity, humidityStatus(temperature,humidity))

Did you try that?
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Compute Humidity

Post by Piacco »

No I did't try that :oops:

Thank you, that did the trick :D

Code: Select all

function humidityStatus (temperature, humidity)
	local temperature = tonumber(temperature)
	local humidity = tonumber(humidity)
    local dz = dz or domoticz

	if humidity <= 30 then return dz.HUM_DRY
	elseif humidity >= 70 then return dz.HUM_WET
	elseif  humidity >= 35 and
			humidity <= 65 and
			temperature >= 22 and
			temperature <= 26 then return dz.HUM_COMFORTABLE
	else return dz.HUM_NORMAL end
end

dz.devices('Vochtigheid-badkamer').updateHumidity(humidity, humidityStatus(temperature,humidity))
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest