shoei600
(Shoei600)
February 16, 2025, 6:48pm
1
Please help, what am I missing with ‘templates’ please?
I’m parsing data from modbus which working fine but I cannot seem to access the data which I had thought would show as entities from the template created.
In my config.yaml I have the following:
template:
- sensor:
- name: "GSM Cell ID"
state: "{{ states('sensor.rutx_extramodbus').split(',')[0] | int }}"
unique_id: 6f098414-695f-4c38-8fb1-857826d22b9a
I would have expected - after system reboot - to find an entity called ‘GSM Cell ID’ but having tried a long list, nothing ever appears.
Thanks.
Yes, it should create an entity after restart (there shouldn’t be a need for a full system reboot).
How long a list are we talking? States are limited to 255 characters, so if the the Modbus sensor’s state was over that limit it would return an unknown state and the template sensor would also fail.
You should almost always add define an availability
for template sensors to prevent them from failing from things like this.
shoei600
(Shoei600)
February 16, 2025, 8:26pm
3
Many thanks for the quick response. In the meantime I now have the first showing up - but not the rest.
template:
- sensors:
- name: "GSM Cell ID"
state: "{{ states('sensor.rutx_extramodbus').split(',')[0] | int }}"
unique_id: 6f098414-695f-4c38-8fb1-857826d22b9a
- name: "GSM Band"
state: "{{ states('sensor.rutx_extramodbus').split(',')[7] }}"
uniquie_id: aa1b42c4-4402-4397-a85f-bb47b8db06d5
- name: "GSM Band RSRQ"
state: "{{ states('sensor.rutx_extramodbus').split(',')[11] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 727b2b9e-d8cb-44ad-8ba5-488bbb69f132
- name: "GSM Band RSRP"
state: "{{ states('sensor.rutx_extramodbus').split(',')[12] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 8040b296-473f-4ec4-ac49-b2d92195811e
- name: "GSM Band RSSI"
state: "{{ states('sensor.rutx_extramodbus').split(',')[13] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 3b42ace7-88bc-4f0a-944b-6b0f61a3b1c8
- name: "GSM Band SINR"
state: "{{ states('sensor.rutx_extramodbus').split(',')[14] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 0542b5c5-f9b7-4b38-8dbc-fcc9d69fee5d
- name: "GSM Band2"
state: "{{ states('sensor.rutx_extramodbus').split(',')[22] }}"
uniquie_id: 1263324a-97cc-4ebb-87d3-1f717687e212
- name: "GSM Band2 RSRQ"
state: "{{ states('sensor.rutx_extramodbus').split(',')[26] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 91a26d16-017c-420e-9aec-bbc13cf11ec9
- name: "GSM Band2 RSRP"
state: "{{ states('sensor.rutx_extramodbus').split(',')[27] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: c28de2c6-6bb8-4b8d-a730-3a093ed94e9d
- name: "GSM Band2 RSSI"
state: "{{ states('sensor.rutx_extramodbus').split(',')[28] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: ae99bd67-a03a-47f2-9210-81a91e5bb80a
- name: "GSM Band2 SINR"
state: "{{ states('sensor.rutx_extramodbus').split(',')[29] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: cfcbf9e8-ad41-4f35-9db3-ed40caebbec8
- name: "GSM Band3"
state: "{{ states('sensor.rutx_extramodbus').split(',')[40] }}"
uniquie_id: 653a30e8-3fa6-4a85-80ee-92140643c393
- name: "GSM Band3 RSRQ"
state: "{{ states('sensor.rutx_extramodbus').split(',')[44] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 0d2ca664-2dc9-4d5b-9eca-87f05086301b
- name: "GSM Band3 RSRP"
state: "{{ states('sensor.rutx_extramodbus').split(',')[45] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 5493436b-9f6b-408e-8f53-d572bdaa8833
- name: "GSM Band3 RSSI"
value_template: "{{ states('sensor.rutx_extramodbus').split(',')[46] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 574b3d26-98e3-4b81-9f94-3c9e3bb203fb
- name: "GSM Band3 SINR"
state: "{{ states('sensor.rutx_extramodbus').split(',')[47] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: a3737c2e-7be0-4cde-86e8-a7ca50074924
- name: "GSM Band4"
state: "{{ states('sensor.rutx_extramodbus').split(',')[58] }}"
uniquie_id: 3d637046-c405-4557-8d82-4bfd61e33d48
- name: "GSM Band4 RSRQ"
state: "{{ states('sensor.rutx_extramodbus').split(',')[62] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: a88748fb-66a8-4f4a-b7e7-1ee1fea3fc09
- name: "GSM Band4 RSRP"
state: "{{ states('sensor.rutx_extramodbus').split(',')[63] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: a3e218f3-bd7c-452e-8843-995523cbe774
- name: "GSM Band4 RSSI"
state: "{{ states('sensor.rutx_extramodbus').split(',')[64] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: 572e38e4-9d6e-4fff-9f38-a00cf68f9983
- name: "GSM Band4 SINR"
state: "{{ states('sensor.rutx_extramodbus').split(',')[65] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
uniquie_id: dd87f594-d2c6-4df7-a1bf-c1281a50d53d
The original post I was following is here, but I have re-tweaked the list for ‘the modern’ template style as the first was not working. https://community.home-assistant.io/t/teltonika-openwrt-rutos-custom-gsm-modem-modbus/569205
Good idea about availability. Is it literally ‘availability_template: true’ to add?
Thank you.
Check Logs if you got any related warnings / errors.
Paste the whole code for template sensors posted here into “Dev tools → Template” to see what it gives.
I do not think this is correct:
template:
- sensors:
Shouldn’t it be “sensor”?
4. Docs are here , add the “availability” option as per Docs.
123
(Taras)
February 16, 2025, 8:57pm
5
shoei600:
uniquie_id
That should be unique_id
not uniquie_id
.
shoei600
(Shoei600)
February 16, 2025, 9:10pm
6
Good spot on the typo, especially as the first was correct.
In dev tools the last few break it, the variables are populated down to ‘split 58’.
- sensors:
- name: "GSM Cell ID"
state: "{{ states('sensor.rutx_extramodbus').split(',')[0] | int }}"
unique_id: 6f098414-695f-4c38-8fb1-857826d22b9a
- name: "GSM Band"
state: "{{ states('sensor.rutx_extramodbus').split(',')[7] }}"
unique_id: aa1b42c4-4402-4397-a85f-bb47b8db06d5
- name: "GSM Band RSRQ"
state: "{{ states('sensor.rutx_extramodbus').split(',')[11] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 727b2b9e-d8cb-44ad-8ba5-488bbb69f132
- name: "GSM Band RSRP"
state: "{{ states('sensor.rutx_extramodbus').split(',')[12] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 8040b296-473f-4ec4-ac49-b2d92195811e
- name: "GSM Band RSSI"
state: "{{ states('sensor.rutx_extramodbus').split(',')[13] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 3b42ace7-88bc-4f0a-944b-6b0f61a3b1c8
- name: "GSM Band SINR"
state: "{{ states('sensor.rutx_extramodbus').split(',')[14] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 0542b5c5-f9b7-4b38-8dbc-fcc9d69fee5d
- name: "GSM Band2"
state: "{{ states('sensor.rutx_extramodbus').split(',')[22] }}"
unique_id: 1263324a-97cc-4ebb-87d3-1f717687e212
- name: "GSM Band2 RSRQ"
state: "{{ states('sensor.rutx_extramodbus').split(',')[26] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 91a26d16-017c-420e-9aec-bbc13cf11ec9
- name: "GSM Band2 RSRP"
state: "{{ states('sensor.rutx_extramodbus').split(',')[27] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: c28de2c6-6bb8-4b8d-a730-3a093ed94e9d
- name: "GSM Band2 RSSI"
state: "{{ states('sensor.rutx_extramodbus').split(',')[28] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: ae99bd67-a03a-47f2-9210-81a91e5bb80a
- name: "GSM Band2 SINR"
state: "{{ states('sensor.rutx_extramodbus').split(',')[29] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: cfcbf9e8-ad41-4f35-9db3-ed40caebbec8
- name: "GSM Band3"
state: "{{ states('sensor.rutx_extramodbus').split(',')[40] }}"
unique_id: 653a30e8-3fa6-4a85-80ee-92140643c393
- name: "GSM Band3 RSRQ"
state: "{{ states('sensor.rutx_extramodbus').split(',')[44] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 0d2ca664-2dc9-4d5b-9eca-87f05086301b
- name: "GSM Band3 RSRP"
state: "{{ states('sensor.rutx_extramodbus').split(',')[45] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 5493436b-9f6b-408e-8f53-d572bdaa8833
- name: "GSM Band3 RSSI"
value_template: "{{ states('sensor.rutx_extramodbus').split(',')[46] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 574b3d26-98e3-4b81-9f94-3c9e3bb203fb
- name: "GSM Band3 SINR"
state: "{{ states('sensor.rutx_extramodbus').split(',')[47] | float(0) }}"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: a3737c2e-7be0-4cde-86e8-a7ca50074924
- name: "GSM Band4"
state: "{{ states('sensor.rutx_extramodbus').split(',')[58] }}"
unique_id: 3d637046-c405-4557-8d82-4bfd61e33d48
This bit breaks the dev tool which says “UndefinedError: list object has no element 62”. It seems I’m not getting more than about 60 fields to pass although there should be 125+ so that a different issue. For now I think I’ll delete the 4th band as I’m not likely to connect to 4 in any case.
shoei600
(Shoei600)
February 16, 2025, 9:25pm
7
In dev tools the template provides all the data I expect, but after reloading of yaml, restarts and reboots entities still won’t show up in HA.
- sensor:
- name: "GSM Cell ID"
state: "3329542"
- name: "GSM Band"
state: "LTE BAND 7"
- name: "GSM Band RSRQ"
state: "-97.0"
unit_of_measurement: "dBm"
device_class: signal_strength
- name: "GSM Band RSRP"
state: "-9.0"
unit_of_measurement: "dBm"
device_class: signal_strength
- name: "GSM Band RSSI"
state: "-67.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 3b42ace7-88bc-4f0a-944b-6b0f61a3b1c8
- name: "GSM Band SINR"
state: "17.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 0542b5c5-f9b7-4b38-8dbc-fcc9d69fee5d
- name: "GSM Band2"
state: "LTE BAND 3"
unique_id: 1263324a-97cc-4ebb-87d3-1f717687e212
- name: "GSM Band2 RSRQ"
state: "-79.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 91a26d16-017c-420e-9aec-bbc13cf11ec9
- name: "GSM Band2 RSRP"
state: "-20.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: c28de2c6-6bb8-4b8d-a730-3a093ed94e9d
- name: "GSM Band2 RSSI"
state: "-48.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: ae99bd67-a03a-47f2-9210-81a91e5bb80a
- name: "GSM Band2 SINR"
state: "-10.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: cfcbf9e8-ad41-4f35-9db3-ed40caebbec8
- name: "GSM Band3"
state: "LTE BAND 7"
unique_id: 653a30e8-3fa6-4a85-80ee-92140643c393
- name: "GSM Band3 RSRQ"
state: "-95.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 0d2ca664-2dc9-4d5b-9eca-87f05086301b
- name: "GSM Band3 RSRP"
state: "-8.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 5493436b-9f6b-408e-8f53-d572bdaa8833
- name: "GSM Band3 RSSI"
value_template: "-67.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: 574b3d26-98e3-4b81-9f94-3c9e3bb203fb
- name: "GSM Band3 SINR"
state: "21.0"
unit_of_measurement: "dBm"
device_class: signal_strength
unique_id: a3737c2e-7be0-4cde-86e8-a7ca50074924
123
(Taras)
February 16, 2025, 9:34pm
8
The state
value of any entity, such as sensor.rutx_extramodbus
, can store no more than 255 characters (Didgeridrew explained this earlier).
What is the integration responsible for creating sensor.rutx_extramodbus
? If it attempts to store a string longer than 255 characters, in sensor.rutx_extramodbus
, it will either fail to store anything or it will be truncated at 255 characters and the remainder is discarded.
Copy-paste the following template into the Template Editor. The reported result will never be greater than 255.
{{ states('sensor.rutx_extramodbus') | count }}
shoei600
(Shoei600)
February 16, 2025, 9:42pm
9
The GSM device (Teltonika) generates a text file every 10s that has connection details and sends the data via modbus to HA into this variable. It will have up to 4 GSM connection details and pads the rest of the file with 0’s.
Result =250
shoei600
(Shoei600)
February 16, 2025, 9:57pm
10
Probably unnecessary but I loaded ‘template yaml’, then reloaded ‘all yaml’, the restarted all services and now I have all of the sensors expected.
I will add the ‘availability’ now in case this was causing any to fail.
Thank you all so much.
123
(Taras)
February 16, 2025, 10:17pm
11
You said there should be 125+ fields.
Question: How can 125 numeric fields fit into 250 characters including the commas between each field?
Answer: It can’t.
The sensor’s value will only contain as much data as can fit within the maximum limit of 255.
Template Sensors that depend on getting data that exceeds the limit will get nothing. They’ll also generate a template error message, like the one that you reported, because they attempt to access a non-existent list item.
UndefinedError: list object has no element 62