0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

節電対応

Last updated at Posted at 2022-06-19

政府の節電要請に基づき、おうちモニターに当日の電気の使用状況を追加してみました。

image.png

sqlite3からデータを拾ってjson作るスクリプトは以下のようにしました。

todaysm.rb
#!/usr/local/bin/mruby

def utc2jst(h)
  tmo = 0
  if tmo == 0 && h >= 15
    h = h - 15
    hs = "0" + h.to_s
  elsif h == 0
    hs = "09"
    tmo = 1
  else
    h = h + 9
    hs = h.to_s
  end
  hs
end

db = SQLite3::Database.new("/tmp/ouchi.db")

time = Array.new
val = Array.new

ago = 0

yday = (Time.now - 60*60*24*(ago + 1)).to_s[0, 10]
tday = (Time.now - 60*60*24*ago).to_s[0, 10]

i = 0
# get yesterday last recode by JST
sel = "select time, power from sm"
whe = " where (time < '15:00:00' and date=?) order by time desc limit 1"

db.execute(sel + whe, yday) do |row, fields|
time[i] = row[0]
val[i] = row[1]
i = i + 1
end

# no yesterday recode then get today first recode
if i == 0 then
sel = "select time, power from sm"
whe = " where (time>='15:00:00' and date=?) or (time<'15:10:00' and date=?) order by time asc, date asc limit 1"

db.execute(sel + whe, yday, tday) do |row, fields|
time[i] = row[0]
val[i] = row[1]
end
end

# get last recode by JST
sel = "select time, power from sm"
whe = " where (time>='15:00:00' and date=?) or (time<'15:10:00' and date=?) order by date desc, time desc limit 1"

db.execute(sel + whe, yday, tday) do |row, fields|
time[i] = row[0]
val[i] = row[1]
end

# convert to JST from UTC
h = time[i][0, 2].to_i
print "{ \"a\": "
print "\"" + utc2jst(h) + time[i][2, 3] + "\", "
print "\"b\": { \"c\": \"" + (val[i] - val[0]).round(1).to_s + " kWh"
print "\"} }"

グラフ用のcgiをベースに作ってみました。

タグが意味不明ですがGridagramのサンプルのなごりです。

スマートメーターからは10分おきにデータを拾っていてたまに失敗していますが、ほぼほぼ10分くらいの遅延で表示できます。

Magic-Grid便利です。

電力会社の本音は実入りがへるので、節電して欲しくないんだと思います。

本来Aルートでもいろいろできるのですが、電力会社はやる気がないので、Bルートの利用がもう少し普及するといいのですが。

昼の12時の時点で半分くらいになるので、目安にはなるようです。

無理して節電して死なないようにしてくださいね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?