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

[request] Add power consumption for switchboxD device to HA integration #137

Closed
shibby20 opened this issue Aug 24, 2022 · 23 comments
Closed

Comments

@shibby20
Copy link

API for switchboxD (api/relay/extended/state) already return activePower and powerConsumption value. Can we have those values in homeassinstant (propably as another entries)? It will be nice to use it in Energy dashboard of Home Assistant.

@riokuu
Copy link
Contributor

riokuu commented Aug 29, 2022

Hi @shibby20 according to documentation there is sensor entity that would fit this case. Thanks for your input. BR

@shibby20
Copy link
Author

shibby20 commented Sep 9, 2022

In the best way i can use REST API and parse json result to get those two information. But better solution will be add this to blebox integration. At the moment integration create only switch entities for switchBoxD. There is no "energy" information or even atributes for entity.

@shibby20
Copy link
Author

Witaj @riokuu. Widziałem, że pewne ruchy w kierunku mojej propozycji zostały poczynione (added: Energy sensor class for power consumption tracking). Ale mimo, iż HA korzysta już z uniapi 2.1.4 to wciąż nie widzę encji energii dla switchboxów. To jeszcze nie zostało ukończone? czy może powinienem usunąć switchboxy z HA i dodać je jeszcze raz by nowe encje się potworzyły?

Pozdrawiam

@riokuu
Copy link
Contributor

riokuu commented Feb 16, 2023

@shibby20, tak blebox_uniapi przekazuje już odpowiednie encje do HA. Zmiany w HA przedstawiamy jedna po drugiej, w tym momencie czekam na wprowadzenie obsługi lameli. Kod dla zużycie energii czeka na lokalnym repo, aż wcześniejsze zmiany zostaną wciągnięte.

@shibby20
Copy link
Author

@riokuu rozumiem, że czekamy na ten commit?
home-assistant/core#90516

Zwykle tak długo to trwa? Czy da się to jakoś przyśpieszyć?
Pozdrawiam.

@riokuu
Copy link
Contributor

riokuu commented Apr 25, 2023

@shibby20
Niestety tak to wygląda, poniżej flow:
https://developers.home-assistant.io/docs/review-process/
Pozdrawiam

@shibby20
Copy link
Author

shibby20 commented May 5, 2023

@riokuu sorry że tak dopytuję ale bardzo mi zależy na tym PR. Nie musisz czasem tego "pchnąć"?

obraz

@riokuu
Copy link
Contributor

riokuu commented May 9, 2023

Nie

@shibby20
Copy link
Author

shibby20 commented Jun 10, 2023

@riokuu nie chcąc już dłużej czekać na akceptację PR przez HA dodałem sobie go ręcznie. Encje mi się pojawiły ale widzę jeden problem logiczny. Otóż encje które integracja tworzy są typu "total", ponadto ich licznik resetuje się co godzinę. Taka encja jest niezdatna do użycia w module "energia". Tam encja musi być typu "total_increasing" i licznik nigdy nie może być resetowany.

Na zwykłym wykresie widać pobór i pokrywa się on ze wskazaniami w aplikacji wbox
obraz

Ale zużycie w module energii jest widoczne tylko do wyzerowania licznika czyli przez godzinę, a później
obraz

bo encje nie są typu "total_increasing".

@riokuu
Copy link
Contributor

riokuu commented Jun 30, 2023

@shibby20 dzięki za podpowiedź, wybacz za opóźnienie w odpowiedzi.
To najpewniej by wyszło przy review. Wypchnąłem tę poprawkę do brancha.
Rozumiem że teraz korzystasz z własnej "instancji".
I te zmiany ręcznie copy-paste czy rebase swojej kopii?
Pozdrawiam

@shibby20
Copy link
Author

shibby20 commented Jul 3, 2023

to copy-paste commitów z oczekującego na accept PR i zwyczajnie nie podnoszę póki co HA do wyższej wersji by nie nadpisać zmian. Póki co by osiągnąć to co potrzebuję utworzyłem "pomocnika" typu "Licznik mediów" z zaznaczoną opcją "okresowe resetowanie". Dzięki temu mam licznik "total_increasing" na podstawie encji "power consumption" z integracji bleboxa

obraz

i taką encję mogę użyć do modułu "energia" (przykładowo zeszły tydzień)
obraz

W wolnej chwili sprawdzę nowe zmiany czy liczą poprawnie i dam znać :)

@shibby20
Copy link
Author

shibby20 commented Jul 4, 2023

Sprawdziłem twoją poprawkę. Z tego co widziałem zmieniłeś tylko typ encji z total na total_increasing
obraz

Niestety to nie wystarczy, bo encja nadal się resetuje :/ a jej licznik powinien stale rosnąć (jak licznik prądu od energetyki). Czyli nadal muszę używać pomocnika.

Encja z blebox
obraz

Pomocnik bazujący na encji bleboxa
obraz

Jak to duży problem to może niech już tak zostanie (w sumie chyba trzeba by typ zmienić spowrotem na total), tyle że tylko "wtajemniczeni" będą wiedzieli że trzeba ustawić pomocnika by można było używać go w module Energy.

@shibby20
Copy link
Author

@riokuu nie wiem czy to traktować jako błąd bo może to być powiązane z tym, że HA jeszcze nie dodało ostatniego PR do proda (nie wgłębiałem się w to co on wnosi prócz tego że podnosi wersję uniapi) ale po wymuszeniu wersji 2.2.0 w manifeście pojawiły mi się encje powerConsumption ale też przy przełączaniu switchboxa lub switchboxD dostaję błąd:
return product.follow(product.last_data, method)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/blebox_uniapi/box.py", line 327, in follow
    raise JPathFailed(
blebox_uniapi.error.JPathFailed: item 'powerMeasuring' not among ['relays'] at 'powerMeasuring/powerConsumption/[0]/value' within '''{'relays': [{'relay': 0, 'state': 0}]}''' 

mimo to switch się przełącza poprawnie. Po prostu w logach sypie errorem.

@shibby20
Copy link
Author

shibby20 commented Nov 16, 2023

home-assistant/core#103421

kiedy można liczyć na rozwiązanie problemu? Musiałem cofnąć się do wersji październikowej, bo na najnowszej przez te błędy w logach wiele automatyk w Nodered przestało mi działać - sypało błędami API i procesy nie wykonywały się poprawnie, np tam gdzie sprawdzam czy światło jest zapalone zamiast zwracać mi on/off to dostawałem API error...

@lukaszgithub
Copy link

+1
Currently for all automations using blebox i need to push blebox activity to the end of the scripts to avoid errors in the middle of the scripts and to make automations work again.

@Rexluu
Copy link

Rexluu commented Jan 9, 2024

Temporary solution for switchBox family in HA:

  • remove device with issue in HA
  • turn off power measurement in settings in wBox app
  • add switch again to HA

@swistakm
Copy link
Contributor

EN: I have a PR (#152) with small fix that should resolve issues with errors being reported when toggling switchboxD relays (as complained by @shibby20). I am also verifying if power consumption for switchboxD works as expected. If not, I will look into a fix in a separate PR. Once done and released I will submit a PR to HA core to include new version with my fixes.

I've also built a small device simulator that should be helpful in diagnosing issues and testing integration with HA. It is still closed-source but I will try to publish it soon in separate repo.

PL: Zgłosilem PR (#152) z małą poprawką która powinna rozwiązać problem z błędami raportowanymi przy przełączaniu przekaźników (wspomniane przez @shibby20). Przyjrzę się samej funkcjonalności mierzenia zużycia energii bo nie wiem jeszcze jak to działa. Jak znajdę jakieś babole to postaram się je naprawić w osobnych PR-kach. Jak już wszystko będzie wypuszczone to zgłoszę osobny PR w HA core aby dołączyć najnowszą wersję uniapi z moimi fixami.

Na boku buduję mały symulator do urządzeń który może być pomocny przy diagnozowaniu takich problemów i testowaniu integracji z HA. Mam to jeszcze w prywatnym repo ale postaram się to upublicznić niebawem.

PS. Zrobiło się tu multi-języcznie. Napisałem w dwóch językach bo dyskusja zaczęła się po angielsku, a potem zeszła na PL. Dalej będę odpowiadał po angielsku.

@shibby20
Copy link
Author

shibby20 commented Jan 17, 2024

@swistakm after applying your changes i have new errors

2024-01-17 08:08:37.229 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Przedpokój Światło (switchBoxD#0.relay_0)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Lewe', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Prawe', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:37.229 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Pokój Światło (switchBoxD#0.relay_0)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Małe ', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Duże ', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:37.244 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Łazienka Światło (switchBoxD#0.relay_1)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Główne', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Lustro', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:37.247 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Przedpokój Światło (switchBoxD#0.relay_1)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Lewe', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Prawe', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:37.247 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Pokój Światło (switchBoxD#0.relay_1)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Małe ', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Duże ', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:42.222 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Przedpokój Światło (switchBoxD#0.relay_0)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Lewe', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Prawe', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:42.225 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Łazienka Światło (switchBoxD#0.relay_0)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Główne', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Lustro', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:42.228 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Pokój Światło (switchBoxD#0.relay_0)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Małe ', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Duże ', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}''' 2024-01-17 08:08:42.240 ERROR (MainThread) [homeassistant.components.blebox] Updating 'Przedpokój Światło (switchBoxD#0.relay_1)' failed: unexpected item type: 'value' not in: [{'periodS': 3600, 'value': 0.0, 'state': 4}] at 'powerMeasuring/powerConsumption/value' within '''{'relays': [{'relay': 0, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Lewe', 'iconSet': 0}, {'relay': 1, 'state': 0, 'stateAfterRestart': 0, 'defaultForTime': 0, 'name': 'Prawe', 'iconSet': 0}], 'powerMeasuring': {'enabled': 1, 'powerConsumption': [{'periodS': 3600, 'value': 0.0, 'state': 4}]}, 'sensors': [{'type': 'activePower', 'value': 0, 'trend': 0, 'state': 4}]}'''

i had to revert all changes and back to HA 2023.10.x

@swistakm
Copy link
Contributor

ohh, I've misread the API spec for SwitchboxD 🤦

Now I know where's the problem. Thanks @shibby20 for the test! Without it I would be able to catch it!

@swistakm
Copy link
Contributor

OK, @shibby20 I'm getting better understanding of the library. Issue wasn't exactly with the manifest (although it was missing latest 20200831 version) but with data race when relays were toggled. Essentially, toggling relay did clear sensor state and created an issue.

I have updated my PR #152 so that it solves the data race. It also does update boxtype manifests for all switchboxD API versions because these were not aligned with OpenAPI definitions found at https://technical.blebox.eu/

@shibby20
Copy link
Author

@swistakm do you have any idea how to fix power measuring?

#152 (comment)

@swistakm
Copy link
Contributor

Should be fixed in v2.2.1 (see #152) and is waiting to be incorporated in home-assistant/core as a dependency update. Will keep you posted.

@shibby20
Copy link
Author

shibby20 commented Mar 7, 2024

Finally we have it. Changes has been implemented into 2024.03 :D

https://www.home-assistant.io/changelogs/core-2024.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants