archef2000 / homeassistant-upsplus

Home Assistant integration for the 52PI UPS
8 stars 1 forks source link

shutdown issue and error message #5

Closed marcsauter75 closed 1 month ago

marcsauter75 commented 3 months ago

Hi, I configured automation to shutdown and send me telegram message on 30% Battery. But I have the problem that this happen also some times when power supply is connected normaly. Any Idea on this or do I have any miss configurations ? I changed it for now on "Battery Voltage to <4V" hope that helps

Also I have this error message in the logs: Logger: homeassistant.helpers.entity Quelle: helpers/entity.py:945 Erstmals aufgetreten: 09:24:17 (26 Vorkommnisse) Zuletzt protokolliert: 10:02:37

Update for sensor.ups_accumulated_running_time fails Update for sensor.ups_input_report_voltage fails Update for sensor.ups_micro_usb_voltage fails Update for sensor.ups_battery_empty_voltage fails Update for sensor.ups_running_time fails Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 945, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1262, in async_device_update await self.async_update() File "/config/custom_components/upsplus/sensor.py", line 69, in async_update state = read_buff(self._bus, *self._entity.get("index")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/upsplus/battery.py", line 31, in read_buff result = bus.read_byte_data(DEVICE_ADDR, index1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/smbus2/smbus2.py", line 433, in read_byte_data ioctl(self.fd, I2C_SMBUS, msg) OSError: [Errno 5] I/O error

archef2000 commented 3 months ago

Do you see the values of

sensor.ups_accumulated_running_time
sensor.ups_input_report_voltage
sensor.ups_micro_usb_voltage
sensor.ups_battery_empty_voltage
sensor.ups_running_time

being reported correctly or are they missing sometimes/completely?

What version of HA are you using?

What sensor are you using for "30% Battery" ?

What Firmware version are you using ?

marcsauter75 commented 3 months ago

hi

yes - sensor.ups_accumulated_running_time yes - sensor.ups_input_report_voltage yes - sensor.ups_micro_usb_voltage yes - sensor.ups_battery_empty_voltage yes - sensor.ups_running_time

being reported correctly or are they missing sometimes/completely?

need to check this ....

What version of HA are you using? newest 2024.3.1

using UPS battery capacity

firmware: 10

archef2000 commented 3 months ago

Ok with "missing sometimes/completely" I mean in the history do you see unregular steps in sensor.ups_accumulated_running_time

And what type of are you running? (Core/Supervised/OS)

In the history is the "UPS battery capacity" sensor below 30% sometimes?

marcsauter75 commented 3 months ago

Supervisor 2024.03.0 Operating System 12.1 Frontend 20240307.0

Below 30% then i had a shutdown. As I said I changed it now to lower 4v for >20s then shutdown. Cause never seen in history voltage lower 4v. I will view capacity over next days...

what i have seen some peek where % is going to 125 or 300 or something over 100

archef2000 commented 3 months ago

you can also see the capacity in the history

archef2000 commented 3 months ago

Maybe also update your UPS. docs

marcsauter75 commented 3 months ago
image
archef2000 commented 3 months ago

Yeah that should definitely not happen please try updating the UPS.

marcsauter75 commented 3 months ago

ok will try it soon, takes time cause the raspberry is in my caravan ;)

archef2000 commented 3 months ago

Ok be sure to have a backup of the PI just in case anything goes wrong.

Lord-Memester commented 1 month ago

ok will try it soon, takes time cause the raspberry is in my caravan ;)

did you update it? did that fix it?

archef2000 commented 1 month ago

Do you have the same error? Also with 0% capacity and the error message?

Lord-Memester commented 1 month ago

Do you have the same error? Also with 0% capacity and the error message?

Maybe, it would seem I have a very similar error.

Source: helpers/entity.py:950
First occurred: May 24, 2024 at 3:48:57 PM (758 occurrences)
Last logged: 11:42:02 AM

Update for sensor.ups_processor_voltage fails
Update for sensor.ups_micro_usb_voltage fails
Update for sensor.ups_battery_capacity fails
Update for sensor.ups_restart_countdown fails
Update for sensor.ups_sampling_period fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 950, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1293, in async_device_update
    await self.async_update()
  File "/config/custom_components/upsplus/sensor.py", line 69, in async_update
    state = read_buff(self._bus, *self._entity.get("index"))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/upsplus/battery.py", line 35, in read_buff
    result = result | bus.read_byte_data(DEVICE_ADDR, index) << (8 * i)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/smbus2/smbus2.py", line 433, in read_byte_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 5] I/O error

I intermittently get a good reading for each sensor, but have only recently had this issue of getting nothing at times. Throughout my entire use of this integration, I have had instances of enormously incorrect readings, though I cannot say if this is a result of the integration or if it is to do with the actual data the UPS transmits.

For example, the battery capacity sensor: image and the battery temperature sensor: image both have insane spikes which make historical data nearly impossible to see, and tend to be really harmful to the accuracy of the moving averages depicted in things like the line graph cards. This happens with all sensors.

archef2000 commented 1 month ago

Could you tell me your UPS firmware version?

Lord-Memester commented 1 month ago

Could you tell me your UPS firmware version?

I don't know off the top of my head, I'll have to look up how to check.

Lord-Memester commented 1 month ago

Could you tell me your UPS firmware version?

Integration says it's version 10, same as the other person having errors.

archef2000 commented 1 month ago

It is in my integration in the device info.

Lord-Memester commented 1 month ago

It is in my integration in the device info.

Ah, thank you!

Firmware: 10

archef2000 commented 1 month ago

Latest is 15 or 16 so try updating. https://github.com/archef2000/homeassistant-upsplus/blob/main/docs.md#updating-the-ups

Lord-Memester commented 1 month ago

Latest is 15 or 16 so try updating. https://github.com/archef2000/homeassistant-upsplus/blob/main/docs.md#updating-the-ups

I've been trying, but when I press "Call Service" it says Failed to call service upsplus.update. Unknown error if I have all the checks on the checklist checked. If I don't have them all checked, it only returns

success: false
error: Please finish the preperation

This is what I submit: image

archef2000 commented 1 month ago

Do you see something in the log? Have you done all steps in the doc?

Lord-Memester commented 1 month ago

Do you see something in the log? Have you done all steps in the doc?

I did everything that the doc explicitly says to do, but got stuck at the updating service call for obvious reasons, so no step past that. Some logs:

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:501
First occurred: 2:01:19 PM (4 occurrences)
Last logged: 2:09:40 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: [Errno 121] Remote I/O error
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 501, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/upsplus/__init__.py", line 79, in update
    ups_manager = UPSManager()
                  ^^^^^^^^^^^^
  File "/config/custom_components/upsplus/battery.py", line 23, in __init__
    self.sw_version = read_buff(self.bus,40,41)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/upsplus/battery.py", line 31, in read_buff
    result = bus.read_byte_data(DEVICE_ADDR, index1)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/smbus2/smbus2.py", line 433, in read_byte_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error
Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/upsplus/battery.py:31
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 2:01:19 PM (4 occurrences)
Last logged: 2:09:40 PM

[547680825280] Error handling message: Unknown error (unknown_error) Meme from fe80::1d3:a2a5:8bb7:fb21 (Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0)
[547605170624] Error handling message: Unknown error (unknown_error) Meme from fe80::1d3:a2a5:8bb7:fb21 (Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 793, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1731, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 503, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 533, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 501, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/upsplus/__init__.py", line 79, in update
    ups_manager = UPSManager()
                  ^^^^^^^^^^^^
  File "/config/custom_components/upsplus/battery.py", line 23, in __init__
    self.sw_version = read_buff(self.bus,40,41)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/upsplus/battery.py", line 31, in read_buff
    result = bus.read_byte_data(DEVICE_ADDR, index1)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/smbus2/smbus2.py", line 433, in read_byte_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error
archef2000 commented 1 month ago

Plaese check that all pins make good contact.

Lord-Memester commented 1 month ago

Plaese check that all pins make good contact.

They all look good to me. Is there anything else?

archef2000 commented 1 month ago

And you powered it down completly battery and cord?

Lord-Memester commented 1 month ago

And you powered it down completly battery and cord?

Yes. I removed the batteries and unplugged the pi (in the correct order, of course) after shutting it down.

archef2000 commented 1 month ago

They there would be the manual way to run the script from https://github.com/geeekpi/upsplus

Lord-Memester commented 1 month ago

They there would be the manual way to run the script from https://github.com/geeekpi/upsplus

I keep getting this error when running the script via python3 OTA_firmware_upgrade.py:

Traceback (most recent call last):
  File "/root/upsplus/OTA_firmware_upgrade.py", line 19, in <module>
    bus = smbus2.SMBus(DEVICE_BUS)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/smbus2/smbus2.py", line 280, in __init__
    self.open(bus)
  File "/usr/lib/python3.12/site-packages/smbus2/smbus2.py", line 310, in open
    self.fd = os.open(filepath, os.O_RDWR)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 1] Operation not permitted: '/dev/i2c-1'
archef2000 commented 1 month ago

Have you enabled i2c via raspi-config? Does the device i2c-1 exist? Maybe try sudo.

Lord-Memester commented 1 month ago

Have you enabled i2c via raspi-config? Does the device i2c-1 exist? Maybe try sudo.

Not via raspi-config. I used the HassOS I2C Configurator. Checking home assistant's hardware, I see that i2c-1 seems to exist. image

archef2000 commented 1 month ago

And with sudo?

Lord-Memester commented 1 month ago

And with sudo?

Same thing, just about.

With sudo python3 OTA_firmware_upgrade.py:

Traceback (most recent call last):
  File "/root/upsplus/OTA_firmware_upgrade.py", line 19, in <module>
    bus = smbus2.SMBus(DEVICE_BUS)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/smbus2/smbus2.py", line 280, in __init__
    self.open(bus)
  File "/usr/lib/python3.12/site-packages/smbus2/smbus2.py", line 310, in open
    self.fd = os.open(filepath, os.O_RDWR)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 1] Operation not permitted: '/dev/i2c-1'
archef2000 commented 1 month ago

Load up an sd card via RPI-OS and try it with that

Lord-Memester commented 1 month ago

Load up an sd card via RPI-OS and try it with that

In what sense? Install home assistant on the new card or just do it in RPI-OS?

archef2000 commented 1 month ago

Just with RPI-OS without HA.

Lord-Memester commented 1 month ago

Just with RPI-OS without HA.

Alright. Might not be possible, since most of the SD cards I have are either corrupted or historically unreliable. The definitely working ones are all slotted into Pi's, but I'll see if I get lucky.

Lord-Memester commented 1 month ago

The update appears to have been successful! The version is now reported to be 14. I suppose I got lucky. image

Interestingly, the integration startup times show the 52PI UPS integration starting -3.03 seconds before the rest. image

That aside, it looks like the errors have also stopped. I am getting regular readings again. Wildly incorrect readings have yet to show up, though given their irregularity that may simply be a matter of time.

Lord-Memester commented 1 month ago

Around 8pm on May 25th was when I updated the UPS's firmware from version 10 to version 14. This is important because it reveals the huge improvement in the lack of abnormal spikes when looking at the graphs of the data. (I'm not showing all the graphs here, just enough to illustrate my point.)

image image image image image

And looking in the logs, I haven't seen any errors reported by your UPS integration since then. Thank you!

archef2000 commented 1 month ago

Ok then I will close this issue for now. If you or @marcsauter75 have any more problems feel free to comment or create a new issue. Would just like to know why the update function is not working. Could you now tell me your firmware version again please.

Lord-Memester commented 1 month ago

Ok then I will close this issue for now. If you or @marcsauter75 have any more problems feel free to comment or create a new issue. Would just like to know why the update function is not working. Could you now tell me your firmware version again please.

I edited my comment to include the firmware version. I hope that's what you meant.

archef2000 commented 1 month ago

Yeah thx