Author Topic: Humidifier control question  (Read 208 times)

Offline owensct

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-0
Humidifier control question
« on: August 03, 2018, 05:11:53 pm »
Hi All,

I have a question about controlling a humidifier. I have a humidifier in my master bedroom along with a battery powered humidity sensor. I can create a scene that basically says if the humidity in the bedroom drops below 45% then turn on the humidifier and a corresponding scene that says if humidity is above 55% turn off humidifier, (conflict potential?). I'm looking for is something a little more complex and concise and I think the only way to accomplish is is with luup code. Can anyone advise as to where I would want to start? I want something similar to the below pseudo code:

Loop to check humidity sensor1 every xx minutes
  If humidity sensor reading is below 46% and humidifier is off
  then turn on humidifier
  if humidifier is above 55% and humidifier is on
  then turn off humidifier
  end if
end loop

I'm not sure if I need a specific command to make sure it checks the humidity status every xx minutes, but thought it might be necessary since it is a battery powered unit.

Any suggestions and or direction as to where I would start would be great. I have a programming background, (RPG), but I'm retired now and haven't coded professionally in quite a few years so I'm pretty rusty to say the least.

Thanks  ;D


Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 894
  • Karma: +139/-1
Re: Humidifier control question
« Reply #1 on: August 03, 2018, 05:26:42 pm »
I assume your humidifier is powered by a Z-wave switch? You should be able to do this with two scenes, one for on, one for off, with each having a trigger based on the sensor's humidity reading. The device action would be to turn the Z-wave switch on or off as needed.

That alone should work. You could amp it up a little (no pun intended) by adding Lua in each scene to test if the humidier is on or off as needed. That would look something like this:

In the "on" scene (humidity below 45%):
Code: [Select]
-- Return true if humidifier switch off
return luup.variable_set( "urn:upnp-org:serviceId:SwitchPower1", "Status", switch-device-number ) == "0"

In the "off" scene (humidity over 55%):
Code: [Select]
-- Return true if humidifier switch on
return luup.variable_set( "urn:upnp-org:serviceId:SwitchPower1", "Status", switch-device-number ) ~= "0"

When you return true or false in scene Lua, it tells Luup whether the scene should execute or not. So all put together, when your humidity sensor sees a reading of 44 (for example), it will try to run the "on" scene. It first runs the Lua, which examines the status of the Z-wave switch, and if it's 0 (off), returns true, which allows the rest of the scene to run (with the device action to turn the switch on). The "off" side behaves similarly, with the task reversed.

Using the scene Lua isn't strictly necessary though. Without it, the only ill effect is that the on or off scene may run again every time the humidity sensor updates (which usually isn't often enough to load anything down), and turning off a switch that's already off, or turning one on that's already on, is harmless. Using the scene Lua is a perfection, but not really necessary.
« Last Edit: August 03, 2018, 05:29:58 pm by rigpapa »
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1251
  • Karma: +31/-13
Re: Humidifier control question
« Reply #2 on: August 10, 2018, 05:08:36 pm »
I'm looking for is something a little more complex and concise and I think the only way to accomplish is is with luup code.

Or the PLEG plug-in.  Not discouraging you from learning Lua/luup, but if I were doing this I would build these inputs as triggers and properties in PLEG, then build the conditions and associated actions you want to turn them on and off....
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)