July 05, 2023

Teltonika router as security, burglar, alarm !

The use case was that we on our yacht have a security alarm which is using 2 G, service terminating during 2024 ?, so it was time to check for some other solution. 

Since several years we have used the very nice Teltonika RUT 240(TR) onboard which have served us very well. Knowing that this device have both a digital in and out I started to check if it could do the job ?? 

Googling didn't give any direct clues but the "Input/Output" handling together with "Profiles" changed with a SMS, "Mobile Utilities", is doing the job.

Please note that this setup could be done with any of the routers from Teltonika with I/O !!

Intro
Not familiar with the Teltonika router ? Here is a post how to start up.

This setup is referring to FW 7.04.3

Please note !! For test purposes all SMS rules are set to;
    Authorization metod =>  "No authorisation" 
Change this when you go into production !!

We have several sources for alarms on our yacht
  • Door sensors
  • Bilge water level sensor 
  • PIR motion sensors
and to make this post simple we assume that they all are having dry contacts, are normally closed and are connected in series. The "chain" of contacts are in one end connected to 12 V DC and the other end is connected to the TR:s digital input. Check out circuit diagram below.

If an alarm is triggered, one of the alarm sources is opening it contacts, the 12 VDC will be interrupted and the TR input will go to zero. This will trigger 3 events
  • The outdoor siren will turn on via the TR digital output
  • SMS:s will be sent
  • E-mail will be sent
Setup
Hardware
The best way to connect to the TR In/Out terminals is this accessory.

Profiles
TR profiles are a way to have multiple configuration sets available and then choosing the appropriate one depending on your use case. We will switch between the "default", regular operation, and the "alarm" one. The "alarm" profile will be setup to handle the alarms when we are away from the yacht.

At "System => Profiles" copy the "default" profile creating the "alarm" one. In the list click on "APPLY",  for the "alarm" profile, which will apply that configuration.

Input/Output
Setup the I/O Juggler 

Start with creating actions "Services => Input/Output => Actions".
    => For the SMS alert, add "Name" => "Alarm_SMS" and "Type" => SMS" and then fill in whats             appropriate for your use case.
    => Repeat and add with "Name" => "Alarm_Siren" and "Type" => Output"
            Revert "120", this will turn the siren of after 120 seconds
            Maintain "off", will not maintain the I/O state after reboot
            State "High"

Then at "Services => Input/Output => General"
    Enable "ON"
    => SAVE & APPLY

    => ADD NEW INSTANCE =>
            ROLE "Input (3)" => Add
                Trigger "Falling"
                Add actions "Alarm_SMS" "Alarm_Siren"
                Enabled "on"
                => SAVE & APPLY

Activate the alarm
Via, "Services => Mobile utilities => SMS Utilities" 
    => change action "Change Profile" to "No authorization".

Send the SMS "pr alarm" to activate the "alarm" profile and "pr default" to deactivate it and turn back to the "default" one.
(Please note that the manual is using another command)

Tuning
Stop siren
To force the siren to stop, output low, create a new SMS rule. "Services => Mobile utilities => SMS Utilities => Add rule"
    SMS Text  "Alarm_Siren_Off"
    Action "Change I/O state"
    => ADD
            => GENERAL
                    Enable "on"
                    State "low"
            => AUTHORIZATION 
                    Authorization metod "No authorisation"
            => SAVE & APPLY

Shortcuts
If you are using Apple devices, also check "Another way ... below,  you can create "Shortcuts", Shortcut app, to do the alarm handling a little nicer. Check the picture to the right where I turn the alarm off.

The 20 seconds delay is used giving the TR time to swap to the new profile.

The extra logic, "Alarm_Siren_Off", is due to that the siren is activated for 2 minutes and if the alarm is turned off before that, the siren will never go off. 

Get active profile
To really confirm that the TR is in the right mode, alarm or not, you could retrieve the actual profile.

1/The last SMS, shown in the shortcut, is using action "UCI API", with command

uci show profiles.general.profile

which confirms which profile is active. UCI command usage. The response will be 

profiles.general.profile=default

2/You could also get the actual profile using a SMS with action "Execute custom script" using a shell command 

echo -n "Active profile => " && uci show profiles.general.profile | cut -c 26-40

which will give the response 

Active profile => 'alarm'
Status code: 0       

Another way...
Instead of sending several SMS you could use a more complex SMS action with "Execute custom script" which you call "Alarm_ON", added for profile "default",

#!/bin/sh
# Set alarm profile
uci set profiles.general.profile=alarm
uci commit profiles
/etc/init.d/profiler restart
# Restart I/O juggler
/etc/init.d/iojuggler restart
# Send active profile in response SMS
echo -n "Profile is => " && uci show profiles.general.profile | cut -c 26-40

and "Alarm_OFF", added for profile "alarm", 

#!/bin/sh
# Set default profile
uci set profiles.general.profile=default
uci commit profiles
/etc/init.d/profiler restart
#Set siren OFF
uci set ioman.dout1.value=0
uci commit ioman
/etc/init.d/ioman restart
# Send active profile in response SMS
echo -n "Profile is => " && uci show profiles.general.profile | cut -c 26-40

Lower the power consumption
Turning off some, not needed, functions will lower the power consumption when using the "alarm" profile.
  • Mobildata    "Network => Interfaces", click "off" and "SAVE & APPLY"
  • WiFi            "Network => Wireless", click "off" and "SAVE & APPLY"
Circuit diagram


Please note that the output is open collector and maximized to 0,3 Amps DC ! With a bigger load use a relay or something similar as buffer.

Additional reading
How to connect a relay to a RUT 240 digital output.
Nice information for RUT 955 Input/Output but in many ways also applicable for other devices in RUT-series.

No comments:

Post a Comment

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !