class Sunscout::SolarLog::SolarLog

High-level binding to the SolarLog HTTP API @example Basic usage

require 'sunscout'
sl = Sunscout::SolarLog::SolarLog.new('http://10.60.1.10', timezone: 'CEST')
puts "AC power: #{ sl.power_ac }W (DC: #{ sl.power_dc }W, Efficiency #{ (sl.efficiency*100).round(0) }%)"
puts "Remaining power: #{ sl.power_available }W"

Attributes

consumption_ac[R]

Current consumption in W @return [Fixnum]

consumption_day[R]

Today's consumption in Wh @return [Fixnum]

consumption_month[R]

This month's consumption in Wh @return [Fixnum]

consumption_total[R]

Total consumption in Wh @return [Fixnum]

consumption_year[R]

This year's consumption in Wh @return [Fixnum]

consumption_yesterday[R]

Yesterday's consumption in Wh @return [Fixnum]

power_ac[R]

AC power in W @return [Fixnum]

power_dc[R]

DC power in W @return [Fixnum]

power_total[R]

Maximum DC power in W @return [Fixnum]

time[R]

Timestamp of the data. @return [DateTime]

voltage_ac[R]

AC voltage in V @return [Fixnum]

voltage_dc[R]

DC voltage in V @return [Fixnum]

yield_day[R]

Today's yield in Wh @return [Fixnum]

yield_month[R]

This month's yield in Wh @return [Fixnum]

yield_total[R]

Total yield in Wh @return [Fixnum]

yield_year[R]

This year's yield in Wh @return [Fixnum]

yield_yesterday[R]

Yesterday's yield in WH @return [Fixnum]

Public Class Methods

new(host, opts = {}) click to toggle source

Initialize a new instance of the class.

This also immediately queries data from the SolarLog API.

@param host [String] URI of the SolarLog web interface @param opts [Hash] Additional options.

If not consumed by this class itself, they are passed to {Client#initialize}
Be sure to check there for all possibilities!

@option opts [String] :timezone Timezone (or offset) which the SolarLog station resides in.

If none is specified, assume UTC.
# File lib/sunscout/solar_log/solar_log.rb, line 80
def initialize(host, opts = {})
  timezone = opts.delete(:timezone) || '+0000'

  client = Sunscout::SolarLog::Client.new(host, opts)
  data = client.get_data

  # SolarLog returns the time a) without a timezone indicator and b) as whatever the station is configured.
  # Hence, the user has to specify what timezone it is in - otherwise we'll just fall back to UTC.
  time = "#{ data.fetch(:time) } #{ timezone }"
  @time = DateTime.strptime(time, '%d.%m.%y %H:%M:%s %Z')

  @power_ac    = data.fetch :power_ac
  @power_dc    = data.fetch :power_dc
  @power_total = data.fetch :power_total

  @voltage_ac = data.fetch :voltage_ac
  @voltage_dc = data.fetch :voltage_dc

  @yield_day       = data.fetch :yield_day
  @yield_yesterday = data.fetch :yield_yesterday
  @yield_month     = data.fetch :yield_month
  @yield_year      = data.fetch :yield_year
  @yield_total     = data.fetch :yield_total

  @consumption_ac        = data.fetch :consumption_ac
  @consumption_day       = data.fetch :consumption_day
  @consumption_yesterday = data.fetch :consumption_yesterday
  @consumption_month     = data.fetch :consumption_month
  @consumption_year      = data.fetch :consumption_year
  @consumption_total     = data.fetch :consumption_total
end

Public Instance Methods

alternator_loss() click to toggle source

Loss of DC to AC conversion. @return [Fixnum] Loss of alternator in Watt.

@example

solar_log.power_ac #=> 94
solar_log.power_dc #=> 100
solar_log.alternator_loss #=> 6
# File lib/sunscout/solar_log/solar_log.rb, line 131
def alternator_loss
  power_dc - power_ac
end
capacity() click to toggle source

Capacity of peak power generation. @return [Float] Percentage of peak power generation.

@example

solar_log.power_dc #=> 8000
solar_log.power_total #=> 10000
solar_log.capacity #=> 0.8
# File lib/sunscout/solar_log/solar_log.rb, line 175
def capacity
  return 0 if power_total == 0
  power_dc / power_total
end
efficiency() click to toggle source

Efficiency of DC to AC conversion. @return [Float] Efficiency as percentage between 0 and 1.

@example

solar_log.power_ac #=> 94
solar_log.power_dc #=> 100
solar_log.efficiency #=> 0.94
# File lib/sunscout/solar_log/solar_log.rb, line 119
def efficiency
  return 0 if @power_dc == 0
  power_ac.to_f / power_dc
end
power_available() click to toggle source

Surplus AC power. @return [Fixnum] Surplus AC power in Watt. Negative if more power consumed than generated.

@example Usage <100%

solar_log.consumption_ac #=> 50
solar_log.power_ac #=> 100
solar_log.power_available #=> 50

@example Usage >100%

solar_log.consumption_ac #=> 200
solar_log.power_ac #=> 100
solar_log.power_available #=> -100
# File lib/sunscout/solar_log/solar_log.rb, line 164
def power_available
  power_ac - consumption_ac
end
usage() click to toggle source

Usage of AC power. @return [Float] Usage of AC power as percentage. >1 if more power consumed than generated.

@example Usage <100%

solar_log.consumption_ac #=> 50
solar_log.power_ac #=> 100
solar_log.usage #=> 0.5

@example Usage >100%

solar_log.consumption_ac #=> 200
solar_log.power_ac #=> 100
solar_log.usage #=> 2
# File lib/sunscout/solar_log/solar_log.rb, line 147
def usage
  return 0 if @power_ac == 0
  consumption_ac.to_f / power_ac
end