[Solved]Scripting help please

Posted on
Fri Feb 17, 2017 10:02 am
jalves offline
Posts: 744
Joined: Jun 16, 2013

[Solved]Scripting help please

I want to set up a trigger that will turn on an exhaust fan (two actually) in my master bathroom when the humidity in there gets significantly higher than the rest of the house. The idea is that if somebody should happen to forget to turn the exhaust fan on when showering it will magically turn itself on. Here's what I was thinking of:
    I've got a Aeotec Multi-sensor in the master bathroom that reports humidity.
    I've got another Aeotec Multi-sensor in the Master Bedroom that reports humidity (there is a door between the MBath & MBR) so ...
    Indigo should compare the two humidity readings and trigger the bathroom fan to run for 20 minutes if the humidity in the bath is 10% higher than the reading in the bedroom.
Can't see how to do this with regular Indigo commands so I think I need a python script. Unfortunately, I'm totally python illiterate so I have no clue as to how to do this. Can anybody help?
Last edited by jalves on Fri Mar 03, 2017 2:57 pm, edited 1 time in total.

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Fri Feb 17, 2017 11:33 am
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Scripting help please

This should be close:

Code: Select all
# Get the two humidities
bathHumidity = indigo.devices[12345].sensorValue  # Insert ID of bathroom humidity device
bedroomHumidity = indigo.devices[67890].sensorValue  # Insert ID of bedroom humidity device

# Test to make sure the bath is more humid than the bedroom
if bathHumidity > bedroomHumidity:
   # Calculate the percentage difference and check to see if it's greater than or equal to 10%
    diff = float(bathHumidity - bedroomHumidity) / ((bathHumidity + bedroomHumidity) / 2) * 100
    if diff >= 10:
       # Percentage is greater than or equal to 10%, so turn on the device(s) for 20 minutes
       # Duplicate the following line for each fan
       indigo.devices.turnOn(54321, duration=1200)  # Insert ID of exhaust fan


Run this script (using the Execute Script action) from a trigger that fires whenever the bath humidity sensor value has any change.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Feb 17, 2017 11:49 am
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Scripting help please

Thanks Jay! Appreciate your quick response to this.

I probably should have made my criteria a little clearer though. Both sensors will report humidity as a %. I simply want to run the trigger when the bath is 10 higher than the BR, so I should be able to change
diff = float(bathHumidity - bedroomHumidity) / ((bathHumidity + bedroomHumidity) / 2) * 100
to
diff = float(bathHumidity - bedroomHumidity

Right?

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Fri Feb 17, 2017 12:10 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Scripting help please

Yes, if you want just the difference between the values vs the percentage difference. In fact, to do just a straight comparison it gets much easier (since you don't really have to test first to make sure the bathroom is higher):

Code: Select all
# Get the two humidity values
bathHumidity = indigo.devices[12345].sensorValue  # Insert ID of bathroom humidity device
bedroomHumidity = indigo.devices[67890].sensorValue  # Insert ID of bedroom humidity device

# Calculate the difference and check to see if it's greater than or equal to 10
if (bathHumidity - bedroomHumidity) >= 10:
   # Difference is greater than or equal to 10, so turn on the device(s) for 20 minutes
   # Duplicate the following line for each fan
   indigo.devices.turnOn(54321, duration=1200)  # Insert ID of exhaust fan

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Feb 17, 2017 2:46 pm
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Scripting help please

Perfect!

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Fri Mar 03, 2017 3:09 pm
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: [Solved]Scripting help please

Just replying to my own thread for the possible benefit of others who may be considering a similar script.

I found a minor typo in Jay's suggested script; The line that says
Code: Select all
indigo.devices.turnOn(54321, duration=1200)  # Insert ID of exhaust fan

needed to be changed to
Code: Select all
indigo.device.turnOn(54321, duration=1200)  # Insert ID of exhaust fan

Note the absence of the "s" in indigo.device....

After making that change I realized that there was actually no reason to have the fan run for 20 minutes each time the logic triggered it. Since the action fires whenever the bathroom humidity sensor reports a change I could just put a smaller run-time in (I settled on 5 minutes). If the humidity hasn't yet come down enough (but is still changing) the trigger fires again.

Tried this out today by purposely not turning the fan on when I showered. Sure enough a few minutes into the shower the fan kicked on. It stayed running until some time after the differential returned to a satisfactory range.

Some may be wondering why I wanted to do this. I live in central FL and mold/mildew is a constant threat. I wanted to be sure that bathroom exhaust fans ran whenever somebody showered to keep humidity low not just in the bathroom but in the whole house.

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest