Author Topic: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin  (Read 31537 times)

Offline jswim788

  • Hero Member
  • *****
  • Posts: 733
  • Karma: +49/-2
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #90 on: July 10, 2017, 01:40:05 pm »
Love this plugin! Is there any way to reset the DeliveredKWH, ReceivedKWH and NetKWH variables back to zero? I'd like to create a scene that did this monthly so that I can see the monthly totals.
@jamac, Delivered and Received are pulled directly from the meter and Net is calculated from them.  There is no way to "reset" them.  But I suppose we could add some new variables to serve as a base.  DeliveredBase and ReceivedBase.  The "reset" button that you describe would update the bases.  Then you could calculate the new delta as DeliveredKWH - DeliveredBase.  What do you think of that?

Also, the Eagle is able to show the monthly totals in its local web server (I think).  You might try opening the local web page on it using Chrome with F12 to see the debug window.  Navigate to the page with the monthly totals.  Then see if there is a way to pull the monthly data directly from the server.  This might be easier than the above.

Offline jamac

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +0/-1
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #91 on: July 11, 2017, 04:39:58 am »
Love this plugin! Is there any way to reset the DeliveredKWH, ReceivedKWH and NetKWH variables back to zero? I'd like to create a scene that did this monthly so that I can see the monthly totals.
@jamac, Delivered and Received are pulled directly from the meter and Net is calculated from them.  There is no way to "reset" them.  But I suppose we could add some new variables to serve as a base.  DeliveredBase and ReceivedBase.  The "reset" button that you describe would update the bases.  Then you could calculate the new delta as DeliveredKWH - DeliveredBase.  What do you think of that?

Also, the Eagle is able to show the monthly totals in its local web server (I think).  You might try opening the local web page on it using Chrome with F12 to see the debug window.  Navigate to the page with the monthly totals.  Then see if there is a way to pull the monthly data directly from the server.  This might be easier than the above.

Reset-able variables would be awesome. This would mirror the functionality offered by the Aeon Labs Home Energy Meter (HEM) and Smart Switches, both of which allow the user to reset the internal kWh counter. You can then create a scene to do that daily, weekly or monthly according to your preference.

I've had a look at the Rainforest Eagle's local and cloud portals and the 'consumption' view for a year shows the monthly NET totals. I'm not sure how this data could be extracted from the server... you have to scrape it somehow right? Anyway, having reset-able variables for delivered and received kWh would be a much nicer solution. Happy to roadtest a beta for you!  :)

Offline jswim788

  • Hero Member
  • *****
  • Posts: 733
  • Karma: +49/-2
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #92 on: July 14, 2017, 12:14:39 pm »
I've attached an updated implementation file.  This uses port 80 to access the Eagle data instead of 5002.  It gets a JSON response instead of XML.  I mainly did this to see if I would stop getting bogus power data.  Unfortunately that did not happen, but it is easier to detect with the JSON which will return "nan" instead of giving a bogus timestamp.  The other advantages are that it is easier to parse the JSON, you can get access to anything that the internal web server displays, the values are formatted a little better, and you could more easily point this to the Rainforest cloud server if you wanted.  Otherwise there is not a lot of advantage of this over the original.

I did add two features:
1) the ResetKWH action now works.  This will save a base value for delivered and received and give the KWH as a delta from the saved values.
2) Price is now reported.  I have no way to test this as my utility does not populate it.

This loses automatic MacID detection.  I will try to look into this.

Installation:
You can update your existing device with the attached xml.  Upload the xml file, change the device to point to this file, and reload.

Or you can create a new device with robertmm's original files with the attached replacing the I_SmartMeterHAN1.xml.

You must set the IP.

Since there is no autodetect of the MacID, you MUST set it manually if not already set.  See the attached picture of the Eagle - get the MacID from the bottom.  The format must have "0x" in front of it.

If your Eagle has security turned on (optional, you can turn it off in the settings in the Eagle GUI, but I believe the default is on), then you must get the CloudId and the DeviceIN which is also on the bottom of the device.

Sample lua to set them below.  Replace the '46' with the Vera ID for this device, and replace the values with the ones from the bottom of your Eagle.

Code: [Select]
luup.variable_set("urn:smartmeter-han:serviceId:SmartMeterHAN1", "DeviceMACID", "0xabababababababab", 46)
luup.variable_set("urn:smartmeter-han:serviceId:SmartMeterHAN1", "DeviceIN", "1eabababadddddddd", 46)
luup.variable_set("urn:smartmeter-han:serviceId:SmartMeterHAN1", "CloudId", "000eee", 46)

Or, after the initial reload, set these 3 variables in the advanced tab appropriately.

Then reload the Vera.

Should you have any trouble, try the following curl test line on a unix box (must be a Windows version of curl too?).  Replace the IP with your Eagle IP, 6 digits before the : are the Cloud ID, 16 digits after the : are the IN, and the MacID is the 0xXXXXXXXXXXX delimited by <MacId>.  This should return the status of your Eagle in JSON format.  If you don't get the status back, the plugin won't work.

Code: [Select]
curl -d '<LocalCommand><Name>get_setting_data</Name><MacId>0xXXXXXXXX</MacID></LocalCommand>' http://XXXXXX:XXXXXXXXXXXX@192.168.1.201/cgi-bin/cgi_manager
Thanks to robertmm for the original code - this is a great plugin.

Also, I'm keeping the code in github here: https://github.com/jswim788/rainforest-eagle-vera
« Last Edit: November 18, 2017, 10:47:10 am by jswim788 »

Offline jamac

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +0/-1
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #93 on: July 14, 2017, 10:44:07 pm »
This looks great.

A dumb question - presumably I need to update the local variables in the xml implementation file before uploading it, eg:

local HAN_IP                = "123.456.7.89"
local HAN_MACID         = "0xabababababab"
local HAN_IN                = "12341234a123a123"
local HAN_CLOUDID      = "000123"

Offline jswim788

  • Hero Member
  • *****
  • Posts: 733
  • Karma: +49/-2
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #94 on: July 15, 2017, 12:27:26 am »
You don't need to change the xml.  Case 1 is if you are modifying an existing energy meter device and case 2 is for creating a new energy meter device.

Case 1: you already have the IP and likely the MACID.  If security is off, then you can likely just change the implementation file and reload and it should get the new file and start working.  If you do have security on, then you'll want to add those 2 variables to the device.  After you first install and reload the device, you should see DeviceIN and CloudId as blank in the advanced tab.  Fill these in with the appropriate values and reload.

Case 2: create the new device with robertmm's original files except the I_SmartMeterHAN1.xml replaced with this new one, then go into the tabs and set the IP, then set the variables in the advanced tab.  Reload the Vera to get it to start up with the new variables set.

See http://forum.micasaverde.com/index.php/topic,14767.msg325432.html#msg325432 for the latest files.  Also, I have them in github here: https://github.com/jswim788/rainforest-eagle-vera
« Last Edit: August 13, 2017, 11:31:33 pm by jswim788 »

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1172
  • Karma: +23/-13
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #95 on: July 18, 2017, 11:43:07 pm »
I had Rainforest update my firmware - I had to remind them twice.  Now it is a mess.  Disconnected from meter.  No advanced settings to disable credentials.

I updated my ticket with my frustrations...
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1172
  • Karma: +23/-13
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #96 on: July 25, 2017, 04:44:47 pm »
I had Rainforest update my firmware - I had to remind them twice.  Now it is a mess.  Disconnected from meter.  No advanced settings to disable credentials.

I updated my ticket with my frustrations...

I got my Eagle re-paired with my meter.  Leaving it on the older plug-in code as it started working - WITHOUT any security updates.  I didn't add in the username/passowrd to the plug-in nor did I disable the security on the Eagle.  Meaning it looks to me like port 5002 isn't requiring a password.  When I try to connect via browser it says "Connection Dropped", but I get data from the plug-in...
« Last Edit: July 25, 2017, 04:48:46 pm by wilme2 »
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)

Offline jswim788

  • Hero Member
  • *****
  • Posts: 733
  • Karma: +49/-2
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #97 on: July 25, 2017, 07:20:44 pm »
What firmware do you have now?  I'm getting the impression that they started using port 5002, then shifted over to the web browser interface on port 80 but didn't remove the port 5002 access.  Also, it doesn't appear they've made any firmware changes recently, so maybe it is stuck as is.  2.3.4 was released in Dec 2015.

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1172
  • Karma: +23/-13
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #98 on: July 25, 2017, 07:57:06 pm »
What firmware do you have now?  I'm getting the impression that they started using port 5002, then shifted over to the web browser interface on port 80 but didn't remove the port 5002 access.  Also, it doesn't appear they've made any firmware changes recently, so maybe it is stuck as is.  2.3.4 was released in Dec 2015.

HW   3.2.3
FW   2.3.4.8466
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)

Offline jamac

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +0/-1
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #99 on: July 29, 2017, 02:53:35 am »
I just can't get this to work.

I've uploaded the new implementation file as I_SmartMeterHAN1.xml (ie, replacing the existing implementation file) but I get the following error whenever I restart the Luup engine: "Rainforest Eagle[18] : Startup Lua Failed".

If i reload the old implementation file and restart the luup engine everything goes back to that way it was.

Any tips?

Offline jswim788

  • Hero Member
  • *****
  • Posts: 733
  • Karma: +49/-2
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #100 on: August 09, 2017, 04:46:18 pm »
There are 2 conditions where the startup can fail.
Code: [Select]
      if ((HAN_MACID or "") == "") then
        return false, "Please enter the DeviceMACID of your HAN device", "SmartMeterHAN1"
      end
      if (HAN_IP:match("%d+%.%d+%.%d+%.%d+") == nil) then
        return false, "Please enter the IP address of of your HAN device", "SmartMeterHAN1"
      end
Do you see either of these messages in the log file?  And do you have the DeviceMACID variable set (case sensitive)?  It will not auto-detect as the prior XML did.  "HAN_MACID" is the internal variable - "DeviceMACID" is the variable you need to set on the plugin.

Offline jamac

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +0/-1
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #101 on: November 06, 2017, 04:05:15 am »
Back again. I'm really keen to get this plugin working but cannot.

I keep getting the message "Rainforrest Eagle[18]: Startup Lua Failed"

If I look at the log using http://[IP address]/cgi-bin/cmh/log.sh?Device=LuaUPnP i see the following message:

luup_log:18: Starting ZigBee HAN device, version 0.41js <0x2be5d680>
LuaInterface::CallFunction_Startup-1 device 18 function startup failed /usr/lib/lua/socket/http.lua:116: bad argument #2 to 'connect' (number expected, got string) <0x2be5d680>
LuImplementation::StartLua running startup code for 18 I_SmartMeterHAN1.xml failed <0x2be5d680>


Elsewhere I see repeats of the following message:
luup_log:18: SmartMeterHAN1: Cannot receive data from HAN device: closed <0x2c213680>
Device_Variable::m_szValue_set device: 18 service: urn:micasaverde-com:serviceId:HaDevice1 variable: CommFailure was: 1 now: 1 #hooks: 0 upnp: 0 skip: 0 v:0xee7b78/NONE duplicate:1 <0x2c213680>
Device_Variable::m_szValue_set device: 18 service: urn:micasaverde-com:serviceId:EnergyMetering1 variable: Watts was: 0 now: 0 #hooks: 0 upnp: 0 skip: 0 v:0xb6b2d8/NONE duplicate:1 <0x2c213680>
Device_Variable::m_szValue_set device: 18 service: urn:smartmeter-han:serviceId:SmartMeterHAN1 variable: LinkStrength was: 0 now: 0 #hooks: 0 upnp: 0 skip: 0 v:0xf4c728/NONE duplicate:1 <0x2c213680>
Device_Variable::m_szValue_set device: 18 service: urn:smartmeter-han:serviceId:SmartMeterHAN1 variable: LinkStatus was: ? now: ? #hooks: 1 upnp: 0 skip: 0 v:0xf4c920/NONE duplicate:1 <0x2c213680>


If I look at the device's ''advanced' tab the IP address, DeviceMACID, CloudId and DeviceIN all appear to be set properly. I've tried DeviceMACID with and without the leading '0x'.

Any idea what's going wrong?

Offline jamac

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +0/-1
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #102 on: November 06, 2017, 06:54:05 am »
I've solved the above issue. I must have had a hidden character in the DeviceIN field in the 'advanced' tab. I re-entered the number again and the "startup lua failed" error disappeared.

However, I'm now getting a "Cant Detect Device" error and the log contains the following:

401   11/06/17 22:44:33.490   luup_log:18: Error connecting to Rainforest Eagle server port:  <0x2bcab680>

A port 80/5002 problem i assume?
« Last Edit: November 06, 2017, 07:19:41 am by jamac »

Offline jswim788

  • Hero Member
  • *****
  • Posts: 733
  • Karma: +49/-2
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #103 on: November 06, 2017, 11:55:10 am »
I realize I have an error in the logging, so I've attached another implementation file which should allow us to see the error code.  However, I can tell that you are not getting a '200' response to the http call.  What is your 'CouldId' set to?  No special characters in there?  It should be 6 hex digits, no leading 0x, just 6 characters.

Offline jamac

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +0/-1
Re: Rainforest Automation Eagle ZigBee Smart Meter HAN Gateway Plugin
« Reply #104 on: November 07, 2017, 03:36:58 am »
It's working! After a few restarts and carefully re-entering the cloudID and other parameters a few times, it suddenly started working. All good so far. Thanks for the plugn and your guidance getting it up and running.