# How to do mathematic calculations

**URL:** <https://community.homey.app/t/how-to-do-mathematic-calculations/31774>\
**Category:** Questions & Help\
**Created:** [June 28, 2020, 11:40am UTC](https://community.homey.app/t/how-to-do-mathematic-calculations/31774 "2020-06-28T11:40:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscar\_Andersson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oscar_andersson/32/26933_2.png) [@Oscar\_Andersson](https://community.homey.app/u/Oscar_Andersson)\
**Post date:** [June 28, 2020, 11:40am UTC](https://community.homey.app/t/how-to-do-mathematic-calculations/31774/1 "2020-06-28T11:40:46Z")

</div>

I want to start a fan when relative humidity is lower outside than in the basement. To make this work I need to calculate the new relative humidity when the air cools down in the basement.  
The formula for this is pretty advanced as you can see below. G1 to G3 is sensor values of indoor and outdoor temperatures and outdoor relative humidity.  
Is it possible to create a flow for this?  
I suppose I need better logic app.

RH=100\*(EXP((17,625\*(243,04\*(ln(G1/100)+((17,625_G2)/(243,04+G2)))/(17,625-ln(G1/100)-((17,625_G2)/(243,04+G2)))))/(243,04+(243,04\*(ln(G1/100)+((17,625_G2)/(243,04+G2)))/(17,625-ln(G1/100)-((17,625_G2)/(243,04+G2))))))/EXP((17,625\*G4)/(243,04+G4)))

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [June 28, 2020, 11:42am UTC](https://community.homey.app/t/how-to-do-mathematic-calculations/31774/2 "2020-06-28T11:42:54Z")

</div>

Gues you can do this easely in HomeyScript.

---

<div class="post-metadata">

**Author:** ![Oscar\_Andersson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oscar_andersson/32/26933_2.png) [@Oscar\_Andersson](https://community.homey.app/u/Oscar_Andersson)\
**Post date:** [June 28, 2020, 7:22pm UTC](https://community.homey.app/t/how-to-do-mathematic-calculations/31774/3 "2020-06-28T19:22:35Z")

</div>

Then I need to learn how to do scripts.

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [June 28, 2020, 8:30pm UTC](https://community.homey.app/t/how-to-do-mathematic-calculations/31774/4 "2020-06-28T20:30:26Z")

</div>

[https://www.w3schools.com/js/default.asp](https://www.w3schools.com/js/default.asp)  
you’r never to old to learn, just start, search this forum for HomeyScript and if you get stuck, you always can ask here for help/support. It’s FUN 😃

---

<div class="post-metadata">

**Author:** ![FKey](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/fkey/32/14793_2.png) [@FKey](https://community.homey.app/u/FKey)\
**Post date:** [June 28, 2020, 9:08pm UTC](https://community.homey.app/t/how-to-do-mathematic-calculations/31774/5 "2020-06-28T21:08:23Z")

</div>

Install the app [betterlogic](https://homey.app/nl-nl/app/net.i-dev.betterlogic/Better-Logic/)  
It supports math.js functions

What I would do is split it up in several flows and use multiple variables…

Something like:  
When Temp changes THEN calculate the part with the temp in it and assign tthe outcome to a variable1

When humidity changes THEN calculate the part with the humidity in it and assign tthe outcome to a variable2

When variable1 changes THEN calculate the next part and assign tthe outcome to a variable  
Etc

---

<div class="post-metadata">

**Author:** ![peltsi51](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peltsi51/32/12564_2.png) [@peltsi51](https://community.homey.app/u/peltsi51)\
**Post date:** [June 29, 2020, 3:02pm UTC](https://community.homey.app/t/how-to-do-mathematic-calculations/31774/6 "2020-06-29T15:02:22Z")

</div>

Hi

You can easily do this with better-logic app. I have made similar calculation to calculate the absolute humidity of outside and inside temperature, which can be compared.

[https://homey.app/f/8jiC0c](https://homey.app/f/8jiC0c)

sisäkosteus=indoor humidity  
AH=absolute humidity
