korylprince / hassio-apcupsd

An apcupsd Hass.io add-on
MIT License
52 stars 20 forks source link

ERROR, when battery goes below X minutes time remaining #2

Closed andreasfromch closed 6 years ago

andreasfromch commented 6 years ago

Hi @korylprince,

I’ve a new question, when the remaining time of the battery goes below 10 minutes ("key": "MINUTES ", "val": "10") I get the errors in the log file extract below (Currently no apc ups automations are configured). Maybe you could help me again?

Regards,

Andreas

2017-12-20 15:38:39 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_total_time_on_battery fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(*args, *kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again 2017-12-20 15:38:44 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_startup_time fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(self.args, self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(*args, **kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again

korylprince commented 6 years ago

socket.gaierror: [Errno -3] Try again

That's strange. That indicates that the home assistant docker container can't resolve the a722577e-apcupsd hostname.

My initial assumption is the apcupsd container is dying for some reason. When you start getting this error again, go to the Hass.io panel and see if the apcupsd add-on is running. Also see if it's output any log messages.

I'll see if I can replicate this later this week.

andreasfromch commented 6 years ago

I can reproduce this error. After I got it, I have to start the “APC UPS Daemon” again. It seems that it has crashed. After remove the power from the ups I get immediately the following message: /etc/apcupsd/onbattery: line 18: mail: not found

Please let me know if you need any more information.

korylprince commented 6 years ago

Okay, so the mail: not found line is there because there is no mail package set up or included in the docker image.

For now, I've just placed a dummy mail command in the docker image.

I'm, unfortunately, unable to replicate your issue with version 1.0 or 1.2. From your description, it sounds like the apcupsd daemon itself is crashing, but I can't get that to happen.

I did realize that beyond the startup version line, apcupsd logs everything to syslog. So I've added a syslog server that logs to stdout to the docker image so you'll see the messages in the Hass.io log for the add-on, even if the container dies. If it does die, check the logs before starting it again, as starting it through Hass.io causes a new container to be created, losing the old logs.

So update to the new version, and see if you can replicate the issue again. If you can, check to see if any other messages are logged on the Hass.io add-on page and report them back here.

If you're not seeing 1.2, try removing the add-on and repository and reinstalling. (I rebased the repo and had divergent branches which might cause Hass.io to not update properly. I'm pretty sure I've fixed it, though, so you shouldn't have to do this.)

andreasfromch commented 6 years ago

Thank you again for the support! The mail: not found line has gone.

The main problem still exists. After the voltage has gone below "key": "MINUTES ", "val": "10", the process gets stopped and I have to restart it agin. Here are the messages I get:

starting version 3.2.4 Dec 21 07:49:24 a722577e-apcupsd syslog.info syslogd started: BusyBox v1.27.2 Dec 21 06:49:24 a722577e-apcupsd daemon.notice apcupsd[10]: apcupsd 3.14.14 (31 May 2016) unknown startup succeeded Dec 21 06:49:24 a722577e-apcupsd daemon.info apcupsd[10]: NIS server startup succeeded Dec 21 06:54:12 a722577e-apcupsd daemon.crit apcupsd[10]: Power failure. Dec 21 06:54:14 a722577e-apcupsd daemon.alert apcupsd[10]: Power is back. UPS running on mains. Dec 21 06:54:17 a722577e-apcupsd daemon.crit apcupsd[10]: Power failure. Dec 21 06:54:23 a722577e-apcupsd daemon.crit apcupsd[10]: Running on UPS batteries. Dec 21 06:57:04 a722577e-apcupsd daemon.alert apcupsd[10]: Reached remaining time percentage limit on batteries. Dec 21 06:57:04 a722577e-apcupsd daemon.alert apcupsd[10]: Initiating system shutdown! Dec 21 06:57:04 a722577e-apcupsd daemon.alert apcupsd[10]: User logins prohibited

I think it is stopped (has crashed) after the last message. Below is tagin a part of the main log, but I think there are still the same messages.

2017-12-21 07:57:50 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_load fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(*args, *kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again 2017-12-21 07:57:55 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_status fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(self.args, self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(*args, kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again 2017-12-21 07:58:00 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_total_time_on_battery fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, *self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(args, kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again 2017-12-21 07:58:05 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_time_left fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(*args, *kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again 2017-12-21 07:58:10 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_battery fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(self.args, self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(*args, kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again 2017-12-21 07:58:15 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ups_time_on_battery fails Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state yield from self.async_device_update() File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update yield from self.hass.async_add_job(self.update) File "/usr/lib/python3.6/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup future.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, *self.kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/apcupsd.py", line 178, in update if self.type.upper() not in self._data.status: File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 80, in status self.update() File "/usr/lib/python3.6/site-packages/homeassistant/util/init.py", line 306, in wrapper result = method(args, kwargs) File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 90, in update self._status = self._get_status() File "/usr/lib/python3.6/site-packages/homeassistant/components/apcupsd.py", line 85, in _get_status return self._parse(self._get(host=self._host, port=self._port)) File "/usr/lib/python3.6/site-packages/apcaccess/status.py", line 37, in get sock.connect((host, port)) socket.gaierror: [Errno -3] Try again

korylprince commented 6 years ago

What's happening is apcupsd is trying to shutdown the system, but it can't do that since it's in a docker container.

If I'm reading the source right, apcupsd terminates itself after attempting the shutdown. Since apcupsd is exec'ed in the init script for the container, the whole container stops once the apcupsd process stops.

So what I plan to do in the 1.3 release (tonight, hopefully) is to replace poweroff and reboot with scripts that tell Hass.io to do those actions on the actual device. So if apcupsd tries to shutdown, your device will actually shutdown.

So my question is, what behavior are you expecting? That it actually shuts down the device?

andreasfromch commented 6 years ago

Before I found your component, I had a Windows Server connected to the ups. When the time remaining fell below a certain value the ups started a script which, shut down two ESXi servers. That’s more or less what I want to do. When the remaining time falls below a given value or the remaining percentage of the battery power goes below a given value I want to make an ssh connection from the Raspberry Pi to the ESXi servers for shutting them down.

korylprince commented 6 years ago

Okay, I will add the ability to add custom event scripts as described here.

You might also want to consider the master/slave approach with apcupsd. You can install apcupsd on your two ESXi servers and point them to your Hass.io instance. That way you can configure them separately.

korylprince commented 6 years ago

Version 1.3 is out now. Please check out the updated README, especially the Host Control and the Advanced Configuration sections.

I think this will solve your issues so I'm going to close this. If you're still having issues, feel free to reopen this issue.

andreasfromch commented 6 years ago

@korylprince Thank you!