Teltonika (OpenWRT / RutOS) custom GSM modem modbus

p.s: I assume you’ve seen this link? There is a table halfway down the page which shows all the sent / received data already reported in the default modbus.

https://wiki.teltonika-networks.com/view/Monitoring_via_Modbus

Perhaps ignore my previous reply and I reckon we just need to figure out how to interpret the bl**dy modbus data into something Home Assistant can understand :rofl:

root@Teltonika-RUTX11:~# gsmctl -CA 'AT+QCAINFO' -o --
modemtime 2
48xxxxxx
OK
Willkommen
23/05/20,23:01:33

Maybe this is because my Teltonika router is currently connected to my home WiFi (yet another router) and thus the mobile connection is “sleeping”?

I have no other scripts running. When I rename the file, I can save the settings.

PS:
I removed extramodus & from the custom script (just left exit 0), rebooted, then first went to modbus slave settings - which I could now save without error - then entered the file path there, then the master settings, and rebooted again. So saving works (maybe because I now first saved the settings and only afterwards had the script running), but I need to check why the message is too short.

the data sent and received I have actually. But I like to see my traffic real time as well which is Kbit/s (up and down). That I haven’t figured out yet…
This is what I have now:

And this is what I like to add to it:
Screenshot 2023-05-20 at 19.51.12

Cheers

Maybe this is because my Teltonika router is currently connected to my home WiFi

100% yes – the gsmctl command only returns info from the SIM card modem. Your modem is not connected to anything, so there is no info to return :slight_smile:

1 Like

Ah … you want data from the Router UI > Realtime Data > Traffic page. Just had a quick look at the source code and it seems as if all the values are calculated on the page itself (there is a javascript app that seems to handle updating all the values) … so I don’t think you’re going to find an easy way to echo this over to HA via modbus.

I am often wrong, but my gut says nope!

So I have to tweak the failover settings and force the GSM modem to connect.

I ran into another problem, though, i.e. an obviously wrong temperature.

If I understand it correctly, this works without extramodbus, but I have no idea what is wrong. Do you have some idea where I should have a closer look? Thank you so much for your patience and help! :grinning:

@7wells Re: temps see my reply copied above from earlier in this thread … tl;dr: ^^

And yes, temp & RSSI are both handled by the default modbus service (nothing to do with extramodbus), and I only included them with my guide simply as a verification that HA is receiving ‘default’ modbus messages, before attempting to troubleshoot issues with ‘extramodbus’ messages.

1 Like

How do I merge the already existing templates.yaml and the additional temperature sensor template you have kindly quoted? (my bad that did not realise it before :blush:)

Just paste the whole code snippet (be wary of indents & spacing) into your templates.yaml file and restart HA.

I am very much impressed by how this has been done, very interesting!

However, the Teltonika devices support SNMP out of the box and this includes the SINR, RSRP and RSRQ values, the GPS coordinates and much more. You can find all the oid’s at the bottom of that page.

HomeAssistant supports SNMP as well. I think it is much easier to use this instead.

How did you manage to get the accumulated download and upload data?

Somewhere over the weekend I will put it together for you!

Here we go:

  1. follow the instructions of disuye in his first post step by step. Test it and make it run. If it does you already have 95% done!

  2. Go to webui of your router again. In advance mode go to services->modbus->modbus tcp master-> edit


    to edit use the pencil and add 2 lines to the list: bytes_received_mtd and bytes_sent_mtd. Just copy address number and value.

    That should be it for the router side. Just restart the router to make it happen.

Then you go to your HAS environment and continue to your modbus.yaml or wherever you have put your RUTX50 sensors according the description of disuye and add these sensors:

      - name: "bytes received mtd" 
        unique_id: bts_rcvd_mtd01
        scan_interval: 30
        data_type: uint32
        input_type: holding
        state_class: total_increasing
        device_class: data_size
        count: 2
        unit_of_measurement: "MB"
        slave: 1
        address: 193         
      - name: "bytes sent mtd" 
        unique_id: bts_snt_mtd01
        scan_interval: 30
        data_type: uint32
        input_type: holding
        state_class: total_increasing
        device_class: data_size
        count: 2
        unit_of_measurement: "MB"
        slave: 1
        address: 195 

Copy, save and restart and if your modbus_extra is working the sensors will appear in your list of entities.

Good luck!

2 Likes

Is there any way to send SMS notification from Home Assistant using Teltonika router?

Yes. Find ‘Send SMS’ on the following link … and it’s fairly easy to add gsmctl / AT commands into a Teltonika script. Let me know if you need pointers.

https://wiki.teltonika-networks.com/view/Gsmctl_commands

1 Like

Thank you. Can you give me configuration examples of the Home Assistant part as well?
Thanks

Each use case is different, but the simplest method it to use CURL out of Home Assistant (buttons or automations can be assigned to trigger a shell command). Anywhere in configuration.yaml add the following line:

shell_command:
  send_sms_shell_command: curl -X GET "http://192.168.1.1/cgi-bin/sms_send?username=USERNAME&password=PASSWORD&number=00MOBILENUMBER&text=test%20message"

You’ll also need to enable this on your router… WebUI > Services > Mobile Utilities > Mobile Post/Get Settings and create a username & password matching the CURL command above. Everything should work from this starting point.

Things can be made a lot more complex via gsmctl / AT commands, router scripting, and/or you can have Home Assistant generate dynamic data that is passed into the CURL shell command (I’ve never done this tbh)… but again… all depends on the use case.

Perfect!
I succeeded, but only the SMS with the text “test message” always arrives. Isn’t it possible to set the message directly in the automation?

#AUTOMATION
alias: SMS Teltonika RUT test
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
condition: []
action:
  - service: shell_command.send_sms_shell_command
    data:
      message: AAA BBB CCC
mode: single

@disuye
I’m revisiting this great thread of yours and wanted to (again) set things up for my RUTX11, which has the IP 192.168.11.1 (not 192.168.1.1 as in many of Teltonika’s examples and its default).

I do get the /tmp/regfile created but when I click that TEST button on the WebGUI, I get this:

Request failed, result: Failed to get response: Slave device or server failure

I don’t know what I’m doing wrong, though.

This is my login via ssh on my router:

BusyBox v1.34.1 (2023-07-24 11:59:22 UTC) built-in shell (ash)

   ____        _    ___  ____
  |  _ \ _   _| |_ / _ \/ ___|
  | |_) | | | | __| | | \___ \
  |  _ <| |_| | |_| |_| |___) |
  |_| \_\\__,_|\__|\___/|____/

 ---------------------------------
   Teltonika RUTX series 2023
 ---------------------------------
root@Teltonika-RUTX11:~# cat /bin/extramodbus
#!/bin/ash
while true
do
gsmctl -CA 'AT+QCAINFO' -o --modemtime 2 | tr '\n\r,\"' ',' > /tmp/regfile
echo '0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000' >> /tmp/regfile
sleep 8
done
root@Teltonika-RUTX11:~# cat /tmp/regfile
18187266,OK,,Willkommen,23/08/28,15:48:50,0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000
root@Teltonika-RUTX11:~#

Since my router modem is currently not transferring any data (because it’s connected to my home router via wifi), there are only zeros, but that is not the problem, I guess.

These are the router modbus settings:

PS:
Meanwhile, I observed that the “Brackets” option should be off, so I disabled that radio button, but the error message remains.

I am guessing your issue is related to section 4d) of my original post (see below) – you can get weird modbus errors / failures if the data size generated is smaller than expected. Try adding another bunch more 00000 s to your code (there are 100 right now, maybe add another 50 or 100?).

4d) Pad out the /tmp/regfile … If a Modbus server is given data file that contains less than the expected number of characters / below the register count, it returns an error and fails. We want the /tmp/regfile to contain a minimum of 250 characters (aka a register count of 125, = 250 characters / 2) so running the echo command below appends 100x '0’s to the end of the /tmp/regfile. Hacky but it works, and I would love to know a cleaner solution…

Maybe you can help me.
I’m trying to send the RUTX11 GPS data to Home assistant but I have wrong data in HA entities:

Attacj image of Rutx modbus conf, HA modbus and entities

Other data are received correctly
Sorry but can’t make image bigger

Thanks
Toni

1 Like