We had a couple of power outages that lasted a few minutes. HA somehow thinks that during that time we generated (solar) and used 181MWh of power. It seems to be a fault in the utility meter logic because the underlying sensors don’t show any such spikes. Any idea how to 1. Prevent this from happening during power outages, 2. Scrub the spikes from the data so it doesn’t mess up monthly statistics.
I stand corrected. The underlying sensor (from Enphase) did show two spikes, but didn’t include it in the daily total. Any easy way to filter out such spikes. I am pretty safe ignoring any value over 1MWh. I think the sensor reset to 0 after each spike.
You can filter it through a template sensor. e.g.
template:
- sensor:
- name: Solar Production (Filtered)
unique_id: solar_production_filtered
state_class: total_increasing
device_class: energy
unit_of_measurement: kWh
state: {{ states('sensor.your_solar_production_sensor_here') }}
availability: >
{{ has_value('sensor.your_solar_production_sensor_here') and
states('sensor.your_solar_production_sensor_here')|float(0) < 1000 }}
Then use that sensor in your utility meter instead of the raw Enphase sensor.
This will replace values over 1MWh with unknown
, which the utility meter will ignore.
It would be wise to click the “Show more” link in that pop-up and zoom in on the spikes to make sure they go directly to the huge stupid value and do not have values under 1MWh on the way up or down. If these intermediate points do exist then this method will not work.
Thanks, I implemented the filter sensor and it worked great. Upon inspection, each power outage seemed to produce a spike of +90MWh and -90MWh from the enphase sensor. The utility meter sensor doesn’t have net metering enabled, so it ignored the -90MWh spike. So to be on the safe side, I filtered out large positive values and negative values.
The underlying sensor is actually a mqtt sensor, so there may have been some way to template a solution in the original sensor, but I couldn’t figure it out.
I also found that HA has a nice way to edit historical data: Developer Tools → Statistics → Select the entity → Click on the Triangle Icon on the right → Select Outliers in the Popup → Change the value of the datapoint. You can also select data by datarange, but with extreme values, the outlier function is easier.
If it is defined in yaml rather than discovered it may just need an availability template. Post the yaml and I’ll have a look.
The mqtt entry is below. It is in a subdirectory, so the leading mqtt:sensor stuff isn’t there. I can’t figure out what to put in the availability template. But I want to make it unavailable for values >1000 or <0.
- name: "Daily Solar Production"
state_topic: "enPhaseData"
unit_of_measurement: "kWh"
device_class: "energy"
state_class: "total"
unique_id: dailySolarProduction
value_template: "{{ value_json.ProductionDailyKWH }}"
availability_template: "{{ 'online' if 1000 > value_json.ProductionDailyKWH|float(1001) >= 0 else 'offline' }}"
Thanks, that looks great and I can reduce the number of entities. Are ‘online’ and 'offline" mapped to ‘available’ and ‘unavailable’?
Regards, Stephen
Yes. They are the default availability payloads the template checks for. You can change them. MQTT Sensor - Home Assistant