Notification -> Event wrong position id in tc_events

Nikolay 2 years ago

Hello again,

I have a question regarding the launch of a notification.

After updating to version 5.4, I noticed something I don't know if I should expect.

The trigger that raises an alarm is io11 < io21 (-66.6 < -60.00)

As can be seen in the tables below.

position.id --> 830 has a value of io11 --> -66.6
events.id --> 93 has a value for positionid --> 844
position.id --> 844 has a value of io11 --> -53.3
position.id --> 846 has value of io11 --> -66.6
No events triggering until next position?!?

The new position value arrives in the email notification

Here is the data:

Table tc_positions:
id protocol deviceid servertime devicetime fixtime valid latitude longitude altitude speed course address attributes accuracy network
846 osmand 30 2022-11-11 14:29:15.865000 2022-11-11 14:29:15.000000 2022-11-11 14:29:15.000000 true 47.644 28.4132 0 0 NULL {"course":0.0, "sat":8.0, "io11":-66.6, "io12":-50.1, "io13":-48. 7,"io14":-49.303,"io15":-50.1,"io16":-47.7,"io17":-48.927,"io21":-60.0,"io22":-40.0,"io23":5.0,"io24":5. 0, "io25":900.0, "distance":677371.98, "totalDistance":8805835.74, "motion":false, "tempCalculated":-66.6} 0 null
844 osmand 30 2022-11-11 14:26:54.007000 2022-11-11 14:26:54.000000 2022-11-11 14:26:54.000000 true 42. 723293 23.327505 0 0 NULL {"course":0.0, "sat":8.0, "io11":-53.3, "io12":-66.6, "io13":-52.2, "io14":-54.667, "io21":-60. 0,"io22":-40.0,"io23":5.0,"io24":5.0,"io25":900.0,"distance":677371.98,"totalDistance":8128463.76,"motion":false,"io15":-50. 1, "io16":-47.7, "io17":-48.927, "tempCalculated":-56.3, "isLowTemp":true, "isHiTemp":false, "alarm": "temperature"} 0 null
830 osmand 30 2022-11-11 14:26:18.475000 2022-11-11 14:26:18.000000 2022-11-11 14:26:18.000000 true 47.644 28.4132 0 0 NULL {"course":0.0, "sat":8.0, "io11":-66.6, "io12":-50.1, "io13":-48.7, "io14":-49. 303,"io15":-50.1,"io16":-47.7,"io17":-48.927,"io21":-60.0,"io22":-40.0,"io23":5.0,"io24":5.0,"io25":900.0,"distance":677371. 98, "totalDistance":7451091.78, "motion":false, "tempCalculated":-66.6, "isLowTemp":false, "isHiTemp":false} 0 null
table tc_events
id type eventtime deviceid positionid geofenceid attributes maintenanceid
93 alarm 2022-11-11 14:26:54.000000 30 844 NULL {"alarm": "temperature"} NULL
Anton Tananaev2 years ago

I see that position 844 has the "alarm": "temperature", so it doesn't seem to be an event issue. Are you using computed attributes for it? Are you sure the formula is correct?

Nikolay 2 years ago

Hi Anton,

Yes, I use computedAttribute for this purpose.

Triggers
id description type attribute expression
16 CA Low Temperature boolean isLowTemp tempCalculated ? tempCalculated < io21 ? true : false : null
17 CA Hi Temperature boolean isHiTemp tempCalculated ? tempCalculated > io22 ? true : false : null
Alarms
id description type attribute expression
18 Alarm Hi Temp string alarm isHiTemp ? 'temperature' : null
19 Alarm Low Temp string alarm isLowTemp ? 'temperature' : null
Calculated Attributes for each device
id description type attribute expression
1 temp R_A.TC-07 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -40.9) ? io11 - 1 : ((io11 <= -41.00) && (io11 >= -46.9)) ? io11 - 2 : ((io11 <= -47.00) && (io11 >= -65.9) ? io11 - 3 : io11 : null
2 Temp R_B.TC-00 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -65.9)) ? io11 - 4 : io11: null
3 Temp R_B.TC-01 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -65.9)) ? io11 - 3 : io11: null
4 Temp R_B.TC-02 number tempCalculated io11 ? (io11 <=200.00) && (io11 >= -100)) ? io11 - 4 : io11 : null
5 temp R_B.TC-03 number tempCalculated io11 ? (io11 <=200.00) && (io11 >= -100)) ? io11 - 3 : io11 : null
6 Temp R_B.TC-04 number tempCalculated io11 ? (io11 <=200.00) && (io11 >= -100)) ? io11 - 3 : io11 : null
8 Temp R_B.TC-00 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -40.9) ? io11 - 1 : ((io11 <= -41.00) && (io11 >= -65.9)) ? io11 - 2 : io11 : null
9 Temp R_A.TC-00 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -40.9)) ? io11 - 5 : ((io11 <= -41.00) && (io11 >= -65.9)) ? io11 - 6 : io11 : null
10 Temp R_A.TC-01 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -40.9)) ? io11 - 1 : ((io11 <= -41.00) && (io11 >= -46.9)) ? io11 - 2 : ((io11 <= -47.00) && (io11 >= -53.9) ? io11 - 3 : ((io11 <= -54.00) && (io11 >= -59.9) ? io11 - 4 : ((io11 <= -60.00) && (io11 >= -65.9) ? io11 - 5 : io11 : null
11 Temp R_A.TC-02 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -46.9)) ? io11 - 1 : ((io11 <= -47.00) && (io11 >= -65.9)) ? io11 - 2 : io11 : null
12 temp R_A.TC-03 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -46.9) ? io11 - 4 : ((io11 <= -47.00) && (io11 >= -65.9)) ? io11 - 5 : io11 : null
13 Temp R_A.TC-04 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -56.9)) ? io11 - 6 : ((io11 <= -57.00) && (io11 >= -65.9)) ? io11 - 7 : io11 : null
14 Temp R_A.TC-05 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -46.9) ? io11 - 4 : ((io11 <= -47.00) && (io11 >= -65.9)) ? io11 - 5 : io11 : null
15 Temp R_A.TC-06 number tempCalculated io11 ? (io11 <= -30.00) && (io11 >= -56.9)) ? io11 - 6 : ((io11 <= -57.00) && (io11 >= -65.9)) ? io11 - 7 : io11 : null

For each device I have made a link for the corresponding calculation

tc_device_attribute
deviceid attributeid
30 10
30 16
30 17
30 18
30 19
Anton Tananaev2 years ago

Wait. You have multiple computed attributes that depend on each other? How does that work?

Nikolay 2 years ago

;)

Well, it works as I described it. Not very well ;)

Each device generates an alarm, but the notification arrives with the next item and the notification contains the attributes of the new position.

Give me some hint, my idea is that the measured temperature needs recalculation. And this recalculation is different for each device.

Anton Tananaev2 years ago

Do you have attribute copying?

Nikolay 2 years ago

Yes, I have for groups

id name groupid attributes
2 test-group NULL {"processing.copyAttributes": "io11,io12,io13,io14,io15,io16,io17,io18,io21,io22,io23,io24,io25,tempCalculated"}

As in the configuration

    <entry key='processing.copyAttributes.enable'>true</entry>
    <entry key="processing.copyAttributes">io11,io12,io13,io14,io15,io16,io17,io18,io21,io22,io23,io24,io25</entry>
    <entry key='processing.computedAttributes.enable'>true</entry>
    <entry key='processing.computedAttributes.deviceAttributes.enable'>true</entry>
Anton Tananaev2 years ago

Most likely copying tempCalculated is causing this issue. You should not have multiple computed attributes depending on each other. They can be executed in a random order, so it's very unreliable setup. Combine all the logic into one attribute.

Nikolay 2 years ago

Hello everyone,

just to confirm:

I removed all dependencies, triggers, alarms.

I used one attribute, different for each device in which I added all the alarm logic.

R_A.TC-00 Alarm Temperature
alarm
io11 ? (io11 <= -30.00) && (io11 >= -40.9) ? (io11 - 5) < io21 ? 'temperature' : (io11 - 5) > io22 ? 'temperature' : null : ((io11 <= -41.00) && (io11 >= -65.9)) ? (io11 - 6) < io21 ? 'temperature' : (io11 - 6) > io22 ? 'temperature' : null : io11 < 21 || io11 > io22 ? 'temperature' : null : null

I left tempCalculated as a separate attribute that I use for the templates.

Now I think everything works as expected.