PV Power set to last positive value during night

Hi,

I’m new to hass and I could manage most of the configuration. I configured my pv panels sensor using MQTT protocol. Here are the settings my configuration.yml:

homeassistant:
  customize_glob:
    sensor.*_energy:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: measurement

  - platform: mqtt
    name: "pv_power"
    state_topic: "/sensor/XXXXXXXXX/gauge"
    unit_of_measurement: "W"
    value_template: "{{ value_json[1] }}"

  - platform: integration
    source: sensor.pv_power
    name: pv_energy
    unit_prefix: k
    round: 2

It works well and I can see correct values for both power (sensor.pv_power) and energy (sensor.pv_energy). However, I realized that both power energy are still giving positive value after sunset. It seems that the last recorded value is kept constant overnight:

How can I make sure that the power and energy sensor values are set to 0 overnight?

Thanks for you support :slight_smile: .

Best,
Greg

Add an availability template to each sensor.

Thanks for your suggestion. I looked at the documentation but I don’t really know what to do. Could you give me a bit of guidance on how to use availability template in my case, given this configuration?

homeassistant:
  customize_glob:
    sensor.*_energy:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: measurement

sensor:
  - platform: mqtt
    name: "power_import"
    state_topic: "XXXX/PUB/CH0"
    unit_of_measurement: "W"
    value_template: "{{ value_json.PI }}"

  - platform: integration
    source: sensor.power_import
    name: import_energy
    unit_prefix: k
    round: 2

  - platform: mqtt
    name: "power_export"
    state_topic: "XXXX/PUB/CH0"
    unit_of_measurement: "W"
    value_template: "{{ value_json.PE }}"

  - platform: integration
    source: sensor.power_export
    name: export_energy
    unit_prefix: k
    round: 2


  - platform: mqtt
    name: "pv_power"
    state_topic: "/sensor/XXXXX/gauge"
    unit_of_measurement: "W"
    value_template: "{{ value_json[1] }}"

  - platform: integration
    source: sensor.pv_power
    name: pv_energy
    unit_prefix: k
    round: 2

I also realized that the calculated exported energy “export_energy” also yields a weird behavior. It basically jumped this morning from 0 to 5,7kWh when my pv system started producing, which is quite unrealistic. Could it also be related with the missing availability template in each sensor?

What are the states of the sensors after sunset as shown in Developer Tools / States?

What are you using to measure these values?

What are the states of the sensors after sunset as shown in Developer Tools / States?

Here are the state and attributes for “pv_power” and “pv_energy” entities in the Developer Tools/States:

I see that the last MQTT message posted by my pv sensor for power is indeed [1643040924,17,"W"]. I guess I need to setup a logic that sets power to 0 after sunset or something like that?

What are you using to measure these values?

I basically have 3 sensors providing power measurements (W) that I read from my flukso MQTT broker. I have an energy integration setup for each of these sensors:

  1. Imported Power from the grid “import_power” sensor. I then use the energy integration to calculate imported energy to “sensor.import_energy”. Config:
  - platform: mqtt
    name: "power_import"
    state_topic: "XXXX/PUB/CH0"
    unit_of_measurement: "W"
    value_template: "{{ value_json.PI }}"

  - platform: integration
    source: sensor.power_import
    name: import_energy
    unit_prefix: k
    round: 2
  1. Exported energy to the grid “power_export”. Also with an integration for energy conversion to “export_energy”. Config:
  - platform: mqtt
    name: "power_export"
    state_topic: "XXXX/PUB/CH0"
    unit_of_measurement: "W"
    value_template: "{{ value_json.PE }}"

  - platform: integration
    source: sensor.power_export
    name: export_energy
    unit_prefix: k
    round: 2
  1. and finally, power produced by my PV system “pv_power”, also converted to energy with “sensor.pv_energy”. Config:
  - platform: mqtt
    name: "pv_power"
    state_topic: "/sensor/XXXXX/gauge"
    unit_of_measurement: "W"
    value_template: "{{ value_json[1] }}"

  - platform: integration
    source: sensor.pv_power
    name: pv_energy
    unit_prefix: k
    round: 2

Thanks
Greg

What is sending the messages to the broker?

Grid Power Import/Export messages (XXXX/PUB/CH0/PI and XXXX/PUB/CH0/PE topics) are send to my Flukso Broker using a LoWi3 device that is connected to the P1 port of my grid smart meter (Siconia T211).

The PV generation (Wh) is measured by a pulse counter that is connected to my Flukso meter. PV power is available on the Flukso broker in the /sensor/XXXXX/gauge message that I use in HA configuration. There is also the PV energy (in Wh) available on /sensor/XXXXX/gauge topic on the Flukso broker, but I’m not using it at the moment (the value of the gauge topic correspond to the total energy provided by my PV system for years and I didn’t know how to deal with that in HA).

I hope it clarifies my setup.

Thanks,
Greg