高木のブログ

【Nature Remo E lite】瞬時電力計測値をAmbientでグラフ化する

· 95 words · 1 minutes to read

半年くらい前にNature Remo E lite を買って放置していたが、せっかくなのでAmbient に値を投げてグラフ化してみることにした。
Nature Remoの公式アプリでグラフは見れるので、正直何も意味はない。
API でいろいろ値は取れるが、ばっと見、意味がわかるのは瞬時電力計測値くらいなのでそれを使う。

手順 🔗

コード 🔗

source 'https://rubygems.org'

git_source(:github) {|repo_name| 'https://github.com/#{repo_name}' }

gem 'dotenv'
gem 'nature_remo'
gem 'ruby-ambient'
NATURE_REMO_API_TOKEN=
AMBIENT_CHANNEL_ID=
AMBIENT_WRITE_KEY=
require 'dotenv/load'
require 'nature_remo'
require 'ruby-ambient'

client = NatureRemo::Client.new(ENV['NATURE_REMO_API_TOKEN'])
response = client.appliances
appliances = JSON.parse(response.body, symbolize_names: true)

el_smart_meter = appliances.find { |appliance| appliance[:type] == 'EL_SMART_METER' }
echonetlite_properties = el_smart_meter[:smart_meter][:echonetlite_properties].each_with_object({}) do |echonetlite_property, hash|
  hash[echonetlite_property[:name].to_sym] = echonetlite_property[:val].to_i
end

ambient = Ambient.new(ENV['AMBIENT_CHANNEL_ID'], write_key: ENV['AMBIENT_WRITE_KEY'])
ambient.send({ d1: echonetlite_properties[:measured_instantaneous] })

ytkg/nature_remo_e_lite_to_ambient - GitHub

Raspberry Piで動かす 🔗

GitHub Actionsで1分毎動かすのはちょっと気が引けたので、Raspberry Piで動かすことにした。

* * * * * cd /home/pi/workspace/nature_remo_e_lite_to_ambient/ && /home/pi/.rbenv/shims/bundle exec ruby app.rb

bundleだけだと、bundle: not foundになってしまったので、フルパスで呼び出した。
crontab何もわからん。

結果 🔗

ambient_graph

Categories


Tags