Using Home Assistant to count self sufficient days

For some time I have wanted to track when we generated enough solar power to make us self sufficient. This led to a debate on Mastodon about what self sufficient means. I think it is when more power is generated than is imported from the grid. Others believe it is when more is generated than the house consumes.

I posted a survey on Mastodon and it came out 50/50. No help there. The problem is, my solar iBoost is recorded against house consumption, yet the power is coming from the solar panels.

To cover both bases I made two counters in Home Assistant. One for the grid and one for consumption

self_sustained_consumption and self_sustained_grid

I followed these instructions to make the counters

Mine look like this in the Home Assistant GUI

Home Assistant Helper screen with my counters

I then made two automations that will trigger at 23:55 each night. I doubt the last five minutes of the day will swing it one way or the other. The first automation compares the solar generation against the grid import

alias: Solar - Self Sustained Counter (Grid)
description: Solar - Self Sustained Counter (Grid)
trigger:
  - platform: time
    at: "23:55:00"
condition:
  - condition: numeric_state
    entity_id: sensor.lux_solar_output_daily
    above: sensor.lux_power_from_grid_daily
action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.self_sustained_grid
mode: single

The second compares the solar generation to the house consumption

alias: Solar - Self Sustained Counter (Consumption)
description: Solar - Self Sustained Counter (Consumption)
trigger:
  - platform: time
    at: "23:55:00"
condition:
  - condition: numeric_state
    entity_id: sensor.lux_solar_output_daily
    above: sensor.lux_home_consumption_daily
action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.self_sustained_consumption
mode: single

I then needed a way to display the counters. I made a combined bar card using a custom bar card. I have made two, I am not sure which one I prefer yet. I can track the consumption number prior to today (30th April 2023), but not the grid import. I only have the last 7 days worth of data and we have been self sufficient for all 7 days.

Self Sustained Custom Bar Card. Using the up option

This is the YAML for this card

entities:
  - entity: counter.self_sustained_consumption
    name : Days Self Sustained (Consumption)
    severity:
      - color: red
        from: 0
        to: 10
      - color: orange
        from: 11
        to: 29
      - color: blue
        from: 30
        to: 39
      - color: green
        from: 40
        to: 365
  - entity: counter.self_sustained_grid
    name : Days Self Sustained (Grid)
    severity:
      - color: red
        from: 0
        to: 10
      - color: orange
        from: 11
        to: 29
      - color: blue
        from: 30
        to: 39
      - color: green
        from: 40
        to: 365
title: Self Sustained
direction: up
height: 200px
stack: horizontal
type: custom:bar-card

This is the second Custom Bar Card

Self Sustained Custom Bar Card. Using the default option

This is the YAML code for this card

entities:
  - entity: counter.self_sustained_consumption
    name: Days Self Sustained (Consumption)
    type: custom:bar-card
    max: 365
    severity:
      - color: red
        from: 0
        to: 10
      - color: orange
        from: 11
        to: 29
      - color: blue
        from: 30
        to: 39
      - color: green
        from: 40
        to: 365
  - entity: counter.self_sustained_grid
    name: Days Self Sustained (Grid)
    type: custom:bar-card
    max: 365
    severity:
      - color: red
        from: 0
        to: 10
      - color: orange
        from: 11
        to: 29
      - color: blue
        from: 30
        to: 39
      - color: green
        from: 40
        to: 365
type: entities

The maximum value does not need to be 365 days. Plainly there is no chance of being self sufficient every day. I will change this next autumn when I know what a good target number will be.

 
Michael Curtis

My introduction to computers started at my middle school in 1981 when our maths teacher brought in a ZX80. That led the computer club being founded and using a Research Machine 380Z

My first computer was a 48K ZX Spectrum which I loved to programme. Once I left school I worked as a photocopier engineer, then a fax engineer and finally moving on the Apple computers.

For the next 30 years I worked as a system administrator. I now work in the cyber security industry as a Sophos Professional Services consultant

https://www.bazmac.me
Previous
Previous

April’s Solar Generation and Export Numbers

Next
Next

Setting overnight battery usage start time