I am bit new to custom sensors in the configuration.yaml. However the recent increase in sensor glitches made me try to get a bit more into it.
For my current power consumption I wrote a static limit within the value has to be to be updated.
For increasing sensors like kWh counters, especially if they are used in the energy dash board is seems not that easy.
My first idea would be to compare it to a value what was recorded shortly before to check if it is not smaller or increased by an implausible amount. I saw an approach with trigger sensors to capture a value/state every few minutes.
What I tried to derive from all me web findings looks like this:
In short: The actual sensor values are read every 5min as reference. Then the sensor template checks if the SML value is bigger that the reference but also not bigger by more than 1 or 3 kWh. Even if a glitch was captured as reference, the worse thing that can happen is that the sensor won’t display a new value/state for 5 min.
Since I run HA core and can’t access the yaml that easy I was hoping to get an opinion and error correction before I cripple my HA
Hello Tom,
thanks for your reply.
The sensors tasmota_sml_total_out and _in are provided by an ESP based power sensor that is connected to my main power meter in the house. The information is then provided as an sensor via the Tasmota integration.
I don’t know were this error originates since the main power meter does not have any glitches.
The glitches are random values ranging from 0.000 to 99999999999.999, however it can also be a number like 250.258. This makes it difficult to work with fixed limit to accept data. At the moment the power meter has around 450kWh, but it will increase over time, and so the limits would have to adapt.
Therefor I just wanted to compare the current value with a value it read 5 minutes ago.
The value in the energy dashboard basically sums up all the changes in between the sensors grid_in and _out (kWh) readings within 1 or 2 hours. Sensor glitches therefor produce insane high energy consumptions (kWh).
At no time the state/value is unknown or unavailable.
This is how is should work.
read the state value of the tasmota sensors in and out every 5 min, e.g. 455.123
if the tasmota sensor value changes the template sensor should check if the new value is bigger than the value 5min ago. On the other hand the value cannot be bigger than the 5min reference value + 3 kWh (because I technically cannot draw more Energy in 5 minutes).
It is going to be very difficult to filter out those glitches. You need to fix the sensor.
Sounds to me like there is a problem with Tasmota or its configuration.
Searching their issues I discovered this:
So they seem to be refusing to implement the checksum (which would reject invalid readings) and request that you check your serial installation.
Seems like a terrible answer to me. Any brief understanding of Shannon’s Theorem would tell you that you can not eliminate noise in a communication channel completely. Using the checksum is wise. All sorts of impulse noise could exist near your power switchboard that could cause bad data.
Try to eliminate this by checking your installation, in particular:
positioning of the IR head
use the shortest serial cabling possible, consider extending the power cabling instead.
Yeah, as assumed there is no error correction in the transmission…
Wifi is stable, position is good.
Well, I am still wondering if there could be a dirty fix for now.
Where I am stuck now is actually how to write the current sml_total_* state into prev_grid_in_5m or something i can access in the sensor grid_power-* state calculations.
The trigger might be triggering by time pattern, but I don’t get a entity_id to access.
Sadly no luck so far. I partially re-soldered the whole thing but no significant changes. I also removed all other Mqtt traffic that could cause some trouble on my server side. But since I saw the glitches also on the Tasmota web interface, it is clear that the glitches must occur directly on the read-out side.
For now the only solution is to work with tight limits, but any dynamic filter would be better. Is there no way to implement a filter (or something like my first idea) in the yaml?
Another work around might rely on statistics. Right now the value is updating every few seconds. If a value is fetches every 5min, the chance of fetching a glitch would be at least a bit lower.
So I am still open for all temporary work arounds better than this:
this seems to do what I want. So I created a new template sensor from that value [ state: filter…] to get into the device class energy with the correct unit of measurement.
I hope this will work …