Convert formula

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
basti
New user
Posts: 8
Joined: 08 Apr 2024, 09:16

Convert formula

#1 Post by basti » 08 Apr 2024, 14:56

Hello,
I am completely new to the subject. I would like to have this formula calculated:

([Pressure#Druck]+1.013)*(2.71828182845904^(-10.73797+(2617.25/([Temp#temp]+273.15))))*10

Unfortunately, I don't know how to change it so that ESPeasy can work with it. I have already tried a few things, but unfortunately without success.

I hope someone has a solution?

TD-er
Core team member
Posts: 8762
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Convert formula

#2 Post by TD-er » 08 Apr 2024, 15:14

It is probably a bit too much for the formula field.
N.B. the formula field can use %value% as template for the value of that taskvalue.
But since you need to also use other taskvalues and need quite a lot of calculation, I guess it is best done via rules.

Something like this:

Code: Select all

on Pressure#Druck do
  let,1,[Temp#temp]+273.15          // To Kelvin
  let,1,(2617.25/[var#1])-10.73797  // Exponent
  let,1,2.71828182845904^[var#1]    // e^Exponent
  let,1,([Pressure#Druck]+1.013)*[var#1]
  let,1,[var#1]*10
  logentry,"Computed value: [var#1]"
endon
The computed value can be referred to via [var#1]
You can also store it in a dummy task using the TaskValueSet command.

basti
New user
Posts: 8
Joined: 08 Apr 2024, 09:16

Re: Convert formula

#3 Post by basti » 08 Apr 2024, 15:27

TD-er wrote: 08 Apr 2024, 15:14 It is probably a bit too much for the formula field.
N.B. the formula field can use %value% as template for the value of that taskvalue.
But since you need to also use other taskvalues and need quite a lot of calculation, I guess it is best done via rules.

Something like this:

Code: Select all

on Pressure#Druck do
  let,1,[Temp#temp]+273.15          // To Kelvin
  let,1,(2617.25/[var#1])-10.73797  // Exponent
  let,1,2.71828182845904^[var#1]    // e^Exponent
  let,1,([Pressure#Druck]+1.013)*[var#1]
  let,1,[var#1]*10
  logentry,"Computed value: [var#1]"
endon
The computed value can be referred to via [var#1]
You can also store it in a dummy task using the TaskValueSet command.

Thank you very much for the quick reply. I have now tried to solve it this way:

Code: Select all

On Pressure#Druck Do
  TaskValueSet 3,1,[Pressure#Druck]
Endon

on Temp#temp do
  TaskValueSet 3,2,[Temp#temp]
 Endon
 
 on Pressure#Druck do
  let,1,[Temp#temp]+273.15          // To Kelvin
  let,1,(2617.25/[var#1])-10.73797  // Exponent
  let,1,2.71828182845904^[var#1]    // e^Exponent
  let,1,([Pressure#Druck]+1.013)*[var#1]
  let,1,[var#1]*10
  TaskValueSet 3,3,[var#1]
Endon
Unfortunately, it doesn't work that way. What am I doing wrong?

This is what my setup looks like:
Screenshot 2024-04-08 153238.jpg
Screenshot 2024-04-08 153238.jpg (81.11 KiB) Viewed 147 times
Last edited by basti on 08 Apr 2024, 15:34, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3531
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Convert formula

#4 Post by Ath » 08 Apr 2024, 15:34

basti wrote: 08 Apr 2024, 15:27 Unfortunately, it doesn't work that way. What am I doing wrong?
You have a duplicate On Pressure#Druck handler, and only the first one is executed (speed optimization in the Rules engine).
Combined you could have this:

Code: Select all

On Temp#temp do
  TaskValueSet 3,2,%eventvalue1%
Endon
 
On Pressure#Druck do
  TaskValueSet 3,1,%eventvalue1%
  let,1,[Temp#temp]+273.15          // To Kelvin
  let,1,(2617.25/[var#1])-10.73797  // Exponent
  let,1,2.71828182845904^[var#1]    // e^Exponent
  let,1,(%eventvalue1%+1.013)*[var#1]
  let,1,[var#1]*10
  TaskValueSet 3,3,[var#1]
Endon
Also used %eventvalue1% instead of the separate variables
/Ton (PayPal.me)

basti
New user
Posts: 8
Joined: 08 Apr 2024, 09:16

Re: Convert formula

#5 Post by basti » 08 Apr 2024, 15:38

Ath wrote: 08 Apr 2024, 15:34
basti wrote: 08 Apr 2024, 15:27 Unfortunately, it doesn't work that way. What am I doing wrong?
You have a duplicate On Pressure#Druck handler, and only the first one is executed (speed optimization in the Rules engine).
Combined you could have this:

Code: Select all

On Temp#temp do
  TaskValueSet 3,2,%eventvalue1%
Endon
 
On Pressure#Druck do
  TaskValueSet 3,1,%eventvalue1%
  let,1,[Temp#temp]+273.15          // To Kelvin
  let,1,(2617.25/[var#1])-10.73797  // Exponent
  let,1,2.71828182845904^[var#1]    // e^Exponent
  let,1,(%eventvalue1%+1.013)*[var#1]
  let,1,[var#1]*10
  TaskValueSet 3,3,[var#1]
Endon
Also used %eventvalue1% instead of the separate variables

This is how it works. Thank you very much. I'm still a complete beginner and have yet to really get to grips with the subject. But I haven't found many good tutorials yet...

Thanks again for the quick help.

User avatar
Ath
Normal user
Posts: 3531
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Convert formula

#6 Post by Ath » 08 Apr 2024, 17:25

basti wrote: 08 Apr 2024, 15:38 This is how it works. Thank you very much. I'm still a complete beginner and have yet to really get to grips with the subject. But I haven't found many good tutorials yet...
Haven't we pointed you at the Rules documentation yet? ;)
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests