CurrentCost EnviR energy monitor

Then definitely there’s a bug. It could be:

  • The empty daily history is causing a JavaScript crash.
  • Firefox’s JavaScript implementation is different on Mac OS (where I developed it) and Windows (where you’re testing it), enough to cause a crash.
  • We have locale differences (say, decimal point) which is messing with a locale-dependent function in JavaScript.

My money’s on the first one, but you won’t know till tomorrow when the first daily history populates.

Are you any good at using Firebug to debug JavaScript on your machine? If you can identify the crash on your installation it would help immensely. Otherwise I will have to try to reproduce a virgin device without history at my end.

(You are using the latest version of the plugin, aren’t you? I specifically fixed a couple of bugs related to empty history a few days ago in changesets @9-@11.)

(Edit: You are also pressing the History tab handle twice to get around the JavaScript tab bug in MiOS, yes? I am assuming yes, but let’s just get all the obvious problems out of the way first.)

[tt]J_CurrentCostEnviR1.js[/tt] was missing from [tt]/etc/cmh-ludl[/tt], but there was a [tt]/etc/cmh-ludl/J_CurrentCostEnviR1.json[/tt] …
The link for [tt]J_CurrentCostEnviR1.js[/tt] is still wrong ([tt]http://code.mios.com/trac/mios_currentcost-envir/wiki[/tt]).

The history is working now, I just had to put the right [tt]J_CurrentCostEnviR1.js[/tt] into [tt]/etc/cmh-ludl[/tt].

That’d be it. Thanks for figuring it out.

Now fixed, and with another bugfix too: the history doesn’t have an off-by-one error between the top of the odd hour and the end of the history dump several minutes later.

Here comes a quick and dirty (and untested) hack for logging with maximum resolution and moving the daily logfile to a ftp server:

-- Compute parent device's reading, using its custom formula.
		APPLIANCE_POWER[context.sensor] = context.watts
                local total_watts = calculateFormula(APPLIANCE_POWER)
		luup.variable_set(ENERGY_SERVICE_ID, "Watts", total_watts, lul_device)

local ftp_user        = 'xxxxxx'
local ftp_password    = 'xxxxxx'
local ftp_server_ip   = '192.168.178.22'
local remote_dir      = 'public/EnergyLogs/'

local local_dir       = '/etc/cmh-ludl/'

local LOG_SERVICE  = 'urn:upnp-ap15e-com:serviceId:Log1'


local outf
 
local cur_day  = os.date( '%Y%m%d' )

local last_day = luup.variable_get( LOG_SERVICE, 'LogFileName', lul_device )
 
if ( last_day == nil ) or ( last_day == '' )
 then
 
  luup.variable_set( LOG_SERVICE, 'LogFileName', tostring( cur_day ), lul_device )

  outf = io.open( local_dir .. cur_day, 'w')
  outf:close()
 
 else
 
  if last_day ~= cur_day 
   then
 
    os.execute( 'ftpput -u ' .. ftp_user .. 
                      ' -p ' .. ftp_password .. ' ' .. 
                      ftp_server_ip .. ' ' ..
                      remote_dir .. last_day .. ' ' ..
                      local_dir .. last_day                          )

    os.execute( 'rm ' .. local_dir .. last_day )
 
    outf = io.open( local_dir .. cur_day, 'w')
    outf:close()

    luup.variable_set( LOG_SERVICE, 'LogFileName', tostring( cur_day ), lul_device )
  
  end

 end

local cur_day = luup.variable_get( LOG_SERVICE, 'LogFileName', lul_device )

outf = io.open( local_dir .. cur_day, 'a')
outf:write( tostring( os.time() ) .. ';' .. tostring( total_watts ) .. '\n' )
outf:close()
	end
end

Hey, nice idea. Do you mind if I take your code and run with it? I’m thinking of turning it into a generic device that listens for the state of any other device’s variable, and logs it. Done that way, every energy monitor owner will be able to do what you do, not just us CurrentCost people. It could also be useful for other types of variable (say, motion sensors or temperature sensors).

I don’t mind if you run with my code - but if OpenWRT doesn’t use a wear leveling algorithm, it might be a bad idea to do extensive logging to the file system.

To be on the safe side, I’d use [tt]logger[/tt] and log the data to an external syslog server.

… and here comes a more elegant hack (using a remote syslog server: [tt]http://forum.micasaverde.com/index.php?topic=7288.msg46266#msg46266[/tt]):

-- Compute parent device's reading, using its custom formula.
		APPLIANCE_POWER[context.sensor] = context.watts
                local total_watts = calculateFormula(APPLIANCE_POWER)
		luup.variable_set(ENERGY_SERVICE_ID, "Watts", total_watts, lul_device)

os.execute( 'logger "'..tostring( total_watts )..'"' )


	end
end

Logger takes some options (-p in particular) that your remote syslog server can use to filter the log stream for energy monitoring into its own file. Maybe it can save you some postprocessing later.

Hack is no longer needed:
[tt]http://forum.micasaverde.com/index.php?topic=7305.0[/tt]

Feature request: child device for temperature

… but the EnviR temperature sensor doesn’t seem to be the most reliable (see attachment).

Done, in revision 13. All the other global variables too. For what it’s worth…

Thanks for the new revision. Unfortunately, my feature request was imprecise: add a NEW child device for temperature.

Oh, gotcha. That’ll take a little more programming; I’ll want it configurable so that people who don’t want the feature can turn it off.

Now done, properly, in revision 14. It’s disabled by default. To enable, set the ChildTemperature variable on the parent device to “1”.

Thanks a lot for implementing my feature request!

I have the envi connected directly to my verde, and I added all of the plugin files, but I only get one device that shows Power: W. I can’t seem to get it to display any power usage.

Hi jpitts,

Probably a serial port problem. Describe what you’ve done, and how it’s connected. Also tell me if the Luup log has any relevant messages.

Edit: Specifically, have you been into Toolbox > MiOS Developers > Serial Port Configuration, and set (at least) Baud, Data bits, Parity, Stop Bits, and Used By Device?

I have the vera2 and the current cost 128. The currentcost is connected with the supplied usb/serial/rj45 cable directly to the back or the vera.
lsusb shows
Bus 001 Device 003: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
dmesg shows
usbserial.c: USB Serial support registered for CP210X
usbserial.c: USB Serial support registered for FTDI SIO
usbserial.c: USB Serial support registered for FTDI 8U232AM Compatible
usbserial.c: USB Serial support registered for FTDI FT232BM Compatible
usbserial.c: USB Serial support registered for USB-UIRT Infrared Tranceiver
usbserial.c: USB Serial support registered for Home-Electronics TIRA-1 IR Transceiver
usbserial.c: USB Serial support registered for PL-2303
usbserial.c: PL-2303 converter detected
usbserial.c: PL-2303 converter now attached to ttyUSB0 (or usb/tts/0 for devfs)
I’ve added the 8 plug in files and created a new device called “power” using the device file D_CurrentCostEnviR1.xml
I then when back to miis developers on the serial port tab, I see one serial port called pl2303
I set the path as /dev/usb/tts/0 and set the Baud rate to 57600 and the used by device to power then close the dialog and clicked save.
The only device I see is Power but no usage next to it.

You’re going to have to get into the Luup log and search for error messages. What you’ve done ought to be sufficient.