Teltonika (OpenWRT / RutOS) custom GSM modem modbus

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”.

@disuye
This is fantastic, thank you. I have been wrestling with various options of getting cell info out of my TRB500 recently with some success but not complete. I have this (your solution) working with HA but I’m having trouble aligning the modbus response CSV with the HA sensors as I have very limited java knowledge.

This is my TRB500 response, what I need to do overall is monitor the cell ID and then ideally send a command for checking neighbouring cells and if I see the one I want, change to it. I have found it goes offline overnight sometimes and switching it would leave no internet access.

Request successful, result: “3400450,+QCAINFO: ,PCC,1617,100,LTE BAND 3,1,260,-61,-10,-32,8,+QCAINFO: ,SCC,1761,50,LTE BAND 3,2,260,-61,-9,-34,4,1,50,19761,EE,24/11/26,23:28:25,0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000”

For example, in your string below, does the [29] correspond to the 29th comma in the whole string or 29 chars from the next comma it is splitting from?

value_template: “{{ states(‘sensor.rutx_extramodbus’).split(‘,’)[29] | float(0) }}”

Thanks.

Hi all,
I would really appreciate some help here please. I have tried to align the csv location with the template code and HA just seem 95% full of bad entities. It appears that it’s unable to find data it likes in the slots provided probably looking for a ‘float’ where text is needed but I’m not sure.




Screenshot 2024-11-28 at 18.12.18

This image has the responses broken out into csv numbered locations. One has a two cell connection and the other a 3 cell connection.

This is the log from HA

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:203
integration: Template (documentation, issues)
First occurred: 27 November 2024 at 21:46:17 (60 occurrences)
Last logged: 27 November 2024 at 22:42:42

TemplateError('UndefinedError: list object has no element 64') while processing template 'Template<template=({{ states('sensor.rutx_extramodbus').split(',')[64] | float(0) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.extramodbus_gsm_band4_rssi'
TemplateError('UndefinedError: list object has no element 65') while processing template 'Template<template=({{ states('sensor.rutx_extramodbus').split(',')[65] | float(0) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.extramodbus_gsm_band4_sinr'
TemplateError('UndefinedError: list object has no element 10') while processing template 'Template<template=({{ states('sensor.rutx_extramodbus').split(',')[10] | int }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.extramodbus_gsm_cell_id'
TemplateError('UndefinedError: list object has no element 10') while processing template 'Template<template=({{ states('sensor.rutx_extramodbus').split(',')[10] | float(0) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.extramodbus_gsm_band_rsrq'
TemplateError('UndefinedError: list object has no element 11') while processing template 'Template<template=({{ states('sensor.rutx_extramodbus').split(',')[11] | float(0) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.extramodbus_gsm_band_rsrp'

This is the template code:


- sensors:
    extramodbus_gsm_cell_id:
      unique_id: c9beaf2d-32b2-4f9f-97d2-688347f2ebd8
      friendly_name: "GSM Cell ID"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[0] | int }}"
    # GSM primary band
    extramodbus_gsm_band:
      unique_id: 2346fc76-8d3a-410d-aa37-d559cfcdb3f6
      friendly_name: "GSM Band"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[7] }}"
    extramodbus_gsm_band_rsrq:
      unique_id: 9be10477-0b73-4969-9c60-f367eaf73e1f
      friendly_name: "GSM Band RSRQ"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[12] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band_rsrp:
      friendly_name: "GSM Band RSRP"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[11] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band_rssi:
      friendly_name: "GSM Band RSSI"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[13] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band_sinr:
      friendly_name: "GSM Band SINR"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[14] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    # GSM secondary band2
    extramodbus_gsm_band2:
      friendly_name: "GSM Band2"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[22] }}"
    extramodbus_gsm_band2_rsrq:
      friendly_name: "GSM Band2 RSRQ"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[27] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band2_rsrp:
      friendly_name: "GSM Band2 RSRP"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[26] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band2_rssi:
      friendly_name: "GSM Band2 RSSI"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[31] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band2_sinr:
      friendly_name: "GSM Band2 SINR"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[28] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    # GSM secondary band3
    extramodbus_gsm_band3:
      friendly_name: "GSM Band3"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[40] }}"
    extramodbus_gsm_band3_rsrq:
      friendly_name: "GSM Band3 RSRQ"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[44] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band3_rsrp:
      friendly_name: "GSM Band3 RSRP"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[45] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band3_rssi:
      friendly_name: "GSM Band3 RSSI"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[46] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band3_sinr:
      friendly_name: "GSM Band3 SINR"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[47] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    # GSM secondary band4
    extramodbus_gsm_band4:
      friendly_name: "GSM Band4"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[58] }}"
    extramodbus_gsm_band4_rsrq:
      friendly_name: "GSM Band4 RSRQ"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[62] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band4_rsrp:
      friendly_name: "GSM Band4 RSRP"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[63] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band4_rssi:
      friendly_name: "GSM Band4 RSSI"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[64] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength
    extramodbus_gsm_band4_sinr:
      friendly_name: "GSM Band4 SINR"
      value_template: "{{ states('sensor.rutx_extramodbus').split(',')[65] | float(0) }}"
      unit_of_measurement: "dBm"
      device_class: signal_strength

Thank you.

Hi –

split(‘,’)[29]

… means “split at the 29th comma”, so in regards to your error messages below:

TemplateError('UndefinedError: list object has no element 64')

There might not be a 64th comma in the modbus data string or sometimes (for various reasons) modbus server can return an empty value which results in two commas next to each other with no data in between. I forget what caused this on my system, I think when running the gsmctl command when the modem has 5G only service, not a 4G LTE / 5G mixed? Something along those lines, sorry I can’t remember. But an unexpected response from gsmctl can sometimes result in an empty modbus register (i.e: two commas next to other with no data in between, then HA stumbles to parse it).

Noted but I’m not getting anything in any location. The only entities that are not complaining are those without ‘float’ or ‘int’, etc meaning text (I assume) but even that doesnt show. I have run the test on the TRB again so there is definitely something in the registers even if it was doing it every 8 seconds.

Does the csv list start at 0 or 1 and I’m not clear when to use int or float for those values expected?