Tasmota Current Sensor Integration and Troubleshooting Tips

I’ve recently been working on integrating a Tasmota-powered current sensor into my home automation setup, and I wanted to share my experiences and some troubleshooting tips that might help others facing similar issues.

My Setup

I’ve been using a Tasmota SML module with a Hichi IR-WiFi sensor for about a year now. It’s been a great way to monitor my energy consumption in real-time. Initially, everything worked smoothly with the template sensors provided in the configuration. However, after updating Home Assistant and switching to the Spook integration, I started encountering some unexpected behavior with the sensor readings.

The Issue

The main problem I faced was that the sensor would occasionally report utopian and unrealistic values. Instead of showing the incremental daily consumption, it would jump to the total annual usage. This was especially concerning because it happened almost daily and seemed to correlate with poor WLAN reception in my basement. While I understood that network issues could cause data spikes, I wanted to find a reliable way to filter out these erroneous readings without losing any data or having to add new sensors to my Energy Dashboard.

The Solution

After some research and experimentation, I found a solution that involved modifying the sensor’s template to include a check for valid data increments. Here’s the adjusted code I used:

yaml
sensor:

  • name: “Stromzähler Verbrauch”
    unique_id: “StromVerbrauch”
    unit_of_measurement: ‘kWh’
    device_class: “energy”
    state_class: “total_increasing”
    state: >-
    {% set new_value = states(‘sensor.tasmota_sml_total_kwh’) | float(default=0) %}
    {% set last_value = states(‘sensor.stromzahler_verbrauch’) | float(default=0) %}
    {% if new_value >= last_value and (new_value - last_value) < 10 %}
    {{ new_value | round(3) }}
    {% else %}
    {{ last_value | round(3) }}
    {% endif %}

This code checks if the new value is a reasonable increment from the last value. If not, it retains the last valid reading. This has significantly reduced the number of erroneous readings I encounter.

Tips for Others

  1. Network Stability: Ensure your sensor has a stable WLAN connection, especially if it’s in an area with potential signal interference.
  2. Regular Updates: Keep your Tasmota firmware and Home Assistant installations up to date to benefit from the latest bug fixes and improvements.
  3. Data Validation: Implement checks in your sensor templates to filter out unrealistic spikes, as shown in the code above.
  4. Backup and Restore: Regularly back up your Home Assistant configuration to avoid data loss in case of hardware failures or updates.

Success Story

After implementing these changes, my energy monitoring setup has become much more reliable. I no longer receive those shocking utopian readings, and I can trust the data being displayed in my Energy Dashboard. It’s been a great learning experience, and I’m happy to share what I’ve learned to help others troubleshoot similar issues.

If anyone has additional tips or has faced similar challenges, I’d love to hear about your experiences and solutions! Let’s keep the community knowledge flowing. :blush: