Remove Pi GPIO support

This was requested once but it feels disjointed with the rest of the
application, and doesn't really fit with the scheme of Lux inverter
control generally.

If whoever requested this was using it, let me know and I'll knock up
an alternative solution (probably in another repo).
This commit is contained in:
Chris Elsworth 2020-05-01 20:57:13 +01:00
parent bcd8944916
commit 9069fd18b0
8 changed files with 1 additions and 82 deletions

View File

@ -1,3 +1,2 @@
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "pi"

View File

@ -10,10 +10,6 @@ gem 'lxp-packet', '~> 0.6.0'
gem 'roda'
group :pi do
gem 'rpi_gpio'
end
group :mqtt do
gem 'mqtt-sub_handler'
end

View File

@ -4,8 +4,6 @@ This is a Ruby script to parse [Octopus ToU tariff](https://octopus.energy/agile
The particular use-case of this is to charge your home batteries when prices are cheap, and use that power at peak times.
There's also support for toggling Raspberry Pi GPIO pins as an added bonus.
## Installation
You'll need Ruby - at least 2.3 should be fine, which can be found in all good Linux distributions.
@ -29,12 +27,6 @@ Now install the gems. You may occasionally need to re-run this as I update the r
bundle update
```
If you are running on a Raspberry Pi and want to use the GPIO support, you can install it with: (you only need to do this once, subsequent `bundle installs` will remember you want the pi package)
```
bundle install --with pi
```
Create a `config.ini` using the `doc/config.ini.example` as a template:
```
@ -48,7 +40,6 @@ This script needs to know:
* how many batteries you have, which determines the maximum charge rate (used in agile_cheap_slots rules)
* which Octopus tariff you're on, AGILE-18-02-21 is my current one for Octopus Agile.
* if you're using MQTT, where to find your MQTT server.
* optionally on the Pi, a list of GPIOs you'll be controlling.
Copy `rules.rb` from the example as a starting point:
@ -134,9 +125,3 @@ In your `rules.rb`, you have access to a few objects to do some heavy lifting.
Forced discharge may be useful if you're paid for export and you have a surplus of stored power when the export rate is high.
Setting the power rates is probably a bit of a niche requirement. Note that discharge rate is *all* discharging, not just forced discharge. This can be used to cap the power being produced by the inverter. Setting it to 0 will disable discharging, even if not charging.
*`gpio`* is a GPIO controller (only available on the Raspberry Pi). These two methods take a string which corresponds to your configuration. See the example config under the `[gpios]` section.
* `gpio.on('zappi')` - turn on the GPIO pin identified as *zappi* in your config.
* `gpio.off('zappi')` - turn off the GPIO pin identified as *zappi* in your config.
* `gpio.set('zappi', true)` - alternative way of turning on a GPIO. Pass `false` to turn it off.

View File

@ -14,7 +14,7 @@ require 'zeitwerk'
LOGGER = Logger.new(STDOUT)
LOADER = Zeitwerk::Loader.new
LOADER.inflector.inflect('gpio' => 'GPIO', 'mq' => 'MQ')
LOADER.inflector.inflect('mq' => 'MQ')
LOADER.logger = LOGGER if ENV['ZEITWERK_LOGGING']
LOADER.push_dir('lib')
LOADER.enable_reloading

View File

@ -27,13 +27,6 @@ port = 4346
# you can leave this commented out if you don't want to use MQTT at all.
# uri = mqtt://nas:1883
# an optional list of GPIOs you'd like to control on a Raspberry Pi.
# the names are used in your rules.rb and can be anything you like.
# the numbers are corresponding GPIO numbers.
# See https://www.raspberrypi-spy.co.uk/wp-content/uploads/2012/06/Raspberry-Pi-GPIO-Header-with-Photo.png
[gpios]
zappi = 5
[rules]
# use the cheapest energy to get the batteries to this SOC each night
required_soc = 90

View File

@ -18,9 +18,6 @@ begin
# if the current price is 5p or lower, enable AC charge
charge = octopus.price <= 5
# experimental GPIO support. turn a GPIO on when charge is true, off if false.
# gpio.set('zappi', charge)
unless lc.charge(charge)
LOGGER.error 'Failed to update inverter status!'
exit 255

View File

@ -1,48 +0,0 @@
# frozen_string_literal: true
begin
# may not be installed if not on a Pi!
require 'rpi_gpio'
rescue LoadError
nil
end
class GPIO
def initialize(gpios:)
@gpios = gpios
# do nothing if RPi is not available
return unless defined?(RPi)
RPi::GPIO.set_numbering(:board)
RPi::GPIO.set_warnings(false)
# initialise each GPIOs as output
gpios.each_value { |pin| setup(pin) }
end
def setup(pin)
RPi::GPIO.setup(pin, as: :output)
end
def on(pin)
RPi::GPIO.set_high(lookup_pin(pin))
end
def off(pin)
RPi::GPIO.set_low(lookup_pin(pin))
end
def set(pin, value)
value ? on(pin) : off(pin)
end
private
def lookup_pin(pin)
pin = gpios[pin] if pin.is_a?(String)
raise 'unknown GPIO' unless pin
pin
end
end

View File

@ -23,9 +23,6 @@ lc = LuxController.new(host: CONFIG['lxp']['host'],
ls = LuxStatus.new(host: CONFIG['server']['connect_host'] || CONFIG['server']['host'],
port: CONFIG['server']['port'])
# abstraction of RPi::GPIO
gpio = GPIO.new(gpios: CONFIG['gpios'])
# rubocop:enable Lint/UselessAssignment
raise('rules.rb not found!') unless File.readable?('rules.rb')