Greekworm UPS Hat

Hi,

Bought a Greekworm UPS HAT for the Raspberry Pi. Followed this guide to install it on a raspberry with a driver:
http://www.raspberrypiwiki.com/index.php/How_to_use_UPS_HAT_via_driver

Then made a custom python code:
raspiups.py

import sys
# import Raspi UPS Hat library
import raspiupshat

# init Raspi UPS Hat
raspiupshat.init();

# Get info
print raspiupshat.getsoc();

copy over the raspiupshat.so to the same folder.

in HA:

# Raspberry UPS HAT Battery
  - platform: command_line
    name: UPS HAT Battery
    command: "python /home/homeassistant/.homeassistant/python_scripts/raspiupshat.py"
    unit_of_measurement: "%"
    value_template: '{{ value | round(0) }}'
    scan_interval: 60

Sensor is now in HA, so you could make automations for it e.g. shutdown

2 Likes

I have one coming in the mail and was just starting to see how to get it to work with HA, but you beat me to it!
Will try this out first when it arrives. Thanks for sharing!

Great! Just keep in mind the advantages and disadvantages. Here is a great post of it by Simon:
https://brousant.nl/jm3/elektronica/104-geekworm-ups-for-raspberry-pi

I am busy with the automation to shutdown the host os (pi) when battery is empty but is not finished yet.

Okay… For me those are significant issues. Thanks again for this heads-up!

I have made the automations for it and tested it. Works perfect.

- alias: Warn when on Battery
  initial_state: 'on'
  trigger:
    platform: numeric_state
    entity_id: sensor.ups_hat_battery
    below: 90
    for:
     seconds: 30
  condition:
    condition: numeric_state
    entity_id: sensor.ups_hat_battery
    above: 1   #prevent false triggers when sensor is 0 or none
  action:
   - service: notify.yourdevice
     data_template:
       title: "Power loss"
       message: "Home Assistant is running on battery. Battery is {{ states.sensor.ups_hat_battery.state }} procent."

- alias: Shutdown when on Battery
  initial_state: 'on'
  trigger:
    platform: numeric_state
    entity_id: sensor.ups_hat_battery
    below: 20
    for:
     seconds: 30
  condition:
    condition: numeric_state
    entity_id: sensor.ups_hat_battery
    above: 1   #prevent false triggers when sensor is 0 or none
  action:
   - service: notify.yourdevice
     data_template:
       title: "Powerloss - shutting down"
       message: "Home Assistant is being shutdown! Battery is {{ states.sensor.ups_hat_battery.state }} procent."
   - service: shell_command.shutdown_host_os

shell_command.yaml:

 shutdown_host_os: sudo shutdown -h

Nice work! Can’t wait to try it out, but chinese mail you know…

I keep thinking about these restrictions though…
Maybe it’s possible to overcome the charging restart problem when 2 gpio’s can be used for detecting the input and ‘pressing’ the switch when power returns. HA can be used to maintain the state.
The problem of the Pi shutting down and not restarting can be mitigated the nobrainer way by just using a bigger battery. If it still runs out, then yes, we reached the limit… (maybe some power-on-reset logic circuitry can overcome this too, but I need it in my hands first)

Ingredients for a fun and useful project… :slight_smile:

The drawbacks are no issue for me. First of all when power loss occurs the unit is on battery but my unit seems the recharg directly after power resumed. No reset needed. I have a 2500mah battery concerted and the pi seems the keep on running for hours, so for me the drawback to turn the unit on with the button after shutdown is not a big deal. I mainly bought the battery for short power loss.

I have bought the same UPS board and I notice that also on my device the barrety charging start immidiatly afert power resumed. It’s great !!
I will try to use UPS on my HA based on Hass.io implementation.
Do you have a “standard” implementation or Hass.io platform ?
Many thanks in advance
Umberto

1 Like

I had a standaard HA implementation but in the meantime I switched to an intel nuc with usb ups.

1 Like

Dear All,

is there some other guy who have implemented UPS reading features using Python or i2cget command on HassIO Home Assistant?

many thanks in advance

1 Like

I got my Geekworm UPS Hat in the mail today, anyone how know how to get it working with Hassio?

1 Like

I was wondering the same thing. Wanted an UPS and this seems like a good, well priced solution but I’m running Hassio.

Hi bought one, does anybody found a solution? I’m quite noob…

It might help. Made it for the X720 for myself (for some boards, Geekworms has one algorithm).
In the Home Assistant you need to enable I2C. Link for Raspberry Pi.

1 Like

Any suggestion? I copied x720 folder in custom components and added the lines to config but even after reboot I didn’t find the new sensor…

Is I2C on? Any errors in the logs?

I got this…

Did you copy the folder to /config/custom_components ?

Check out the /config/home-assistant.log.
When restarting, the log should contain the line

WARNING (MainThread) [homeassistant.loader] You are using a custom integration for x720 which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.

You have one of these?
Look there also for errors with x720.

Did you make any other settings? You have lines in your logbook that read https://github.com/Beduir/...
There shouldn’t be any lines like that.

ok I found the line you said, so that’s ok, the next line says: [custom_components.x720.sensor] X720 sensor not detected at 0x36
so I presume it might be that I2c is not working… i try to fix it and let you know.
The strange line comes from the fact that I added your github to repository…

Nothing, it’s not finding the sensor at the address:
2020-07-06 11:38:18 ERROR (SyncWorker_11) [custom_components.x720.sensor] X720 sensor not detected at 0x36
2020-07-06 11:38:25 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/automation/init.py”, line 421, in async_enable_automation
self._async_detach_triggers = await self._async_attach_triggers(True)
File “/usr/src/homeassistant/homeassistant/components/automation/init.py”, line 457, in _async_attach_triggers
results = await asyncio.gather(*triggers)
File “/usr/src/homeassistant/homeassistant/components/automation/time_pattern.py”, line 52, in async_attach_trigger
hass, time_automation_listener, hour=hours, minute=minutes, second=seconds
File “/usr/src/homeassistant/homeassistant/helpers/event.py”, line 472, in async_track_time_change
return async_track_utc_time_change(hass, action, hour, minute, second, local=True)
File “/usr/src/homeassistant/homeassistant/helpers/event.py”, line 417, in async_track_utc_time_change
matching_seconds = dt_util.parse_time_expression(second, 0, 59)
File “/usr/src/homeassistant/homeassistant/util/dt.py”, line 231, in parse_time_expression
res = [x for x in range(min_value, max_value + 1) if x % parameter == 0]
File “/usr/src/homeassistant/homeassistant/util/dt.py”, line 231, in
res = [x for x in range(min_value, max_value + 1) if x % parameter == 0]
ZeroDivisionError: integer division or modulo by zero
is there the possibility to scan i2c addresses? maybe it’s on another one…