Page 1 of 1

Compute Humidity

Posted: Friday 04 December 2020 8:51
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

Re: Compute Humidity  [Solved]

Posted: Friday 04 December 2020 11:12
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

Re: Compute Humidity

Posted: Monday 20 February 2023 13:24
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, ????)

Re: Compute Humidity

Posted: Monday 20 February 2023 15:25
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)

Re: Compute Humidity

Posted: Monday 20 February 2023 16:11
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)

Re: Compute Humidity

Posted: Monday 20 February 2023 16:33
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?

Re: Compute Humidity

Posted: Monday 20 February 2023 19:42
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))