Python Forum

Full Version: How to create a value system with a temp/humidity sensor?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a dht22 temp/humidity sensor and I am looking for help on how to create a value system within the sensor reading. Currently I have a fan turning on if the reading is greater than a certain temp or humidity with if-elif-else statements. But I am looking to create a value system where I could set point values for example; t = temp, h = humidity, p = points, v = value. if t = 80 then p = .1, if t = 81 then p = .2 (and so on), if h = 40 then v = .1, if h = 50 v = .2 (and so ). Then I am looking to code a similar system with if-elif-else statements to say "if (p + v) > 1: (Turn fans on), else: (do nothing).

I am just looking for some advice on what function would be the best solution because if-elif-else doesn't seem to be the right fit and I'm not too familiar with variables and such.

I have a rpi 3. Thank You!
If there is a simple math relationship, then use it. For instance maybe p=(t-79)/10.. Otherwise, make an dictionary where keys are the input values (maybe rounded down) and the values are the output.

Normally, you can avoid writing along series of if/elif/else by using data-driven code (like using a dictionary as mentioned above).
Thank You Soo Much!!!