Skip to content

Instantly share code, notes, and snippets.

@kylejohnson
Last active September 15, 2019 22:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylejohnson/5796d2619e138546466cb0ac4d1cdc81 to your computer and use it in GitHub Desktop.
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.
#!/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