Last active
September 15, 2019 22:22
-
-
Save kylejohnson/5796d2619e138546466cb0ac4d1cdc81 to your computer and use it in GitHub Desktop.
Ruby script utilizing bwa gem to communicat with Balboa spas. Sends results to influxdb.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bwa/client' | |
require 'bwa/discovery' | |
require 'influxdb' | |
database = "udp" | |
name = 'environment' | |
time = (Time.now.to_r * 1000).to_i | |
time_precision = 'ms' | |
influxdb = InfluxDB::Client.new 'udp', | |
host: "192.168.11.17", | |
port: 8086, | |
time_precision: 'ms' | |
if ARGV.empty? | |
$stderr.puts "Could not find spa!" | |
exit 1 | |
else | |
spa_ip = ARGV[0] | |
end | |
begin | |
spa = BWA::Client.new(spa_ip) | |
message = spa.poll | |
data = { | |
values: { | |
temperature: message.current_temperature.to_f, | |
pump_1: message.pump1, | |
pump_2: message.pump2, | |
circulation_pump: message.circ_pump, | |
priming: message.priming, | |
heating_mode: message.heating_mode.to_s, | |
heating: message.heating, | |
temperature_range: message.temperature_range.to_s, | |
set_temperature: message.set_temperature.to_f | |
}, | |
tags: { location: 'hot_tub' }, | |
timestamp: time | |
} | |
influxdb.write_point(name, data) | |
rescue Errno::EHOSTUNREACH | |
abort("No route to host - host unreachable!") | |
rescue Errno::ECONNREFUSED | |
abort("Connection refused!") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment