briancmpbll / home_assistant_custom_envoy

171 stars 76 forks source link

Power factor entities flood logbook #200

Closed lucvandort closed 4 days ago

lucvandort commented 2 weeks ago

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

catsmanac commented 2 weeks ago

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?

lucvandort commented 2 weeks ago

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

image

lucvandort commented 2 weeks ago

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

catsmanac commented 2 weeks ago

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

lucvandort commented 2 weeks ago

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.

catsmanac commented 2 weeks ago

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:

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

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.

catsmanac commented 2 weeks ago

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,
    ),
catsmanac commented 2 weeks ago

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"
lucvandort commented 2 weeks ago

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!

catsmanac commented 2 weeks ago

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

lucvandort commented 4 days ago

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

catsmanac commented 4 days ago

Thanks for the feedback, good to hear its solved.