Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

powerfox integration availability check #134785

Closed
Bertk opened this issue Jan 5, 2025 · 28 comments · Fixed by #136366
Closed

powerfox integration availability check #134785

Bertk opened this issue Jan 5, 2025 · 28 comments · Fixed by #136366
Assignees

Comments

@Bertk
Copy link

Bertk commented Jan 5, 2025

The problem

Thank you for the great integration unfortunately the stability of the powerfox is not very good. I do not know whether this is HW or API related but the entities sensor.stromzahler_energieverbrauch and sensor.stromzahler_energieeinspeisung sometimes are showing 0 values which is bad for state_class: "total_increasing".

Image

The energy dashboard will be useless for that day
Image

What version of Home Assistant Core has the issue?

core-2025.1.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

powerfox

Link to integration documentation on our website

https://www.home-assistant.io/integrations/powerfox

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

I switched back to my old configuration which uses workaround with availability setting e.g.

      - name: "PowerOpti usage total"
        unique_id: "poweropti_usage_total"
        device_class: "energy"
        state_class: "total_increasing"
        unit_of_measurement: "kWh"
        value_template: "{{ value_json.a_Plus }}"
        availability: "{{is_number(state_attr('sensor.poweropti_cloud', 'a_Plus')) and (state_attr('sensor.poweropti_cloud', 'outdated') == false) and (state_attr('sensor.poweropti_cloud', 'a_Plus')|round(0) > float(0))}}"
      - name: "PowerOpti production total"
        unique_id: "poweropti_production_total"
        device_class: "energy"
        state_class: "total_increasing"
        unit_of_measurement: "kWh"
        value_template: "{{ value_json.a_Minus }}"
        availability: "{{is_number(state_attr('sensor.poweropti_cloud', 'a_Minus')) and (state_attr('sensor.poweropti_cloud', 'outdated') == false) and (state_attr('sensor.poweropti_cloud', 'a_Minus')|round(0) > float(0))}}"
image
@home-assistant
Copy link

home-assistant bot commented Jan 5, 2025

Hey there @klaasnicolaas, mind taking a look at this issue as it has been labeled with an integration (powerfox) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of powerfox can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign powerfox Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


powerfox documentation
powerfox source
(message by IssueLinks)

@klaasnicolaas
Copy link
Member

klaasnicolaas commented Jan 5, 2025

The big question now is what makes it suddenly get 0 from the API, is anything of that reflected in the logs?

./Klaas

@Bertk
Copy link
Author

Bertk commented Jan 5, 2025

The home-assistant.log file has 123 lines with homeassistant.components.rest messages. I did not activate debug logging for any integration.

Snippet of the last occurrence with 0 value:

2025-01-05 17:01:13.220 ERROR (MainThread) [homeassistant.components.rest.data] Timeout while fetching data: https://backend.powerfox.energy/api/2/my/main/current?unit=kwh
2025-01-05 17:01:13.221 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2025-01-05 17:05:26.230 ERROR (MainThread) [homeassistant.components.rest.data] Timeout while fetching data: https://backend.powerfox.energy/api/2/my/main/current?unit=kwh
2025-01-05 17:05:26.231 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2025-01-05 18:00:34.233 ERROR (MainThread) [homeassistant.components.rest.data] Timeout while fetching data: https://backend.powerfox.energy/api/2/my/main/current?unit=kwh
2025-01-05 18:00:34.234 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2025-01-05 18:01:50.236 ERROR (MainThread) [homeassistant.components.rest.data] Timeout while fetching data: https://backend.powerfox.energy/api/2/my/main/current?unit=kwh
2025-01-05 18:01:50.237 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2025-01-05 18:02:10.206 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-05 18:02:30.226 ERROR (MainThread) [homeassistant.components.rest.data] Timeout while fetching data: https://backend.powerfox.energy/api/2/my/main/current?unit=kwh
2025-01-05 18:02:30.226 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data

image

@klaasnicolaas
Copy link
Member

It looks like a timeout has occurred, but that doesn't explain why the value jumps to 0. The coordinator will raise an UpdateFailed in these situations and that's a nice way to handle it.

The question is a bit what kind of data do we get from the API.

@alexhass
Copy link

alexhass commented Jan 5, 2025

Sound like my issue, too. But on my side it spikes to the current energy meter value of 19.000 kwh. This was the energy usage within 5 minutes based on the statistics. Really really wrong.

@Bertk
Copy link
Author

Bertk commented Jan 6, 2025

Actually both entities have this problem but not on every occurrence.
image
image

Debug logging does not add more information.

2025-01-06 02:01:47.204 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 02:01:47.204 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 15.003 seconds (success: False)
2025-01-06 02:02:47.855 INFO (MainThread) [homeassistant.components.powerfox] Fetching powerfox data recovered
2025-01-06 02:02:47.855 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 0.655 seconds (success: True)
...
2025-01-06 03:01:16.202 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 03:01:16.203 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 15.003 seconds (success: False)
2025-01-06 03:02:20.657 INFO (MainThread) [homeassistant.components.powerfox] Fetching powerfox data recovered
2025-01-06 03:02:20.657 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 4.458 seconds (success: True)
...
2025-01-06 04:02:40.207 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 04:02:40.208 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 15.005 seconds (success: False)
2025-01-06 04:03:40.322 INFO (MainThread) [homeassistant.components.powerfox] Fetching powerfox data recovered
2025-01-06 04:03:40.322 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 0.123 seconds (success: True)
...

All errors from debug logging

2025-01-05 21:01:09.201 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-05 23:01:53.203 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 00:02:12.202 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 02:01:47.204 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 03:01:16.202 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 04:02:40.207 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 05:00:58.202 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 07:01:39.204 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 08:02:08.202 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.

@Bertk
Copy link
Author

Bertk commented Jan 6, 2025

It looks like a timeout has occurred, but that doesn't explain why the value jumps to 0. The coordinator will raise an UpdateFailed in these situations and that's a nice way to handle it.

The question is a bit what kind of data do we get from the API.

I guess this happend "Empty reply found when expecting JSON data".

2025-01-06 03:01:16.202 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.
2025-01-06 03:01:16.203 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 15.003 seconds (success: False)
2025-01-06 03:01:23.298 ERROR (MainThread) [homeassistant.components.rest.data] Timeout while fetching data: https://backend.powerfox.energy/api/2/my/main/current?unit=kwh
2025-01-06 03:01:23.299 WARNING (MainThread) [homeassistant.components.rest.util] Empty reply found when expecting JSON data
2025-01-06 03:02:20.657 INFO (MainThread) [homeassistant.components.powerfox] Fetching powerfox data recovered
2025-01-06 03:02:20.657 DEBUG (MainThread) [homeassistant.components.powerfox] Finished fetching powerfox data in 4.458 seconds (success: True)

@klaasnicolaas
Copy link
Member

klaasnicolaas commented Jan 8, 2025

I have been running the integration on a test environment of Home Assistant for a few days now. Despite the fact that I often get a Timeout exception I can not reproduce the issue.

I guess this happend "Empty reply found when expecting JSON data".

This is from the REST integration, what if you disable it?

./Klaas

@Bertk
Copy link
Author

Bertk commented Jan 8, 2025

I will temporarily disable the REST integration and will reply Friday or Saturday.

@HonkXL
Copy link

HonkXL commented Jan 8, 2025

I can confirm this. The 0 comes from the API.

Before switching to powerfox integration I integrated it using rest and had exactly the same problem. Here the way I fixed it for me - this prevented my home assistant from getting confused data. Maybe anything like this should be added to the official integration:

`rest:

template:

  • sensor:
    • name: "Strom-aktuell"
      unit_of_measurement: "W"
      device_class: "power"
      state_class: "measurement"
      state: >
      {{ state_attr('sensor.poweropti', 'Watt') }}
    • name: "Strom-Bezug"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing"
      state: >
      {% set bezug = state_attr('sensor.poweropti', 'A_Plus') | float %}
      {% if bezug > 0 %}
      {{ bezug }}
      {% endif %}
    • name: "Strom-Einspeisung"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing"
      state: >
      {% set PV = state_attr('sensor.poweropti', 'A_Minus') | float %}
      {% if PV > 0 %}
      {{ PV }}
      {% endif %}`

@Bertk
Copy link
Author

Bertk commented Jan 10, 2025

@klaasnicolaas The error occurred again after disabling REST integration. Looks like the error frequency is lower than before.
This time there is no information from [homeassistant.components.powerfox] at 6am available in home-assistant.log file.

Stromzähler Energie-Dashboard

Snippet from home-assistant.log:

2025-01-10 06:05:10.114 WARNING (Recorder) [homeassistant.components.sensor.recorder] Entity sensor.pv_einspeisung_taglich from integration template has state class total_increasing, but its state is negative. Triggered by state -1606.901 with last_updated set to 2025-01-10T05:03:18.363038+00:00. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22
2025-01-10 08:00:13.285 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.solarman_pv1_power is taking over 10 seconds
2025-01-10 08:01:09.263 ERROR (MainThread) [homeassistant.components.powerfox] Error fetching powerfox data: Timeout occurred while connecting to Powerfox API.

Additional information:
image

@Bertk
Copy link
Author

Bertk commented Jan 15, 2025

Unfortunately the error still occurs and makes the energy dashboard useless. Looks like the error is not on client side.

Image

@klaasnicolaas
Copy link
Member

Could you maybe give me temporary access to your account, so I can debug more intensively? As long as I can't reproduce it, I can't really do anything more in this issue 🤷‍♂

You can send me an email for this (see github profile).

./Klaas

@Bertk
Copy link
Author

Bertk commented Jan 18, 2025

Sorry, but I will remove the Powerfox device on Monday. The problem is anyway created on the server reply. Yesterday I got a response for a service ticket from 1st January:

Image

Unfortunately, the availability is very bad and invalidates the energy dashboard metrics. There is no energy production during night time.

Image

I guess this happens whenever the connection is broken for a shorter period and the data is not available for the energy dashboard.

Image

@HonkXL
Copy link

HonkXL commented Jan 18, 2025

The solution would be really simple: if the value that is received is 0, just ignore it. Only write values > 0 to the database.

Example:
first value from API: 1.740
second value from API: 0 - this is wrong do not write
third value from API: 1.741 → if 2nd value was written, now the power consumtion is 3.481 kWh (wrong). If second value was ignored, the power consumption is 1 kWh. This is the correct value.

The 0 values are not really reproducable. On some days it works perfectly and on other days like yesterdays I had 3 times a 0 value.

If the 0s come, this is for all values of the counter....

@Bertk
Copy link
Author

Bertk commented Jan 18, 2025

The solution would be really simple: if the value that is received is 0, just ignore it. Only write values > 0 to the database.

Example: first value from API: 1.740 second value from API: 0 - this is wrong do not write third value from API: 1.741 → if 2nd value was written, now the power consumtion is 3.481 kWh (wrong). If second value was ignored, the power consumption is 1 kWh. This is the correct value.

The 0 values are not really reproducable. On some days it works perfectly and on other days like yesterdays I had 3 times a 0 value.

If the 0s come, this is for all values of the counter....

This is a workaround with a restriction. The reset of the energy sensor value is initiated with a “0” value from the electricity meter (state_class: total_increasing). This is required whenever the electricity meter is replaced.

@klaasnicolaas
Copy link
Member

I've first to determine in the API response that a 0 was actually sent as a value...

./Klaas

@alexhass
Copy link

alexhass commented Jan 18, 2025

Nice catch… that explains why I intermittently had 18.000kwh jumps within 5minutes…

If a new meter is installed, it may starts at 0, but it will increase soon and than still show up… just because 0,001 is more than 0. I guess counting will be fine… worst case the statistics are missing 0.001kwh.

@Bertk
Copy link
Author

Bertk commented Jan 19, 2025

This graph shows the reliability disaster. RIP Firefox device.

Image

@EmenefHA
Copy link

Hi,

have the same issues since a few days.

Can confirm this issue happened last year already after a maintenance.
I also used simon42 code and hat same issues like now happening again. Followed the hint here to use only values >0: https://community.simon42.com/t/komische-werte-auf-einmal-energie-dashboard-poweropti/30016/32 and it did resolve it.

Could that be also similar implemented here? Guess it makes sense not only for the power consumptions.

Thanks

@HonkXL
Copy link

HonkXL commented Jan 22, 2025

Today zeroes came at 08:15, 09:15, 10:15 and 11:15 so I had to fix the entries every time.
The solution would be quite easy: whe power consumtion value is zero, drop the data. If not, write it to db.

@klaasnicolaas
Copy link
Member

Could you maybe give me temporary access to your account, so I can debug more intensively? As long as I can't reproduce it, I can't really do anything more in this issue 🤷‍♂

You can send me an email for this (see github profile).

This offer still stands, without extensive testing I won't be working on a fix (how easy the fix would be). But I'm also on another similar problem and that is that the API suddenly sends a slightly lower value and then a higher like normal. Of course the state_class and long-term statistics do not like that 🤔

./Klaas

@bubffm
Copy link

bubffm commented Jan 22, 2025

I keep having these 0 value issues ever other day, sometimes multiple times daily, so I used the code suggested by @EmenefHA above in my "manual" Powerfox integration. Lets see how it works.

@HonkXL
Copy link

HonkXL commented Jan 22, 2025

Could you maybe give me temporary access to your account, so I can debug more intensively? As long as I can't reproduce it, I can't really do anything more in this issue 🤷‍♂
You can send me an email for this (see github profile).

you have mail :-)

@bubffm
Copy link

bubffm commented Jan 22, 2025

Today zeroes came at 08:15, 09:15, 10:15 and 11:15 so I had to fix the entries every time. The solution would be quite easy: whe power consumtion value is zero, drop the data. If not, write it to db.

I had the EXACT same timings today. Every time my counter-total (3800kWh) was added to my consumption. Expensive...

@klaasnicolaas
Copy link
Member

Currently working on a fix, just need to test it thoroughly to make sure it works.

./Klaas

@klaasnicolaas
Copy link
Member

The fix will be available from 2025.1.4.

./Klaas

@alexhass
Copy link

Kann der Fehler nicht auch mit den HT und NT Feldern auftreten?

@github-actions github-actions bot locked and limited conversation to collaborators Mar 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants