Trying to detect specific out of hours events

Kevin Hartin2 months ago

I have a situation where I need to detect a ignitionOn event between 6pm and 6am and subsequently send an email.

I can do this fairly easily with a php script that runs via a cron job, but was wondering if it can be done inside traccar server using Computed Attributes and Notifications.

Anton Tananaev2 months ago

You can create an alarm if you see ignition value between those hours using computed attributes.

Kevin Hartin2 months ago

Is there any code samples

Anton Tananaev2 months ago

There are some examples in the documentation, but obviously not exactly this thing.

Andres2 months ago

Hi @kevinhartin, did you manage to create the calculated attribute with hours?

Adriano Miranda2 months ago

Hello guys,

Just wanted to share a possible solution. I’m using a Teltonika device, which sends event == 239 when the ignition is turned on. Here’s the computed attribute expression I tested:

event && event == 239 && (fixTime.getHours() >= 18 || fixTime.getHours() < 6) ? 'powerOn' : null

You can then create your notification based on the "powerOn" alarm.

Let me know if this helps! :)