Skip to content

Instantly share code, notes, and snippets.

@matsubo
Last active Aug 20, 2020
Embed
What would you like to do?
quick and dirty code for prototyping
require 'bundler/setup'
Bundler.require
# http://192.168.1.124/aircon/get_sensor_info センサの情報。気温とか湿度とか。
# http://192.168.1.124/aircon/get_control_info 設定情報。運転モードとか。
# http://192.168.1.124/common/basic_info 基本的な情報。IDやパスワードまで返ってくる(!)ので取扱注意。
# http://192.168.1.124/common/get_datetime 現在日時。
# http://192.168.1.124/aircon/get_scdltimer_body?target=c ウィークリータイマーの設定情報。
require "open-uri"
class Daikin
def initialize(daikin_host, hash = {})
username = hash[:username] || 'admin'
password = hash[:password] || 'admin'
database = hash[:database] || 'db0'
@name = hash[:name] || 'daikin'
@influxdb = InfluxDB::Client.new database, username: username, password: password
@host = daikin_host
@logger = Logger.new(STDOUT)
end
def sensor
body = URI.open("http://#{@host}/aircon/get_sensor_info").read
data = {
values: parse(body),
tags: { wave: 'sensor' }
}
@influxdb.write_point(@name, data)
@logger.info(data)
end
def control
body = URI.open("http://#{@host}/aircon/get_control_info").read
data = {
values: parse(body),
tags: { wave: 'control' }
}
@influxdb.write_point(@name, data)
@logger.info(data)
end
def basic
body = URI.open("http://#{@host}/common/basic_info").read
data = {
values: parse(body),
tags: { wave: 'basic' }
}
@influxdb.write_point(@name, data)
@logger.info(data)
end
def parse(string)
string.split(',').map{ |string| string.split('=', -1) }.to_h.map {|key,val| val.match(/^[0-9\.]+$/) ? [key, val.to_f] : [key, val] }.to_h
end
end
daikin = Daikin.new('192.168.1.124')
daikin.sensor
daikin.control
daikin.basic
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "influxdb"
gem "logger"
@matsubo

This comment has been minimized.

Copy link
Owner Author

@matsubo matsubo commented Aug 20, 2020

% bundle
% bundle exec ruby daikin.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment