Teltonika (OpenWRT / RutOS) custom GSM modem modbus

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

Sorry for the slow reply – not active on the forums very much. I get correct GPS from my RUTX50 with the following:

      - name: "RUTX50: GPS Lat"
        scan_interval: 30
        slave: 192
        address: 143
        data_type: float32
        precision: 6

      - name: "RUTX50: GPS Lon"
        scan_interval: 30
        slave: 192
        address: 145
        data_type: float32
        precision: 6
1 Like

Thanks
I have already fixed with SNMP

1 Like

Hello @Karumbe

Would you mind sharing how you did that? Thank you! :grinning:

1 Like

I’ve looked into SNMP before (the links below are very well written) but hopefully @Karumbe can share an exact setup for you.

1 Like

Just enabled SNMP as in your link, so far not tested v3 Mode and in HA

sensor:

  • platform: snmp
    name: ‘Rutx_latitude’
    host: 192.168.1.1
    baseoid: .1.3.6.1.4.1.48690.3.1.0
    unique_id: rutlat
  • platform: snmp
    name: 'Rutx_longitude’
    host: 192.168.1.1
    baseoid: .1.3.6.1.4.1.48690.3.2.0
    unique_id: rutlon
  • platform: snmp
    name: ‘Rutx_date’
    host: 192.168.1.1
    baseoid: .1.3.6.1.4.1.48690.3.4.0
    unique_id: rutdat
2 Likes

Hello and thanks for both your feedback! :relaxed:

However, I’m not sure if I’m doing this correctly. Could you maybe please provide me with a hint in this regard?

On my RUTX11, I enabled SNMP like this (and left all other SNMP settings as they were per default):

On HA, I have set up /config/sensors/rutx.yaml (and I have sensor: !include_dir_merge_list sensor in configuration.yaml) as shown below (the baseoids are from Teltonika’s website):

  sensor:
    - platform: snmp
      name: 'RUTX_gps_latitude'
      host: 192.168.11.1                                           # note that this is my RUTX11's IP (not 192.168.1.1)
      baseoid: .1.3.6.1.4.1.48690.3.1.0
      accept_errors: true
      unique_id: rut_gps_latitude

    - platform: snmp
      name: 'RUTX_gps_longitude'
      host: 192.168.11.1
      baseoid: .1.3.6.1.4.1.48690.3.2.0
      accept_errors: true
      unique_id: rut_gps_longitude

    - platform: snmp
      name: 'RUTX_gps_accuracy'
      host: 192.168.11.1
      baseoid: .1.3.6.1.4.1.48690.3.3.0
      accept_errors: true
      unique_id: rut_gps_accuracy

    - platform: snmp
      name: 'RUTX_gps_fixtime'
      host: 192.168.11.1
      baseoid: .1.3.6.1.4.1.48690.3.4.0
      accept_errors: true
      unique_id: rut_gps_fixtime

    - platform: snmp
      name: 'RUTX_gps_numsat'
      host: 192.168.11.1
      baseoid: .1.3.6.1.4.1.48690.3.5.0
      accept_errors: true
      unique_id: rut_gps_numsat

I restarted HA and thought that I would now find some new entities via SNMP but there are none. What am I doing wrong or missing? Again, thanks for your help! :heart:

Well, now have another problem, when the SNMP sensor reaches the value of 2000000000
bytes falls to -2000000000.
Any idea?

Thanks, that works very fine.
Finally I receive the router coordinates by SNMP,
not unable to receive in MODBUS.

But can’t get correct daily send or received bytes after trying all in this thread.
In SNMP can’t handle the data over 2.000.000.000

In MODBUS got crazy data

Can you help me?

Yhanksy

Great progress you all made there. Is in first posts all information in example correct? I’m replacing Huawei with RUT241 in remote location, so definitely missing stats.

Looks like I will try to make it work with RUT241 now.

Well, I’m getting stuck on first steps…
On rut241 there is no slave, master, but there is package to be downloaded as modbus TCP server and client. I configured as on teltonika site.
For first command error for $, running without
getting this, and I can’t find a way to get further…

If I close putty and opening again to copy second command is not clear for me. When I just copy paste it includes enter commands and not getting any results, do I need to edit out “enter” to have it on single line? What about # in front?

Sorry for silly question but for me it isn’t as simple as it looks…

@incar Hopefully you managed to get further along. The vi command opens a linux based text editor and yes, the interface is bloody confusing! You might need to take a look at this:

Vi cheat sheet

The simplest operation is to type vi filename which creates a new empty file called filename, then press i to switch from command mode to insertion (aka typing) mode. Type or paste whatever text you want, then you are ready to save and exit press the ESC key to switch back to command (aka menu) mode. Type :w + ENTER to save the file, and :q + ENTER to quit Vi. You could also type :q! + ENTER to force exit Vi without saving any changes.

Thank You. No I couldn’t get any further.
Ok so after running first command I need to exit. How about nexr one? It doesn’t look like it is simple copy paste line. Or is it content of that new modbus file?

Hello!

Can somebody please explain a bit further how values coming via SNMP can be used in Home Assistant (HA)? I have SNMP enabled on my Teltonika RUTX11 and set up a few SNMP platform sensors in HA (see my post dated 03 Nov 2023: Teltonika (OpenWRT / RutOS) custom GSM modem modbus - #49 by 7wells).

However, I fail to understand what to do then in HA. I thought that there must be entities appearing, but the only entities that I see in HA in connection with my RUTX11 are from Modbus (which I want to replace by SNMP).

What am I missing? Do I also have to enable Trap service settings on my RUTX11 and enter my HA’s IP in the “Host” field (and add Trap rules, too)? I do not (yet) need alerts via Trap, but just would like to see values of RUTX11 parameters defined in HA via the SNMP platform, but there are none.

EDIT:
Why have the OIDs on Teltonika’s website trailing periods (.1.3.6.1.4.1.48690)? In all examples from HA, the OIDs start without a trailing period (1.3.6.1.4.1.xxx).

Thanks a lot for your help!

PS:
From another Linux machine, I can read values from my RUTX11 like this:

$ snmpget -v2c -c public 192.168.11.1 1.3.6.1.4.1.48690.2.2.1.12.1
iso.3.6.1.4.1.48690.2.2.1.12.1 = INTEGER: -85

However, I do not understand where/how in HA I can get this value.

Is the following in configuration.yaml not enough?

    sensor:
    - platform: snmp
      host: 192.168.11.1
      port: 161
      version: 2c
      community: public
      accept_errors: true
      name: 'Teltonika mobile signal strength'
      unique_id: "Teltonika_mobile_signal_strength"
      unit_of_measurement: "dBm"
      baseoid: 1.3.6.1.4.1.48690.2.2.1.12.1

What else do I have to set up in HA to see a corresponding entity and to be able to create a lovelace card with this parameter and value (and others)?

@disuye @Karumbe and others:
Any hints? Thank you so much! :heart:

PS2 - solution found!

I had various sensor files in a sensors folder and referred to all of them from my configuration.yaml like this:

sensor: !include_dir_merge_list sensors

However, the teltonika.yaml in that sensors folder started with sensor: , which ruined all (without any error messages in the logs):

    sensor:
    - platform: snmp
      host: 192.168.11.1
      port: 161
      version: 2c
      community: public
      accept_errors: true
      name: 'Teltonika mobile signal strength'
      unique_id: "Teltonika_mobile_signal_strength"
      unit_of_measurement: "dBm"
      baseoid: 1.3.6.1.4.1.48690.2.2.1.12.1

Why? Well, because the configuration.yaml already contains a sensor: group. :face_with_hand_over_mouth:

I just mention this here for completeness, in case others stumble over this, too. My problem had nothing to do with SNMP itself, but rather with my own stupidity. :crazy_face:

Cheers!

Users who still prefer Modbus (which is the topic of this thread :wink:) over SNMP, might be interested in this (German) blog:

There I found the below way (again, Modbus) to toggle in HA between 2 SIM cards inserted in the router:

    switches:
      - name: Sim Switches
        unique_id: "Sim Switches"
        slave: 1
        address: 205
        write_type: holdings
        # OFF Sim1, ON Sim2
        command_on: 2
        command_off: 1

If somebody had a wink if/how to achieve this via SNMP, I would be even happier. :grinning:

1 Like

@disuye
Are you aware how to monitor the GSM bands via SNMP instead of Modbus? I can only find these via SNMP:

.1.3.6.1.4.1.48690.2.2.1.12.1 Signal strength level (RSSI)
.1.3.6.1.4.1.48690.2.2.1.18.1 Cell (Base transceiver station) ID
.1.3.6.1.4.1.48690.2.2.1.19.1 SINR value in dB
.1.3.6.1.4.1.48690.2.2.1.20.1 RSRP value in dBm
.1.3.6.1.4.1.48690.2.2.1.21.1 RSRQ value in dB

(RUTX11 SNMP - Teltonika Networks Wiki)

Not GSM bands, though. Maybe they are not available at all via SNMP?

PS1: I asked Teltonika, too, and referred to your thread here. :wink:

PS2 - here is the reply from Teltonika:

This information doesn’t have an OID, so it can’t be accessed. Trying to access it via SNMP won’t work.

If you truly need it, I suggest following the tutorial you provided in your post. Alternatively, you can use MQTT instead of Modbus.

Also, you can utilize “Data to Server” where you can extract the Band from “Serving cell information”.