Formula >40 char with log()
Moderators: grovkillen, Stuntteam, TD-er
Formula >40 char with log()
Hi,
I would like to use a formula to convert an NTC reading to a temperature.
The formula would be: T = (1/(log(%value%/(32768-%value%))/3988+0.003354)-278.4235
The isses are
a) > 40characters
b) log() needed and at least du to the doc not available.
What are the best options to solve this?
Preferably within the formula of a device, I'd like not to fill up slots with dummy devices because I have a lot of entities to contol.
Thanks for your support
p.s. any suggestions for a good tutorial that goes a bit more in depth about the architecture of the source code, rules, etc.?
I would like to use a formula to convert an NTC reading to a temperature.
The formula would be: T = (1/(log(%value%/(32768-%value%))/3988+0.003354)-278.4235
The isses are
a) > 40characters
b) log() needed and at least du to the doc not available.
What are the best options to solve this?
Preferably within the formula of a device, I'd like not to fill up slots with dummy devices because I have a lot of entities to contol.
Thanks for your support
p.s. any suggestions for a good tutorial that goes a bit more in depth about the architecture of the source code, rules, etc.?
Re: Formula >40 char with log()
You can also act on the generated event and handle the value in the rules.
Then just store it in a variable.
Let's assume your current task is called "ntc" and the value name is "t"
So right now you're using the task variable as [ntc#t]
With a variable you would use [var#1] (or whatever nr you gave it)
Rules would look like this:
Then just store it in a variable.
Let's assume your current task is called "ntc" and the value name is "t"
So right now you're using the task variable as [ntc#t]
With a variable you would use [var#1] (or whatever nr you gave it)
Rules would look like this:
Code: Select all
On ntc#t do
let,1,1/(log(%eventvalue1%/(32768-%eventvalue1%))/3988+0.003354)-278.4235
endon
Re: Formula >40 char with log()
By the way, you're missing a parenthesis, so not sure whether I can simplify the 1/ part or not.
Re: Formula >40 char with log()
Just based on the 2^15 value in your formula, I assume you're measuring using some ADC which isn't the internal ADC.
Would it be useful to have filtering/binning/interpolation options for other ADC plugins as well, like how it is now done for the internal ADC?
See: https://espeasy.readthedocs.io/en/lates ... #p002-page
Would it be useful to have filtering/binning/interpolation options for other ADC plugins as well, like how it is now done for the internal ADC?
See: https://espeasy.readthedocs.io/en/lates ... #p002-page
Re: Formula >40 char with log()
Oh and documentation for the rules: https://espeasy.readthedocs.io/en/lates ... Rules.html
Re: Formula >40 char with log()
It is an ADS1115, and yes, some kind of filter would be nice there too.
So in my case I have a "Device ADS1115_CH0".
For the "Voltage" value I use the formula to calculate it as %value%*4.096/32768
I then add a Rule as follows (parenthesis was mising, you are right)
On ADS1115_CH0#Voltage do
let,1,(1/(log(%eventvalue1%/(32768-%eventvalue1%))/3988+0.003354)-278.4235)
endon
Can I now visualize this value somehow using a Dummy device?
So in my case I have a "Device ADS1115_CH0".
For the "Voltage" value I use the formula to calculate it as %value%*4.096/32768
I then add a Rule as follows (parenthesis was mising, you are right)
On ADS1115_CH0#Voltage do
let,1,(1/(log(%eventvalue1%/(32768-%eventvalue1%))/3988+0.003354)-278.4235)
endon
Can I now visualize this value somehow using a Dummy device?
Re: Formula >40 char with log()
This will put it in the Dummy Device called 'dummy', in the value named 'value'
Code: Select all
On ADS1115_CH0#Voltage do
taskvalueset,dummy,value,(1/(log(%eventvalue1%/(32768-%eventvalue1%))/3988+0.003354)-278.4235)
endon
/Ton (PayPal.me)
Re: Formula >40 char with log()
Thanks,
that works. The only Problem with that is that it fills up a slot and I am running out of them already
Can one have more than 12?
Btw. is this a bug in the rules parser? I need a parenthesis around the ln...
this returns a wrong value:
ln((10000*%eventvalue1%)/(3.3-%eventvalue1%)/10000)/3988
this returns the correct value:
(ln((10000*%eventvalue1%)/(3.3-%eventvalue1%)/10000))/3988
that works. The only Problem with that is that it fills up a slot and I am running out of them already
Can one have more than 12?
Btw. is this a bug in the rules parser? I need a parenthesis around the ln...
this returns a wrong value:
ln((10000*%eventvalue1%)/(3.3-%eventvalue1%)/10000)/3988
this returns the correct value:
(ln((10000*%eventvalue1%)/(3.3-%eventvalue1%)/10000))/3988
Re: Formula >40 char with log()
Not sure what has precedence, ln or /
So not sure if this actually is a bug.
So not sure if this actually is a bug.
Re: Formula >40 char with log()
When running ESPEasy on an ESP32, you have, besides more GPIO pins, memory and clock speed, 32 task .
You can also send it to an external destination, like MQTT or Domoticz, etc., using either the Publish command (MQTT) or SendToHTTP/PostToHTTP/PutToHTTP commands, details are in the Command reference documentation.
That depends where/how you use it. When in a Let command, or prefixed with = it should work without the extra parenthesis, when used in other statements or commands it sometimes needs some extra 'persuasion' to have the full calculated result, because of the order of processing functions and other calculations.
/Ton (PayPal.me)
Re: Formula >40 char with log()
Imho it should be out of question in that case.
ln(x)/y == (ln(x))/y
At least from a mathematicians view I think no one would expect the observed behaviour?
Yeah, but for economical reasons that is out of question
Thats how its gonna be used primarily. So yes, it is somewhat a luxury problem. I could in deed do the calculation on the target side as well, but I like to have a good abstraction, so all senders should provide their stuff in a SI standardized format. And I would like to be able to verify plausibility in the easeasy web interface as well.Ath wrote: ↑27 Apr 2023, 23:00 You can also send it to an external destination, like MQTT or Domoticz, etc., using either the Publish command (MQTT) or SendToHTTP/PostToHTTP/PutToHTTP commands, details are in the Command reference documentation.
p.s.If I would like to add a special function to the formula parser of the tasks to execute my formula in the source code, where would I have to look? Do you have a suggestion how that could look like?
Thanks for your support
Re: Formula >40 char with log()
I think we could make the formula boundaries a bit more flexible.
In recent changes, all access to the formulas is done via the cache struct, so fetching the formula from the settings only has to be changed in that cache object.
Regarding settings compatibility, the formula is a 2-dimensional array, thus we can also consider it to be 1 single array and still maintain compatibility with previous settings.
I have to look into it a bit more, to truly assess the impact of such a change.
In recent changes, all access to the formulas is done via the cache struct, so fetching the formula from the settings only has to be changed in that cache object.
Regarding settings compatibility, the formula is a 2-dimensional array, thus we can also consider it to be 1 single array and still maintain compatibility with previous settings.
I have to look into it a bit more, to truly assess the impact of such a change.
Re: Formula >40 char with log()
Most single-argument math functions are handled in method apply_unary_operator() in source Rules_calculate.cpp, you could have a look if your function could fit in there (though it may be a tad complicated to add a new function)
Alternative could be that you add a rule that handles the calculation, and would return the result in an internal var, that can be retrieved by [var#x] where x is the number matching with the 'let' command you used (let,10,..., used via [var#10]).
Code: Select all
on myCalculation do
let,10,%eventvalue1%*2 // result available in [var#10], [int#10] and %v10%
endon
// use as:
...
event,myCalculation=5.21 // Pass value 5.21 to your special calculation
// do something with [var#10]
...
/Ton (PayPal.me)
Who is online
Users browsing this forum: No registered users and 49 guests