Logging Daily, Weekly, Monthly Energy Usage of Sonoff S31 smart plugs. No metrics are being recorded, DevTools showing "0" or "unknown" for energy sensors

Hello all,
I hope you are all doing well thus far in the new year.

HASS: HASS OS 7.1
Core: Core-2021.12.7
Supervisor: supervisor-12.2
Initially installed Home Assistant using haos_ova_7.0.ova HassOS Image about 2 months ago.

Goal: I would like to start tracking energy usage (consumption) from my Sonoff S31 (not the Lite version) power monitoring feature and display that data in Daily, Weekly, and Monthly aggregate values for each plug that is shown below. I would like to get it to a point where I can show these values in the Energy dashboard and aggregate all values to an overall usage in Daily, Weekly, and Monthly values as well.

Problem: I have been searching through the documentation and through multiple different blogs and forums attempting to see if this has been done before or to figure out what I am doing wrong, but have been unsuccessful in getting the integration entities to show anything other than “unknown” and the Utility Meter integration to show anything other than “0”. Looking at the developer tools and searching for “energy” each sensor appears correctly including with desired naming… but some “energy” sensors show “unknown” and some show “0” for the values. The same for some of the daily/weekly sensors. However, the Monthly sensors weren’t created in HASS at all (searched for “monthly” in DevTools and no entries are returned).

The plugs deliver a few different entities in HA:

  • Power (watts)
  • Current (Amps)
  • Voltage (volts)

I have attempted to utilize the “Integration” integration to create a number of new sensors to track energy consumption by utilizing this blog: https://mwunderling.com/blog/energymonitoringha.html and after creating the Integration integration entities, rounding it out with Daily, Weekly, and Monthly entities for the Utility Meter integration.

I have Recorder recording to a MariaDB container on another VM host. This is working perfectly thus far with reporting everything it was previously. I am also shipping data to InfluxDB for eventual reporting in Grafana. InfluxDB is also working, but I don’t think this has much to do with this issue, other than InfluxDB also confirming that while the energy entities are created, they have 0 data being reported about them. This leads me to believe that the integration isn’t working or I have the integration in configuration.yaml incorrect.

Here are the following entries:

sensor: 
  ## Define Engery Monitoring Collections Integration Sensors
  # Fridge/Freezers
  - platform: integration
    source: switch.sonoff_10012b7956
    name: Fridge Energy
    unit_prefix: k
    round: 2
  - platform: integration
    source: switch.sonoff_10012b7360
    name: Freezer (Center) Energy
    unit_prefix: k
    round: 2
  - platform: integration
    source: switch.sonoff_10012b7d4e
    name: Freezer (Outer) Energy
    unit_prefix: k
    round: 2
  ## HomeLab
  - platform: integration
    source: switch.sonoff_10012ef72b
    name: ESXi Energy
    unit_prefix: k
    round: 2
  - platform: integration
    source: switch.sonoff_10012ef2cf
    name: NAS Energy
    unit_prefix: k
    round: 2
  - platform: integration
    source: switch.sonoff_10012b754a
    name: Desktop-Dave Energy
    unit_prefix: k
    round: 2
  ## TV's
  - platform: integration
    source: switch.sonoff_10012b7af7
    name: TV Alex Energy
    unit_prefix: k
    round: 2
  - platform: integration
    source: switch.sonoff_10012effd6
    name: TV Bash Energy
    unit_prefix: k
    round: 2
  - platform: integration
    source: switch.sonoff_10012ef0c1
    name: TV Living Room Energy
    unit_prefix: k
    round: 2
  ## Geckos
  - platform: integration
    source: switch.sonoff_10012b7461
    name: GeckoDaytimeLight Energy
    unit_prefix: k
    round: 2
  - platform: integration
    source: switch.sonoff_10012b7454
    name: GeckoNightLight Energy
    unit_prefix: k
    round: 2

## Utility Meter Integration
utility_meter:
  ## Fridge/Freezer Energy Consumptions ##############
  ## Fridge
  fridge_daily_energy:
    source: sensor.fridge_energy
    cycle: daily
  fridge_weekly_energy:
    source: sensor.fridge_energy
    cycle: weekly
  fridge_monthly_engergy:
    source: sensor.fridge_energy
    cycle: monthly
  ## Freezer (center)
  freezer_center_daily_energy:
    source: sensor.freezer_center_energy
    cycle: daily
  freezer_center_weekly_energy:
    source: sensor.freezer_center_energy
    cycle: weekly
  freezer_center_monthly_engergy:
    source: sensor.freezer_center_energy
    cycle: monthly
  ## Freezer (outer)
  freezer_outer_daily_energy:
    source: sensor.freezer_outer_energy
    cycle: daily
  freezer_outer_weekly_energy:
    source: sensor.freezer_outer_energy
    cycle: weekly
  freezer_outer_monthly_engergy:
    source: sensor.freezer_outer_energy
    cycle: monthly
  ## HomeLab ################################################################
  ## ESXi
  esxi_daily_energy:
    source: sensor.esxi_energy
    cycle: daily
  esxi_weekly_energy:
    source: sensor.esxi_energy
    cycle: weekly
  esxi_monthly_engergy:
    source: sensor.esxi_energy
    cycle: monthly
  ## NAS
  nas_daily_energy:
    source: sensor.nas_energy
    cycle: daily
  nas_weekly_energy:
    source: sensor.nas_energy
    cycle: weekly
  nas_monthly_engergy:
    source: sensor.nas_energy
    cycle: monthly
  ## Desktop-Dave
  desktop_dave_daily_energy:
    source: sensor.desktop_dave_energy
    cycle: daily
  desktop_dave_weekly_energy:
    source: sensor.desktop_dave_energy
    cycle: weekly
  desktop_dave_monthly_engergy:
    source: sensor.desktop_dave_energy
    cycle: monthly
  ## TV's #######################################################
  ## Alex
  tv_alex_daily_energy:
    source: sensor.tv_alex_energy
    cycle: daily
  tv_alex_weekly_energy:
    source: sensor.tv_alex_energy
    cycle: weekly
  tv_alex_monthly_engergy:
    source: sensor.tv_alex_energy
    cycle: monthly
  ## Bash 
  tv_bash_daily_energy:
    source: sensor.tv_bash_energy
    cycle: daily
  tv_bash_weekly_energy:
    source: sensor.tv_bash_energy
    cycle: weekly
  tv_bash_monthly_engergy:
    source: sensor.tv_bash_energy
    cycle: monthly
  ## Living Room 
  tv_living_room_daily_energy:
    source: sensor.tv_living_room_energy
    cycle: daily
  tv_living_room_weekly_energy:
    source: sensor.tv_living_room_energy
    cycle: weekly
  tv_living_room_monthly_engergy:
    source: sensor.tv_living_room_energy
    cycle: monthly
  ## Geckos ######################################
  ## Gecko Daytime 
  gecko_daytime_daily_energy:
    source: sensor.geckodaytimelight_energy
    cycle: daily
  gecko_daytime_weekly_energy:
    source: sensor.geckodaytimelight_energy
    cycle: weekly
  gecko_daytime_monthly_engergy:
    source: sensor.geckodaytimelight_energy
    cycle: monthly
  ## Gecko Nighttime
  gecko_nighttime_daily_energy:
    source: sensor.geckonightlight_energy
    cycle: daily
  gecko_nighttime_weekly_energy:
    source: sensor.geckonightlight_energy
    cycle: weekly
  gecko_nighttime_monthly_engergy:
    source: sensor.geckonightlight_energy
    cycle: monthly

Additionally, I moved away from SQLite and have MySQL setup.

## Setup Recorder Retention - should help to improve DB performance. 
recorder:
  commit_interval: 120
  purge_keep_days: 7
  auto_purge: true
  db_url: mysql://homeassistant:homeassistantDBPW%4010.0.100.15:3308/homeassistant?charset=utf8mb4
  include:    # Include everything you graph and will want to see later
    domains:
      - sensor
      - binary_sensor
      - switch
      - light
              # Everything is included by default. 
       
  exclude:    # Eliminate anything that you never graph or refer back to
    domains:
      - automation
      - updater
    entities:
      - sun.sun
      - sensor.time
      - sensor.date_time_iso # Don't record date and time
      - sensor.date_time_utc # Don't record date and time
      - sensor.date_time # Don't record date and time
      - sensor.yr_symbol # Ignore this as well

Finally, and I’m not sure that this has anything to do with it… but I also am sending data to InfluxDB as I want to eventually report things in Grafana (but haven’t really gotten there)

## InfluxDB Integration
influxdb:
  api_version: 2
  ssl: false
  host: 10.0.100.15
  port: 8086
  organization: TheHartHaven
  bucket: HomeAssistant
  token: !secret influxdb_administrator_token
  tags: 
    source: HA
  tags_attributes:
    - friendly_name
    - field

Hello all,

I have solved this issue.

It appears that when you use the Riemann Sum Integration with Sonoff plugs… you need to have the source set to the “_power” value of each individual plug. Additionally, I specified unit_prefix and unit for all of them… but for appliances that have high spikes, such as heaters, freezers, etc… it was recommended to use method: left … so I did, and left the rest of them alone since they are frequently changing without massive spike like my fridge and freezers.

Here are the updated Sensors (Riemann Sum Integration and Utility_meter): https://pastebin.com/Mt5nsT7e

1 Like

Hi @BigTRex , could you share your configuration as I’m also trying to integrate my Sonoff S31 plugs to Home Assistant. Thanks.

check out TRex pastebin link, has config.

Hi BigTRex,

I’m missing something, can you provide the rest of the config to define the sonoff sensors?

Thansk