briancmpbll/home_assistant_custom_envoy

Power factor entities flood logbook

Closed this issue · 12 comments

I have enabled the power factor entities, but now they flood my log with seemingly every value change. I cannot seem to find a setting to prevent this from happening. Other entities do not do this. Am I doing something wrong or is this a bug? I tried to look in the source but I cannot find something wrong in the definition of these entities.

image

Hi @lucvandort, Power Factor is not different as the other entities, so would not expect this by default. Looking at the timestamps it's like 6-10 sec apart. Does that match your collection frequency?

Collection interval is set to 5 seconds yes (so that it is equal to the update frequency from my kWh-meter).

image

For what it is worth, this is the data I get from the envoy. Apparently the power factor cannot be determined accurately under all circumstances and then it reports -1. And in that period, no log entries are being added, but then again, there are also no value changes during that time. Every time the values change, they are being added to the log.

image

Guess what, looks like powerfactor is different somehow indeed. Fired up my simulator with forcing change to power factor and the log entries show. As you're the first one to report, it's either HA version related or not as popular as when it was requested. Which justifies the default hidden state. Well I'm rambling, on to finding why this happens.

afbeelding

I am on HA version 2024.5.5 (in a docker container on a Synology NAS). Have not seen this behaviour with other integrations.

I am somewhat of a (professional) power systems nerd, so that is why I set the update interval so short and enabled these entities. Can definitely imagine these entities are hardly ever used, disabled by default seems like a very sensible choice.

It seems specific for POWER_FACTOR. Tried various options, but only options that fixes it is to remove the device_class defenition.

To see if it solves the problem:

  • open /config/custom_components/enphase_envoy/const.py
  • find the power factor entry in there
  • change it by removing the device_class line and adding state_class to example below:
    SensorEntityDescription(
        key="pf",
        name="Power Factor",
        entity_registry_enabled_default=False,
        state_class=SensorStateClass.MEASUREMENT,
    ),
  • save the file
  • restart HA.

At this moment I have no idea why this specific device class for POWER_FACTOR that HA provides has this behavior or when this started.

        device_class=SensorDeviceClass.POWER_FACTOR,

It was tested when requested and added over a year ago, so something in the mean time changed.

Did a bit more testing and just adding state_class=SensorStateClass.MEASUREMENT while leaving device_class=SensorDeviceClass.POWER_FACTOR in is the better solution. The missing state_class was the issue al along.

    SensorEntityDescription(
        key="pf",
        name="Power Factor",
        device_class=SensorDeviceClass.POWER_FACTOR,
        state_class=SensorStateClass.MEASUREMENT,
        entity_registry_enabled_default=False,
    ),

I am somewhat of a (professional) power systems nerd, so that is why I set the update interval so short and enabled these entities.

There's also apparent and reactive data send by the Envoy. These currently have no HA entities, but adding as disabled is not too hard.

        "apparentEnergy" / "vahLifetime"
        "reactEnergyLagg" / "varhLagLifetime"
        "reactEnergyLead" / "varhLeadLifetime"
        "apparentPower" / "apprntPwr"
        "reactivePower" / "reactPwr"

Did a bit more testing and just adding state_class=SensorStateClass.MEASUREMENT while leaving device_class=SensorDeviceClass.POWER_FACTOR in is the better solution. The missing state_class was the issue al along.

    SensorEntityDescription(
        key="pf",
        name="Power Factor",
        device_class=SensorDeviceClass.POWER_FACTOR,
        state_class=SensorStateClass.MEASUREMENT,
        entity_registry_enabled_default=False,
    ),

This seems to work for the 3-phase power factor, to make it work for the individual phase power factors I added the state_class to these as well:

    SensorEntityDescription(
        key="pf_l1",
        name="Power Factor L1",
        device_class=SensorDeviceClass.POWER_FACTOR,
        state_class=SensorStateClass.MEASUREMENT,
        entity_registry_enabled_default=False,
    ),
    SensorEntityDescription(
        key="pf_l2",
        name="Power Factor L2",
        device_class=SensorDeviceClass.POWER_FACTOR,
        state_class=SensorStateClass.MEASUREMENT,
        entity_registry_enabled_default=False,
    ),
    SensorEntityDescription(
        key="pf_l3",
        name="Power Factor L3",
        device_class=SensorDeviceClass.POWER_FACTOR,
        state_class=SensorStateClass.MEASUREMENT,
        entity_registry_enabled_default=False,
    ),

Immediately all old logbook entries about power factor have dissappeared. So this seems to be the solution! Will keep an eye on in the coming days, but I guess this was it! Thanks a lot for figuring this out!

Ah good to hear. I'll add it to an update in the near future once you confirm it's stable.

Seems to be working fine, nothing to be found in the logbook anymore. Case closed I guess, thanks again!

Thanks for the feedback, good to hear its solved.