Hi, I have a problem with HA and I hope you can help me. A few weeks ago I installed a LORA transmitter in the nearest forest, which sends sensor values home every few minutes. It’s working fine, I can parse the payload with Home Assistant and get the corresponding values displayed. However, after 10 days the temperature display does not simply lose the level of detail as normal, but nothing is saved at all.
At first i thought the state_class was missing, but it’s there. Here is an excerpt from config.yaml for the voltage. Sometimes unrealistic values are sent, but the query for realistic values is included.
- name: "Lora1 Voltage"
unique_id: "lora_1_voltage"
state_topic: "tele/Tasmota_Lora/RESULT"
value_template: >-
{% set payload = value_json.LoRaReceived %}
{% if payload.startswith('Lora1:') %}
{% set v = payload.split(':')[1][1:] | float %}
{{ v if 2.5 <= v <= 4.5 else none }}
{% endif %}
unit_of_measurement: "V"
device_class: voltage
state_class: measurement
Do you have any idea what else might block him from showing long-term data? Thank you.
Assuming that is the mqtt integration (you did not say or include the relevant config), you need an else case for your if and you can’t use none in a numeric sensor. Check your logs for errors related to this.
- name: "Lora1 Voltage"
unique_id: "lora_1_voltage"
state_topic: "tele/Tasmota_Lora/RESULT"
value_template: >
{% set payload = value_json.LoRaReceived %}
{% if payload.startswith('Lora1:') %}
{% set v = payload.split(':')[1][1:] | float %}
{% if 2.5 <= v <= 4.5 %}
{{ v }}
{% else %}
{{ this.state }} {# keeps the last value #}
{% endif %}
{% else %}
{{ this.state }}
{% endif %}
Then go to Developer Tools → Statistics and fix any issues listed there before restarting.
It would also help if you shared the payload so we could check your template.
Thanks so far. The none was on purpose so that I can see from the gaps in the graph when there were again some inconsistent values. But I will fix it as you say.
The payload is as follows:
Ok, now I understand. Well, the entity for the battery voltage is sensor.lora_sensor_voltage (Batterie Wald). Don’t ask me why he didn’t create the entity_id sensor.lora1_voltage. Is this what the problem is all about?
No, there is no sensor.lora1_voltage. But I’m a little bit confused now. Shouldn’t it be sensor.lora_1_voltage, since this is the unique id? Anyway, both aren’t there. I can’t remember to have renamed it but I have renamed the entity right now to sensor.lora_1_voltage though but would it fix this anyway?
When you supply a value for the name option, Home Assistant will use that to create an entity_id.
Unlikely.
It’s challenging to provides definitive answers because the presented evidence is contradictory. The MQTT Sensor’s name is “Lora1 Voltage” so that should create sensor.lora1_voltage, but this entity_id doesn’t exist in Developer tools → States.
This may sound far-fetched but is it possible that Home Assistant is discovering your LORA sensors and creating sensor entities automatically?
That would be nice, but I only had the entities after I had edited the config.yaml. If I throw one of them out, the corresponding sensor is no longer recognised.
Can I reset this somehow or do I have any other options?
O boy, I have no clue what happened, but just out of curiosity I have renamed the voltage entity as sensor.lora1_voltage and now from all lora1 entities long-term data is recorded, although I haven’t renamed all of them accordingly.
However, the lora2 entities are all called according to the mqtt sensor config and there is still no long-term data. I’m getting desperate. I will try to delete everything from lora2 as you recommended and see if this will fix it. I really have no clue what is wrong with it.
Well, just in case somebody is running into the same problem. For me it helped to rename any entity of the device to anything else to make long term recording work and then again to the old entity. I guess this is just a bug. Anyway, thanks for your help.
I have several MQTT Sensors, whose history is recorded in long-term statistics, and I have never had to do what you have described (nor have I seen anyone else mention the need for it).
It’s clear from the contradictory evidence you have provided that the problem was caused by something you did in the past that wasn’t explicitly mentioned here. You did something in order to create sensors with entity_ids that do not match the names in the configurations you posted. They don’t just do that on their own.
The only way to confirm it’s an actual bug is to explain how to duplicate it. If you don’t know, or cannot explain, the steps to produce the error, then no one replicate it to test, isolate, and fix the root cause.