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

Add plugin for piusv #981

Merged
merged 9 commits into from
Jan 13, 2025
Merged

Add plugin for piusv #981

merged 9 commits into from
Jan 13, 2025

Conversation

SergeoLacruz
Copy link
Contributor

This is for the piusv+.
The original SW for piusv+ is not up to date any longer. A open source version in C is available here:

https://github.com/dehapama/piupsmonitor-raspberrypi

The plugin communicates directly with the PIUSV via I2C. There is still some work to do but the major
functions are OK. Fine tuning is still needed.

@Morg42
Copy link
Member

Morg42 commented Dec 8, 2024

Anyone able to test this?

piusv/__init__.py Outdated Show resolved Hide resolved
@Morg42 Morg42 added this to the Version 1.12 milestone Dec 8, 2024
@wvhn
Copy link
Contributor

wvhn commented Dec 15, 2024

Do I need to install the new piupsmon version in order to run the plugin? I can test the plugin if it runs with the original versio n.

@SergeoLacruz
Copy link
Contributor Author

The plugin does not need any piupsmon. I communicates with piusv via I2C. You can disable piupsmon.

@wvhn
Copy link
Contributor

wvhn commented Dec 15, 2024

Thanks for the plugin! It has been on my to-do list for a long time but I'm not really familiar with Python (yet).

Configuration docs are missing but I got it running. Had to activate i2c in raspi-config and add the user "smarthome" to the "i2c" group.
Now I'm getting errors in the log every few seconds:

> Traceback (most recent call last):
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 659, in respond
>     self._do_respond(path_info)
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 718, in _do_respond
>     response.body = self.handler()
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/lib/encoding.py", line 223, in __call__
>     self.body = self.oldhandler(*args, **kwargs)
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cpdispatch.py", line 54, in __call__
>     return self.callable(*self.args, **self.kwargs)
>   File "/usr/local/smarthome/plugins/piusv/webif/__init__.py", line 109, in get_data_html
>     data['plugin_suspended'] = self.plugin.suspended
> AttributeError: 'piusv' object has no attribute 'suspended'

The Webif is working well, however. It would be nice to see the voltage / current values in their physical units and an explanation of the status code would be great.

Do I have to add database: yes myself to the struct "piusv_info_db"?

@SergeoLacruz
Copy link
Contributor Author

I added the missing status variable. Surprisingly I did not get this error.
The docu needs some work. You can create a visu panel like this:

grafik

The status value is the raw value from the piusv. You are right, it should be translated:
Bit 0 Micro-USB Power active
Bit 1 Uext Power active
Bit 2 Battery low
Bit 3 Battery charging
Bit 4 ?
Bit 5 Button 1 pressed
Bit 6 ?
Bit 7 ?

@wvhn
Copy link
Contributor

wvhn commented Dec 15, 2024

Starts now without error. Thanks!

  • items are accessible and provide data.

  • Looking into different docs I found on the internet the definitions of status bits seem to be:

    • Bit 0 External power supply
    • Bit 1 Power supply from battery

    So plausibility is given w/ status 9 and u_usb=100 / u_ext=5000

  • Poll interval seems to be quite long. No information available how poll interval can be configured

  • this should be moved to plugin config, too:
    # setup scheduler for device poll loop (disable the following line, if you don't need to poll the device. Rember to comment the self_cycle statement in __init__ as well)

  • automatic updates in web interface are not working. I always have to update manually. Update interval changes back to 30 sec if you try to change it

  • Is there a reason why battery voltage is v_batt and not u_batt like u_ext and u_rasp?

@SergeoLacruz
Copy link
Contributor Author

I added the webinterface update. The function was missing. v_batt it renamed to u_batt. The poll cycle can be configured using the poll_cycle parameter in the plugin config. This should be in the automatically generated docs. Anyhow I need to work on the documentation. Disableing the poll makes no sense. I will remove the comment.
There is still some work to do for the next release :-)

@wvhn
Copy link
Contributor

wvhn commented Dec 17, 2024

Super. Function is OK now.
Using u_batt instead of v_batt is not really important but may help avoiding surprises in visu configuration. Thanks for that.

Maybe it's worth noting: I tested on a Raspi 2 with 32bit Bullseye system and shNG 1.9.5.

From my point of view, the PR can be merged into develop.

@SergeoLacruz
Copy link
Contributor Author

Thanks for testing. I use a Pi4 with 64bit system.

@wvhn
Copy link
Contributor

wvhn commented Dec 18, 2024

grafik

What about this widget for visualization? I could upload it as plugin-specific widget.

@SergeoLacruz
Copy link
Contributor Author

SergeoLacruz commented Dec 19, 2024

Looks nice. Thanks for the contribution. I would use it :-)

@wvhn
Copy link
Contributor

wvhn commented Jan 2, 2025

I had some trouble with the table on small devices. This is now solved.
There is a PR into your repository which provides the widget in the required folder structure.

@SergeoLacruz
Copy link
Contributor Author

Is here still something to do?

@wvhn
Copy link
Contributor

wvhn commented Jan 10, 2025

I have been getting several errors during the day while I2C baud rate was still system default :

2025-01-10  01:08:26 ERROR    plugins.piusv       get_parameter: error writing to piusv
2025-01-10  02:56:38 ERROR    plugins.piusv       get_parameter: error reading to piusv
2025-01-10  03:33:02 ERROR    plugins.piusv       get_parameter: error reading to piusv
2025-01-10  08:38:23 ERROR    plugins.piusv       get_parameter: error writing to piusv
2025-01-10  08:58:37 ERROR    plugins.piusv       get_firmware: error reading to piusv
2025-01-10  08:58:37 WARNING  lib.item.item       Item usv.piusv_firmware: value "0" does not match type str. Via piusv None
2025-01-10  11:15:06 ERROR    plugins.piusv       get_status: error writing to piusv
2025-01-10  13:03:18 ERROR    plugins.piusv       get_parameter: error reading to piusv

Tests with baud rate 40000 are running now.
From my perspective, only documentation is missing but you mentioned there is still some work to do ;)

@SergeoLacruz
Copy link
Contributor Author

I am also running 40000. No errors here.
I would like to close this now.

@wvhn
Copy link
Contributor

wvhn commented Jan 13, 2025

Errors are gone after setting i2c baud rate to 40000.

@Morg42 : Plugin can be merged into develop

@Morg42 Morg42 merged commit 850341c into smarthomeNG:develop Jan 13, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants