Sensor Values calculating
Moderators: grovkillen, Stuntteam, TD-er
- Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
Sensor Values calculating
Hello all
I connected my LPG fuel tank sensor to my ESP32 in my Car.
I had already done this in my house control system with my local water tank at home, but now I have to do all the calculations inside of the car ESP.
First I have two values from the sensor at my ADS1115 connected and working with the ESP32:
Empty tank = 11760
Full tank = 25452
All other levels are in between these two values.
So I need to convert this into 0% till 100%
And if a value is higher or lower as the max and min value, the ESP should still show(display) and send (controller) only 0% or 100%
So no -4% or 107% Level as long my fuel tank is not physical change the shape
And IF my fuel tank is changing the shape, i have other problems then my sensor values
and since my fuel tank is a lot more shaking as my local water tank at home I need to avarage the sensor value.
My idea would be:
- getting sensor data every 10 seconds and store 10 of it it inside of the ESP32.
- Deleting the highest and the lowest value.
- summery all 8 values and divide it by 8.
send value to controller every 100 seconds and repeat procedure.
Or a continues solution, if you have a better solution in mind ?
So first question would be : Doable ?
second question: How ?
Thank you for your help and have a great day !
Sascha
I connected my LPG fuel tank sensor to my ESP32 in my Car.
I had already done this in my house control system with my local water tank at home, but now I have to do all the calculations inside of the car ESP.
First I have two values from the sensor at my ADS1115 connected and working with the ESP32:
Empty tank = 11760
Full tank = 25452
All other levels are in between these two values.
So I need to convert this into 0% till 100%
And if a value is higher or lower as the max and min value, the ESP should still show(display) and send (controller) only 0% or 100%
So no -4% or 107% Level as long my fuel tank is not physical change the shape
And IF my fuel tank is changing the shape, i have other problems then my sensor values
and since my fuel tank is a lot more shaking as my local water tank at home I need to avarage the sensor value.
My idea would be:
- getting sensor data every 10 seconds and store 10 of it it inside of the ESP32.
- Deleting the highest and the lowest value.
- summery all 8 values and divide it by 8.
send value to controller every 100 seconds and repeat procedure.
Or a continues solution, if you have a better solution in mind ?
So first question would be : Doable ?
second question: How ?
Thank you for your help and have a great day !
Sascha
"the flat earth society has members all around the globe"
Re: Sensor Values calculating
To constrain a computed value, see..... Constrain
To map the input to 0...100 output, you can compute it like this:
Empty tank = 11760
Full tank = 25452
Just assuming your task is called MyAnalogSensor with first value called val1.
This set of rules will store the last reading in variable 1 ([var#1])
You can do other computations like averaging in the rules too.
To map the input to 0...100 output, you can compute it like this:
Empty tank = 11760
Full tank = 25452
Code: Select all
on MyAnalogSensor#val1 do
let,1,(%eventvalue1% - 11760) / 136.92 // (25452-11760)/100
let,1,{constrain:[var#1]:0:100}
endon
This set of rules will store the last reading in variable 1 ([var#1])
You can do other computations like averaging in the rules too.
- Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
Re: Sensor Values calculating
great to point me to the constrain function
looks great
This is very useful when we work with raw sensor values.
In my house control system (about local water tank) i have the line:
But at the end of the line I have "times 100" instead of "divided by 100" ?
But so far I can tell it is working.
Was it a typo of you, or did I miss a thing here ?
"You can do other computations like averaging in the rules too."
is there a function for that as well, or do I have to do it by hand ?
So how could I store 10 values without using 10 variables ?
or is there a way to store it as an array and just add next value to it ?
and how to delete lowest and highest value before i do the avarage ?
my value for "empty tank" was just a guessing, so we have about 500 kilometers time before i need the calculation working wich is about in a week
so thank you already for the great informations
looks great
This is very useful when we work with raw sensor values.
In my house control system (about local water tank) i have the line:
Code: Select all
$percent=(GetValueInteger(59082)-$empty)/($full-$empty)*100; // convert to percent (0-100%)
But so far I can tell it is working.
Was it a typo of you, or did I miss a thing here ?
"You can do other computations like averaging in the rules too."
is there a function for that as well, or do I have to do it by hand ?
So how could I store 10 values without using 10 variables ?
or is there a way to store it as an array and just add next value to it ?
and how to delete lowest and highest value before i do the avarage ?
my value for "empty tank" was just a guessing, so we have about 500 kilometers time before i need the calculation working wich is about in a week
so thank you already for the great informations
"the flat earth society has members all around the globe"
Re: Sensor Values calculating
I just wrote it while waiting for a compile to finish, so it might be possible I messed up.
But I don't think so, as I precomputed it so you can read it as if it were in braces.
(A) / (B) * C == (A) / ((B) / C)
At least I think so
But I don't think so, as I precomputed it so you can read it as if it were in braces.
(A) / (B) * C == (A) / ((B) / C)
At least I think so
Re: Sensor Values calculating
Oh and we don't (yet) have an averaging function.
However you could add the new value to the same variable and incrementing a next variable.
In the end, after some time or if count > N, you just divide both (make sure the count isn't 0) and reset the total and the count.
However you could add the new value to the same variable and incrementing a next variable.
In the end, after some time or if count > N, you just divide both (make sure the count isn't 0) and reset the total and the count.
- Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
Re: Sensor Values calculating
Hello
right now i did try to set my rule like:
var#6 always shows "0" as result
But this:
and this:
works fine
But when i start to calculate like:
or
var#6 shows always "0"
So i could need a little help with syntax here
i use normal build at a 8266 latest 27.April.22
Thank you for your help
right now i did try to set my rule like:
Code: Select all
on LPGLevel#LPG do
let,6,(%eventvalue1% - 952) / 244.83 // (25435-952)/100
let,6,{constrain:[var#6]:0:100}
endon
But this:
Code: Select all
on LPGLevel#LPG do
let,6,%eventvalue1%
endon
Code: Select all
on LPGLevel#LPG do
let,6,(%eventvalue1%)
endon
But when i start to calculate like:
Code: Select all
on LPGLevel#LPG do
let,6,%eventvalue1% - 952
endon
Code: Select all
on LPGLevel#LPG do
let,6,(%eventvalue1% - 952)
endon
So i could need a little help with syntax here
i use normal build at a 8266 latest 27.April.22
Thank you for your help
"the flat earth society has members all around the globe"
Re: Sensor Values calculating
Adding an = might sometimes also help to let the rules parser know it needs to call the calculate function.
e.g. let,6,=%eventvalue1%-952
But first, let's make sure we know what the eventvalue is.
(added underscores to wrap the eventvalue, to see if there are spaces too)
By the way, do you have multiple entries for LPGLevel#LPG in your rules?
If so, then you might want to disable the reordering of rules blocks (Tools->Advanced page at the top)
Edit:
One more idea... try to remove the spaces around the - sign in the let line.
e.g. let,6,=%eventvalue1%-952
But first, let's make sure we know what the eventvalue is.
Code: Select all
on LPGLevel#LPG do
let,6,%eventvalue1% - 952
LogEntry,'Eventvalue: _%eventvalue1%_ Var6: [var#6]'
endon
By the way, do you have multiple entries for LPGLevel#LPG in your rules?
If so, then you might want to disable the reordering of rules blocks (Tools->Advanced page at the top)
Edit:
One more idea... try to remove the spaces around the - sign in the let line.
- Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
Re: Sensor Values calculating
YAY
this is how it works perfect now !
so i removed all spaces in between
I bought you some coffee right now but i can´t afford a coffee always i make a mistake. Simply because i make too much mistakes lol
What do you think about a avarage function ? woulden´t that be cool ?
best result i had always with continius reading values and always deleting highest and lowest value of 10 entrys and then doing the avarage calculating. Because if you have bad sensors or too long cables there are always miss values like -250 degree in sommer at my pool or something like this if you have very bad sensors you might be deleting 2 highest and 2 lowest values. So maybe the function would be cool to set how many highest and lowest you want to delete. If you use good sensors in good conditions the answer could be "0"
But thank you again for solving my problems with the calculations syntax in rules
Have a great day !
Sascha
this is how it works perfect now !
Code: Select all
on LPGLevel#LPG do
let,6,(%eventvalue%-952)/244.83
let,6,{constrain:[var#6]:0:100}
endon
I bought you some coffee right now but i can´t afford a coffee always i make a mistake. Simply because i make too much mistakes lol
What do you think about a avarage function ? woulden´t that be cool ?
best result i had always with continius reading values and always deleting highest and lowest value of 10 entrys and then doing the avarage calculating. Because if you have bad sensors or too long cables there are always miss values like -250 degree in sommer at my pool or something like this if you have very bad sensors you might be deleting 2 highest and 2 lowest values. So maybe the function would be cool to set how many highest and lowest you want to delete. If you use good sensors in good conditions the answer could be "0"
But thank you again for solving my problems with the calculations syntax in rules
Have a great day !
Sascha
"the flat earth society has members all around the globe"
Re: Sensor Values calculating
I am preparing to work on a function like that.
This in the form of some processing of ADC data.
Later this will be split into some object you can read from and write to in rules (and tasks)
This in the form of some processing of ADC data.
Later this will be split into some object you can read from and write to in rules (and tasks)
- Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
Re: Sensor Values calculating
YAY Sounds great ^^
"the flat earth society has members all around the globe"
Who is online
Users browsing this forum: No registered users and 6 guests