The problem is not with the formula. The problem is that you have not selected the attribute.
In third formula i selected Attribute Fuel from drop down menu, like in another devices.
And connected to device this computed attribute.
If i chadged this formula from
math:round((io2201 + io2203)/2)
tomath:round((io201 + io203)/2)
Fuel parametr appears!
I only change virtual sensors to hardware.
In both cases, the TEST button works. But the fuel parameter appears only if there is a hardware sensor in the formula.
With virtual sensors fuel parameter does not appear.
Have you waited for new data? Have you checked logs for errors?
In the logs I found an error regarding this attribute and device
2023-03-03 17:27:51 WARN: Attribute computation error - org.traccar.handler.ComputedAttributesHandler.computeAttribute:105@1:13 variable 'io2201' is undefined - Variable (ComputedAttributesHandler:105 < *:115 < BaseDataHandler:27 < ... < *:29 < ... < *:29 < ... < *:29 < ... < GeocoderHandler:81 < ...)
But TEST button show correct value. Maybe try copy attributes?
Have you read our computed attributes documentation? Specifically I'm referring to this part:
The order in which computed attributes are applied to the device is not defined. It is therefore not recommended to use the result of one computed attribute in another computed attribute.
But how can i use huge formula more then 4096 symbols?
This formula works fine with TEST button. But a cant save it.
math:round(((
io201 < 2027 ? 0:
(io201 >= 2027 && io201 <2061)? io201 = ( 0.588235294 * io201) + -1192.352941:
(io201 >= 2061 && io201 <2093)? io201 = ( 0.625 * io201) + -1268.125:
(io201 >= 2093 && io201 <2122)? io201 = ( 0.689655172 * io201) + -1403.448276:
(io201 >= 2122 && io201 <2151)? io201 = ( 0.689655172 * io201) + -1403.448276:
(io201 >= 2151 && io201 <2179)? io201 = ( 0.714285714 * io201) + -1456.428571:
(io201 >= 2179 && io201 <2208)? io201 = ( 0.689655172 * io201) + -1402.758621:
(io201 >= 2208 && io201 <2235)? io201 = ( 0.740740741 * io201) + -1515.555556:
(io201 >= 2235 && io201 <2262)? io201 = ( 0.740740741 * io201) + -1515.555556:
(io201 >= 2262 && io201 <2281)? io201 = ( 1.052631579 * io201) + -2221.052632:
(io201 >= 2281 && io201 <2316)? io201 = ( 0.571428571 * io201) + -1123.428571:
(io201 >= 2316 && io201 <2342)? io201 = ( 0.769230769 * io201) + -1581.538462:
(io201 >= 2342 && io201 <2367)? io201 = ( 0.8 * io201) + -1653.6:
(io201 >= 2367 && io201 <2393)? io201 = ( 0.769230769 * io201) + -1580.769231:
(io201 >= 2393 && io201 <2418)? io201 = ( 0.8 * io201) + -1654.4:
(io201 >= 2418 && io201 <2442)? io201 = ( 0.833333333 * io201) + -1735:
(io201 >= 2442 && io201 <2466)? io201 = ( 0.833333333 * io201) + -1735:
(io201 >= 2466 && io201 <2489)? io201 = ( 0.869565217 * io201) + -1824.347826:
(io201 >= 2489 && io201 <2514)? io201 = ( 0.8 * io201) + -1651.2:
(io201 >= 2514 && io201 <2539)? io201 = ( 0.8 * io201) + -1651.2:
(io201 >= 2539 && io201 <2564)? io201 = ( 0.8 * io201) + -1651.2:
(io201 >= 2564 && io201 <2589)? io201 = ( 0.8 * io201) + -1651.2:
(io201 >= 2589 && io201 <2613)? io201 = ( 0.833333333 * io201) + -1737.5:
(io201 >= 2613 && io201 <2640)? io201 = ( 0.740740741 * io201) + -1495.555556:
(io201 >= 2640 && io201 <2665)? io201 = ( 0.8 * io201) + -1652:
(io201 >= 2665 && io201 <2689)? io201 = ( 0.833333333 * io201) + -1740.833333:
(io201 >= 2689 && io201 <2714)? io201 = ( 0.8 * io201) + -1651.2:
(io201 >= 2714 && io201 <2738)? io201 = ( 0.833333333 * io201) + -1741.666667:
(io201 >= 2738 && io201 <2763)? io201 = ( 0.8 * io201) + -1650.4:
(io201 >= 2763 && io201 <2787)? io201 = ( 0.833333333 * io201) + -1742.5:
(io201 >= 2787 && io201 <2813)? io201 = ( 0.769230769 * io201) + -1563.846154:
(io201 >= 2813 && io201 <2837)? io201 = ( 0.833333333 * io201) + -1744.166667:
(io201 >= 2837 && io201 <2861)? io201 = ( 0.833333333 * io201) + -1744.166667:
(io201 >= 2861 && io201 <2885)? io201 = ( 0.833333333 * io201) + -1744.166667:
(io201 >= 2885 && io201 <2909)? io201 = ( 0.833333333 * io201) + -1744.166667:
(io201 >= 2909 && io201 <2935)? io201 = ( 0.769230769 * io201) + -1557.692308:
(io201 >= 2935 && io201 <2959)? io201 = ( 0.833333333 * io201) + -1745.833333:
(io201 >= 2959 && io201 <2982)? io201 = ( 0.869565217 * io201) + -1853.043478:
(io201 >= 2982 && io201 <3007)? io201 = ( 0.8 * io201) + -1645.6:
(io201 >= 3007 && io201 <3031)? io201 = ( 0.833333333 * io201) + -1745.833333:
(io201 >= 3031 && io201 <3055)? io201 = ( 0.833333333 * io201) + -1745.833333:
(io201 >= 3055 && io201 <3080)? io201 = ( 0.8 * io201) + -1644:
(io201 >= 3080 && io201 <3106)? io201 = ( 0.769230769 * io201) + -1549.230769:
(io201 >= 3106 && io201 <3132)? io201 = ( 0.769230769 * io201) + -1549.230769:
(io201 >= 3132 && io201 <3158)? io201 = ( 0.769230769 * io201) + -1549.230769:
(io201 >= 3158 && io201 <3186)? io201 = ( 0.714285714 * io201) + -1375.714286:
(io201 >= 3186 && io201 <3216)? io201 = ( 0.666666667 * io201) + -1224:
io201 > 3216 ? 940:0)
+(io203 < 2030 ? 0:
(io203 >= 2030 && io203 <2063)? io203 = ( 0.606060606 * io203) + -1230.30303:
(io203 >= 2063 && io203 <2094)? io203 = ( 0.64516129 * io203) + -1310.967742:
(io203 >= 2094 && io203 <2124)? io203 = ( 0.666666667 * io203) + -1356:
(io203 >= 2124 && io203 <2153)? io203 = ( 0.689655172 * io203) + -1404.827586:
(io203 >= 2153 && io203 <2181)? io203 = ( 0.714285714 * io203) + -1457.857143:
(io203 >= 2181 && io203 <2209)? io203 = ( 0.714285714 * io203) + -1457.857143:
(io203 >= 2209 && io203 <2236)? io203 = ( 0.740740741 * io203) + -1516.296296:
(io203 >= 2236 && io203 <2264)? io203 = ( 0.714285714 * io203) + -1457.142857:
(io203 >= 2264 && io203 <2291)? io203 = ( 0.740740741 * io203) + -1517.037037:
(io203 >= 2291 && io203 <2318)? io203 = ( 0.740740741 * io203) + -1517.037037:
(io203 >= 2318 && io203 <2345)? io203 = ( 0.740740741 * io203) + -1517.037037:
(io203 >= 2345 && io203 <2371)? io203 = ( 0.769230769 * io203) + -1583.846154:
(io203 >= 2371 && io203 <2396)? io203 = ( 0.8 * io203) + -1656.8:
(io203 >= 2396 && io203 <2421)? io203 = ( 0.8 * io203) + -1656.8:
(io203 >= 2421 && io203 <2446)? io203 = ( 0.8 * io203) + -1656.8:
(io203 >= 2446 && io203 <2471)? io203 = ( 0.8 * io203) + -1656.8:
(io203 >= 2471 && io203 <2494)? io203 = ( 0.869565217 * io203) + -1828.695652:
(io203 >= 2494 && io203 <2516)? io203 = ( 0.909090909 * io203) + -1927.272727:
(io203 >= 2516 && io203 <2542)? io203 = ( 0.769230769 * io203) + -1575.384615:
(io203 >= 2542 && io203 <2567)? io203 = ( 0.8 * io203) + -1653.6:
(io203 >= 2567 && io203 <2592)? io203 = ( 0.8 * io203) + -1653.6:
(io203 >= 2592 && io203 <2616)? io203 = ( 0.833333333 * io203) + -1740:
(io203 >= 2616 && io203 <2638)? io203 = ( 0.909090909 * io203) + -1938.181818:
(io203 >= 2638 && io203 <2662)? io203 = ( 0.833333333 * io203) + -1738.333333:
(io203 >= 2662 && io203 <2687)? io203 = ( 0.8 * io203) + -1649.6:
(io203 >= 2687 && io203 <2711)? io203 = ( 0.833333333 * io203) + -1739.166667:
(io203 >= 2711 && io203 <2735)? io203 = ( 0.833333333 * io203) + -1739.166667:
(io203 >= 2735 && io203 <2769)? io203 = ( 0.588235294 * io203) + -1068.823529:
(io203 >= 2769 && io203 <2783)? io203 = ( 1.428571429 * io203) + -3395.714286:
(io203 >= 2783 && io203 <2808)? io203 = ( 0.8 * io203) + -1646.4:
(io203 >= 2808 && io203 <2832)? io203 = ( 0.833333333 * io203) + -1740:
(io203 >= 2832 && io203 <2857)? io203 = ( 0.8 * io203) + -1645.6:
(io203 >= 2857 && io203 <2881)? io203 = ( 0.833333333 * io203) + -1740.833333:
(io203 >= 2881 && io203 <2905)? io203 = ( 0.833333333 * io203) + -1740.833333:
(io203 >= 2905 && io203 <2930)? io203 = ( 0.8 * io203) + -1644:
(io203 >= 2930 && io203 <2956)? io203 = ( 0.769230769 * io203) + -1553.846154:
(io203 >= 2956 && io203 <2978)? io203 = ( 0.909090909 * io203) + -1967.272727:
(io203 >= 2978 && io203 <3003)? io203 = ( 0.8 * io203) + -1642.4:
(io203 >= 3003 && io203 <3028)? io203 = ( 0.8 * io203) + -1642.4:
(io203 >= 3028 && io203 <3054)? io203 = ( 0.769230769 * io203) + -1549.230769:
(io203 >= 3054 && io203 <3079)? io203 = ( 0.8 * io203) + -1643.2:
(io203 >= 3079 && io203 <3105)? io203 = ( 0.769230769 * io203) + -1548.461538:
(io203 >= 3105 && io203 <3132)? io203 = ( 0.740740741 * io203) + -1460:
(io203 >= 3132 && io203 <3159)? io203 = ( 0.740740741 * io203) + -1460:
(io203 >= 3159 && io203 <3188)? io203 = ( 0.689655172 * io203) + -1298.62069:
(io203 >= 3188 && io203 <3218)? io203 = ( 0.666666667 * io203) + -1225.333333:
io203 >= 3218 ? 940:0))/2)
Increase the column size in the database.
Anton, thank you very much! Š•verything works great!
Hi,
I am using FMB920 with fuel sensor
1 > 0 liters
28 = 24 liters
68 = 34 liters
114 = 44 liters
158 = 54 liters
203 = 64 liters
I also increase the size of expression under tc_attributes table using following command.
ALTER TABLE tc_attributes MODIFY expression VARCHAR(10000) NOT NULL
io270 < 28 ? 0:
(io270 >= 1 && io270 < 28 )? io270 = (0.888888888888889 * io270) + -0.888888888888886:
(io270 >= 28 && io270 < 68 )? io270 = (0.25 * io270) + 17:
(io270 >= 68 && io270 < 114 )? io270 = (0.217391304347826 * io270) + 19.2173913043478:
(io270 >= 114 && io270 < 158 )? io270 = (0.227272727272727 * io270) + 18.0909090909091:
(io270 >= 158 && io270 < 203 )? io270 = (0.222222222222222 * io270) + 18.8888888888889:
(io270 >= 203 && io270 < 247 )? io270 = (0.227272727272727 * io270) + 17.8636363636364:
Still getting following error,
org.traccar.handler.ComputedAttributesHandler.computeAttribute:142@9:88 parsing error in ':' - Parsing (ComputedAttributesHandler:142 < AttributeResource:63 < ... < OverrideFilter:49 < ...)
I don't think it's a valid expression. You should remove the io270 =
assignment.
I followed what Victor Kyryllov used,
io270 < 28 ? 0:
(io270 >= 1 && io270 < 28 )? (0.888888888888889 * io270) + -0.888888888888886:
(io270 >= 28 && io270 < 68 )? (0.25 * io270) + 17:
(io270 >= 68 && io270 < 114 )? (0.217391304347826 * io270) + 19.2173913043478:
(io270 >= 114 && io270 < 158 )? (0.227272727272727 * io270) + 18.0909090909091:
(io270 >= 158 && io270 < 203 )? (0.222222222222222 * io270) + 18.8888888888889:
(io270 >= 203 && io270 < 247 )? (0.227272727272727 * io270) + 17.8636363636364:
AND Also,
math:round(io270 < 28 ? 0:
(io270 >= 1 && io270 < 28 )? (0.888888888888889 * io270) + -0.888888888888886:
(io270 >= 28 && io270 < 68 )? (0.25 * io270) + 17:
(io270 >= 68 && io270 < 114 )? (0.217391304347826 * io270) + 19.2173913043478:
(io270 >= 114 && io270 < 158 )? (0.227272727272727 * io270) + 18.0909090909091:
(io270 >= 158 && io270 < 203 )? (0.222222222222222 * io270) + 18.8888888888889:
(io270 >= 203 && io270 < 247 )? (0.227272727272727 * io270) + 17.8636363636364:)
Still showing the following when I click on "Test Expression"
org.traccar.handler.ComputedAttributesHandler.computeAttribute:142@7:80 parsing error in ':' - Parsing (ComputedAttributesHandler:142 < AttributeResource:63 < ... < OverrideFilter:49 < ...)
The error is telling you that the expression is invalid. Why do you have a colon at the end of the expression?
I tried even the following simple expression
io270 < 1 ? 0
io270 >= 1 && io270 < 28 ? 0.888888888888889 * io270 - 0.888888888888886
still got
org.traccar.handler.ComputedAttributesHandler.computeAttribute:142@2:1 parsing error in 'io270' - Parsing (ComputedAttributesHandler:142 < AttributeResource:63 < ... < OverrideFilter:49 < ...)
You should read the syntax documentation before we continue this conversation. What you have in the last example is a complete nonsense.
Hello,
I have some problems with fuel calculation and formula size
I have truck with 940 liters fuel tank and two fuel sensors with a calibration table for every sensor.
Like this:
I wrote a formula to calculate intermediate values and it works fine!
Formula like this:
total fuel value is calculated like
(sensor1 + sensor2) / 2
and it works too! But only with TEST button. When i try to save formula - i have an errorTotal formula size is 7068 lenth and 97 lines and it works only with TEST button.
Then i tried to separate formula for every sensor and then calculate it with third formula.
io201 - hardware sensor 1
io203 - hardware sensor 2
I created computed attributes that calculate io201 to io2201 in liters (and io203 to io 2203 too).
I connected the virtual sensors with the device.
Then i have two virtual computed attributes (io2201 and io2203) in liters that displayed in device sensors list.
Finally I tried to calculate FUEL with third formula
math:round((io2201 + io2203)/2)
and it works with TEST Button! But does not save fuel in the list of device sensors.P.S. Of course, I connected the third formula to the device
What am I doing wrong?
Why does the TEST button works but does not save the Fuel data?