Recording maximum watts per solar panel string with Home Assistant

Update - I have updated this post with a new version.

This is our first summer with solar panels. I am interested to see the maximum watts each string produces. Home Assistant can do this for me.

You can read about our solar setup here.

I made three sensors and a new custom bar card for my solar dashboard. At first I thought this would be easy. The sensors would check the new value and if it is larger than the previous largest then update.

These sensors are of no real use for controlling anything, I was just interested what the maximum will be.

This is the YAML code that I added to the configuration.yaml file. This code works, but it turns out, values are reset on a Home Assistant restart. I asked a question on the Home Assistant community forum and was given the code in the next code block.

template:
  - sensor:
     - name: "Maximum Incoming Watts Combined"
       unique_id: maximum_incoming_watts_combined
       state: >-
          {% set old_value = states('sensor.maximum_incoming_watts_combined')|float(default=0) %}
          {% set new_value = states('sensor.lux_solar_output_live')|float(default=0) %}
          {% if new_value > old_value %}
            {{ new_value }}
          {% else %}
            {{ old_value }}
          {% endif %}
     - name: "Maximum Incoming Watts Front"
       unique_id: maximum_incoming_watts_front
       state: >-
          {% set old_value = states('sensor.maximum_incoming_watts_front')|float(default=0) %}
          {% set new_value = states('sensor.lux_solar_output_array_2_live')|float(default=0) %}
          {% if new_value > old_value %}
            {{ new_value }}
          {% else %}
            {{ old_value }}
          {% endif %}
     - name: "Maximum Incoming Watts Back"
       unique_id: maximum_incoming_watts_back
       state: >-
          {% set old_value = states('sensor.maximum_incoming_watts_back')|float(default=0) %}
          {% set new_value = states('sensor.lux_solar_output_array_1_live')|float(default=0) %}
          {% if new_value > old_value %}
            {{ new_value }}
          {% else %}
            {{ old_value }}
          {% endif %}

This is the code suggested on the Home Assistant Community. These values do stick on a restart. If you already have a template section in your configuration.yaml, you won’t need the first line. This code also improves how the sensors work. Rather than check to see if the value is larger than the previous value, it uses the max statement.

template:
  - trigger:
      - platform: state
        entity_id:
          - sensor.lux_solar_output_live
          - sensor.maximum_incoming_watts_combined
        to:
    sensor:
      - name: "Maximum Incoming Watts Combined"
        unique_id: maximum_incoming_watts_combined
        state: >-
           {{ [states('sensor.maximum_incoming_watts_combined')|float(0),
             states('sensor.lux_solar_output_live')|float(0)] | max }}
  - trigger:
      - platform: state
        entity_id:
          - sensor.lux_solar_output_array_2_live
          - sensor.maximum_incoming_watts_front
        to:
    sensor:
      - name: "Maximum Incoming Watts Front"
        unique_id: maximum_incoming_watts_front
        state: >-
           {{ [states('sensor.maximum_incoming_watts_front')|float(0),
             states('sensor.lux_solar_output_array_2_live')|float(0)] | max }}
  - trigger:
      - platform: state
        entity_id:
          - sensor.lux_solar_output_array_1_live
          - sensor.maximum_incoming_watts_back
        to:
    sensor:
      - name: "Maximum Incoming Watts Back"
        unique_id: maximum_incoming_watts_back
        state: >-
           {{ [states('sensor.maximum_incoming_watts_back')|float(0),
             states('sensor.lux_solar_output_array_1_live')|float(0)] | max }}

I then made this card with the custom bar card

Custom Bar Card reporting the maximum watts as of 9 May 2023

Custom Bar Card reporting the maximum watts as of 9 May 2023

This is the YAML for this card

entities:
  - entity: sensor.maximum_incoming_watts_combined
    name: Max Incoming Watts
    max: 5600
    unit_of_measurement: Watts
  - entity: sensor.maximum_incoming_watts_front
    name: Max Incoming Watts Front
    max: 3200
    unit_of_measurement: Watts
  - entity: sensor.maximum_incoming_watts_back
    name: Max Incoming Watts Back
    max: 2400
    unit_of_measurement: Watts
title: Incoming Watts
type: custom:bar-card
 
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

Setting overnight battery usage start time - Updated

Next
Next

April’s Solar Generation and Export Numbers