We have moved at community.getvera.com

Author Topic: Ecobee App Ported to Openluup  (Read 918 times)

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Ecobee App Ported to Openluup
« on: April 27, 2018, 05:49:32 am »
To those who may be interested, I have successfully ported the Ecobee App to Openluup. It was a hobby on its own and was successful thanks to @Watou generosity in providing the encrypted API file. He originally wrote it for UI5 and I made some touch-ups to it last year to make it work on UI7 but making it work on Openluup was a whole different task. I will run a bit more test before calling it good and posting it here.

@akbooer : Since you are going to ask what I did, here are the major changes:

1. I had to install luasec to my lua library to support https calls.
2. A developer account needs to be create on the ecobee website in order to get an API key so that everyone's data remains safe and is seen as an independent app. This only takes a few seconds.
3. Merged the encrypted API lua file into the main one, refactored several functions and eliminated need of module calls which made passing variables more cumbersome.
3. Use of the ubiquitous dkjson decoder instead of a compressed customized one on the original app. (I don't really understand what the purpose was and struggled with it for some time). Related was the "Require" declaration of the json library which did not seem to work on the vera either so it has been a mystery as to how the app works on UI7.
4. luup.task messages does not appear to show anywhere so I added a message field on the device to get status of the app and mostly debug...
5. All the "<" and ">" operators were replaced with lua equivalent in the xml files.
6. Localize all the icons since we should not have storage limitations on openluup and icons are small anyway.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: Ecobee App Ported to Openluup
« Reply #1 on: April 27, 2018, 08:24:09 am »
...but making it work on Openluup was a whole different task.

Well done, but I'm a bit disappointed in myself, since a well-written plugin should run very nicely both on Vera and openLuup.  Some of the more 'sophisticated' ones do pull some strange tricks, and maybe that's what you ran into here.

If' there's anything I should be doing differently, then please let me know, but to comment specifically on your points:

Quote
1. I had to install luasec to my lua library to support https calls.

I do that on standard openLuup installs now, since more and more things need HTTPS.  I'm just working on digest authentication to make this more universal.

Quote
2. A developer account needs to be create on the ecobee website in order to get an API key so that everyone's data remains safe and is seen as an independent app. This only takes a few seconds.

Yes, this is similar to other cloud-based items like Netatmo, etc.

Quote
3. Merged the encrypted API lua file into the main one, refactored several functions and eliminated need of module calls which made passing variables more cumbersome.

That one's definitely not my fault!

Quote
3. Use of the ubiquitous dkjson decoder instead of a compressed customized one on the original app. (I don't really understand what the purpose was and struggled with it for some time). Related was the "Require" declaration of the json library which did not seem to work on the vera either so it has been a mystery as to how the app works on UI7.

I think I know the answer to this one, but it doesn't matter.  Yes, I made dkjson available as part of the standard openLuup install, but openLuup itself doesn't use it, having got its own.

Quote
4. luup.task messages does not appear to show anywhere so I added a message field on the device to get status of the app and mostly debug...

They should show in the log file, but not the user interface.  In fact, I've recently had conversations with @amg0 about this and know how to make this work.  It's on the list, but not high priority.

Quote
5. All the "<" and ">" operators were replaced with lua equivalent in the xml files.

I am really, really surprised by this.  The openLuup xml reader should make these substitutions.  If not, then something is wrong.  Without them, it's actually invalid XML, although the openLuup reader should cope with that.  Can I possibly get an example of a file which didn't work?

Quote
6. Localize all the icons since we should not have storage limitations on openluup and icons are small anyway.

Yes, that certainly works, although, strangely, for my other plugins (like Netatmo) which have lots of icons,  I switched to pulling them directly from GitHub.  This vastly improved the ease of updating the plugins in the MiOS app store, although, TBH, I've really stopped using that.


Anyhow, thanks for putting in the effort and sharing, in due course, with other openLuup users.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Ecobee App Ported to Openluup
« Reply #2 on: April 27, 2018, 02:22:35 pm »
Alright it is ready to go! I also added the instructions

https://github.com/rafale77/vera-ecobee



...but making it work on Openluup was a whole different task.

Well done, but I'm a bit disappointed in myself, since a well-written plugin should run very nicely both on Vera and openLuup.  Some of the more 'sophisticated' ones do pull some strange tricks, and maybe that's what you ran into here.

If' there's anything I should be doing differently, then please let me know, but to comment specifically on your points:

Don't be! I am not a coder by training. I learned Lua from looking at what all other developers did. I am not very good at reading manuals so... From what I can see some apps are not working because they use some unusual structures or functions. Some I really fail to understand but I am sure there was a reason at the time (i.e why the need to use an compressed json interpreter? And why the strange declaration of the
Code: [Select]
json=L_ecobee_dkjson which doesn't seem to work?)

Quote
Quote
4. luup.task messages does not appear to show anywhere so I added a message field on the device to get status of the app and mostly debug...

They should show in the log file, but not the user interface.  In fact, I've recently had conversations with @amg0 about this and know how to make this work.  It's on the list, but not high priority.

It would have saved me some time but not much. No biggie.

Quote
Quote
5. All the "<" and ">" operators were replaced with lua equivalent in the xml files.

I am really, really surprised by this.  The openLuup xml reader should make these substitutions.  If not, then something is wrong.  Without them, it's actually invalid XML, although the openLuup reader should cope with that.  Can I possibly get an example of a file which didn't work?

This I am not sure. It has been one of my most suspicious factor for the Plantlink app not to work so I assumed that it didn't work here. In any case I needed to do it because I moved all the functions into a lua file. I am unfamiliar with xml and was very confused by the mix of both lua and xml in the xml file. I think it is cleaner when separated.

Now one question: I have a device with buttons I want to display on the ALTUI device screen and are already within tabs in the device. The buttons show on UI7 but not on ALTUI... Haven't quite figured this one out.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: Ecobee App Ported to Openluup
« Reply #3 on: April 27, 2018, 03:27:19 pm »
... why the strange declaration of the
Code: [Select]
json=L_ecobee_dkjson which doesn't seem to work?)

I would expect this have been preceded by something like:
Code: [Select]
require "L_ecobee_dkjson"
which would have defined the global module name L_ecobee_dkjson which is then aliased to the usual json prefix.

Quote
I am unfamiliar with xml and was very confused by the mix of both lua and xml in the xml file. I think it is cleaner when separated.

You are absolutely correct.  XML is a mess and the conflation with Lua is an unholy alliance.  Use the minimum possible XML for the implementation file and move swiftly to a separate Lua file (which any IDE can parse and error check for you.)

Quote
Now one question: I have a device with buttons I want to display on the ALTUI device screen and are already within tabs in the device. The buttons show on UI7 but not on ALTUI... Haven't quite figured this one out.

That, I am afraid, is not my area of expertise.  You'd have to poll @amg0 or one of the other JavaScript-fluent developer for a clue here.

Well done again for doing this.  I am assuming that it will end up in the AltAppStore?
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Ecobee App Ported to Openluup
« Reply #4 on: April 27, 2018, 04:21:52 pm »
... why the strange declaration of the
Code: [Select]
json=L_ecobee_dkjson which doesn't seem to work?)

I would expect this have been preceded by something like:
Code: [Select]
require "L_ecobee_dkjson"
which would have defined the global module name L_ecobee_dkjson which is then aliased to the usual json prefix.
Yes there was a
Code: [Select]
dkjson = require("L_ecobee_dkjson") preceding but I could not understand how the two were connected together...

Quote

Well done again for doing this.  I am assuming that it will end up in the AltAppStore?

I have not looked yet at how to publish it yet but I would like to. It needs to come with a heavy warning though that it is meant for Openluup only. For UI7 and UI5, it probably works also but adds the hassle of creating a dev account on ecobee.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: Ecobee App Ported to Openluup
« Reply #5 on: April 27, 2018, 05:19:42 pm »
I have not looked yet at how to publish it yet but I would like to. It needs to come with a heavy warning though that it is meant for Openluup only.

I can help with the publishing, although it is documented at the start of the AltAppStore thread.  It's easy to enforce 'only openLuup' from the store by not enabling the Vera download button.  That's a standard part of the configuration.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Ecobee App Ported to Openluup
« Reply #6 on: April 27, 2018, 06:18:33 pm »
Ok I published it but there are version duplicates as I made a mess trying out things...
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: Ecobee App Ported to Openluup
« Reply #7 on: April 27, 2018, 06:21:19 pm »
I'll fix it tomorrow.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Ecobee App Ported to Openluup
« Reply #8 on: April 28, 2018, 10:08:03 am »
Sorry for the mess. I meant to post only two versions: 1.8 for UI5/UI7 and 2.0 for UI7/Openluup
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: Ecobee App Ported to Openluup
« Reply #9 on: April 28, 2018, 11:16:59 am »
OK, think that's done.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Ecobee App Ported to Openluup
« Reply #10 on: May 01, 2018, 10:24:22 am »
Thank you. Have now released version 2.01 with some bug fixes to retain API Key between Luup reloads and accidental API disconnects. Also improved house mode device appearance in ALTUI.

Edit: After one day of testing, I can report that the plugin is much more resilient on OpenLuup than on the Vera: I am seeing less frequent need to reset the API pin and the post Luup reload consistently use the correct temperature unit unlike the vera which would randomly display the thermostat in C or F after a Luup reload. This is likely due to what I have been reporting in various threads: The architecture of UI7 on the vera hardware is leading to instability related to execution speed of various functions in different threads being inconsistent.
« Last Edit: May 02, 2018, 01:49:31 am by rafale77 »
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline bwillette

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +3/-0
Re: Ecobee App Ported to Openluup
« Reply #11 on: May 12, 2018, 07:12:59 am »
Thanks for putting this together!

After installing on openLuup via the AppStore. I can?t figure out where to put the api key,  there?s only a Get Pin button on the control panel, and nothing obvious in the Attributes list.  I?m sure I?m missing something...

Thanks!

Offline bwillette

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +3/-0
Re: Ecobee App Ported to Openluup
« Reply #12 on: May 12, 2018, 08:05:14 am »
I followed the manual install process and copied the files from github and now see the api key field (I had previously installed the original ecobee plugin on my vera and think openLuup had downloaded those device files previously so the App Store install didn?t overwrite them).

I entered my dev api key and clicked Get Pin but am seeing this in the logs:


2018-05-12 05:58:31.332   luup_log:25: ecobee: task: Trying to getPin                                                                                                     2018-05-12 05:58:31.332   luup.task:: status=2 ecobee : Trying to getPin                                                                                                  2018-05-12 05:58:31.332   luup.variable_set:: 25.urn:ecobee-com:serviceId:Ecobee1.TSK was: Not yet authorized. Press 'Get PIN' once; wait for PIN; enter at ecobee.com. now: Trying to getPin #hooks:0                                                                                                                                              2018-05-12 05:58:31.333   openLuup.context_switch::  ERROR: /usr/share/lua/5.1/socket/http.lua:212: bad argument #1 to 'gsub' (string expected, got nil)                 

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Ecobee App Ported to Openluup
« Reply #13 on: May 12, 2018, 09:44:54 am »
I followed the manual install process and copied the files from github and now see the api key field (I had previously installed the original ecobee plugin on my vera and think openLuup had downloaded those device files previously so the App Store install didn?t overwrite them).

I entered my dev api key and clicked Get Pin but am seeing this in the logs:


2018-05-12 05:58:31.332   luup_log:25: ecobee: task: Trying to getPin                                                                                                     2018-05-12 05:58:31.332   luup.task:: status=2 ecobee : Trying to getPin                                                                                                  2018-05-12 05:58:31.332   luup.variable_set:: 25.urn:ecobee-com:serviceId:Ecobee1.TSK was: Not yet authorized. Press 'Get PIN' once; wait for PIN; enter at ecobee.com. now: Trying to getPin #hooks:0                                                                                                                                              2018-05-12 05:58:31.333   openLuup.context_switch::  ERROR: /usr/share/lua/5.1/socket/http.lua:212: bad argument #1 to 'gsub' (string expected, got nil)                 


Ok I changed the folder structure on Github which should fix the initial problem you had with overwriting files. Thanks for reporting this. I also released 2.02 which has a couple of bug fixes.
Regarding your last problem, it looks like you did not enter an API key. Can you try to download version 2.02 and after you entered the API key from ecobee dev and click on getpin, go to the variables and see if the API_key variable is populated?
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline bwillette

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +3/-0
Re: Ecobee App Ported to Openluup
« Reply #14 on: May 12, 2018, 11:07:44 am »
Unfortunately my Ecobee device refuses to render in AltUI now.  I cleaned out all the files, removed the plugin, deleted the old device and reinstalled from scratch. I see it showing up in the logs that it's setup and waiting for the PIN to be entered, however it's not showing up in AltUI at all now, its like the device is invisible for some reason :(