The Vera Community forums have moved!

Advanced => Plugins & Plugin Development => Programming => openLuup => Topic started by: logread on March 09, 2016, 12:01:10 pm

Title: openWeather plugin for openLuup
Post by: logread on March 09, 2016, 12:01:10 pm
As I was moving as many plugins as possible from my Vera to openLuup on a Raspberry Pi, I stumbled across the fact that the Weather plugin I had obtained from the MiOS app store would not run under openLuup as it is encrypted by his author. Since I need the functionality, I wrote from scratch a basic plugin for my own purposes that reads a few data from the Weather Underground website. Far less functionality than the original plugin that only runs on Vera, but it can be expanded if there is interest.

UPDATE January 31, 2017:

Version 1.6 is now available on the "App Store" from the AltUI interface.

Documentation is at https://raw.githubusercontent.com/999LV/openWeather-plugin-for-openLuup/master/documentation/openWeather%20documentation.pdf

Changelog:
Version 1.0 2016-07-15 - first production version, installation via the AltUI/openLuup App Store
Version 1.1 2016-08-24 - major rewrite for cleaner and faster code, but no new functionality
Version 1.2 2016-09-22 - added language parameter to fetch the WU data in another language than English (@korttoma suggestion) and added today and tomorrow forecast data (high/low temps, conditions and text forecast)
Version 1.3 2016-11-13 - added WU display and observation locations (@jswim788 suggestion)
Version 1.4 2016-11-14 - added 'AllowEstimated' parameter variable, to ignore estimated data produced by WU when a weather station becomes somehow unavailable
Version 1.5 2017-01-19 - update suggested by @amg0 to allow for two icons to appear in the device in AltUI: Not only today's weather condition, but also tomorrow's. This change will be effective with a new release of AltUI by @amg0 to enable the display of the additional icon.
Version 1.6 2017-01-30 - amg0 update for 'WindSpeed' variable

If anyone is interested, the plugin files and installation instructions are available at https://github.com/999LV/openWeather-plugin-for-openLuup.git

Title: Re: openWeather plugin for openLuup
Post by: akbooer on March 10, 2016, 05:05:08 am
I took a quick look and was surprised to see this line  in the source code:
Code: [Select]
if this_device ~= nil then -- quick & dirty solution to the fact that init gets called twice upon luup startup
...since this is not a known issue. 

Then I looked further and saw that this is no surprise at all, since you explicitly call it twice: once on line 161
Code: [Select]
init()

...and once from the implementation file:
Code: [Select]
<startup>init</startup>

I also see that you create the 'child' devices as independent devices, rather than using the luup.chdev modules (which, admittedly, are a bit more cumbersome.)  This is fine, and exactly the way I would do it if running the Lua code as part of startup rather than a bona fide device.  What it means is that the child devices will not get deleted if the parent device is deleted.

Title: Re: openWeather plugin for openLuup
Post by: logread on March 10, 2016, 06:43:32 am
Many thanks Akbooer for taking the time to check my code. Much appreciated.

I now see the issue with the call to init() on line 161... Legacy from an early version that I had ran as a module for testing... and that I forgot to remove once the code was moved to a plugin version. Appreciate the pointer and will correct.

Regarding the creation of the child devices, I actually tried to use the luup.chdev module but I could not get it to work (the parent device implementation code stopped responding after the call to chdev.sync). I then decided to stop banging my head on the wall and just use luup.create_device despite the shortcoming that you describe. I may relook at this in a future version.
Title: Re: openWeather plugin for openLuup
Post by: akbooer on March 10, 2016, 07:02:27 am
chdev.sync will cause a reload if there are any changes in created child devices (eg. the first time you create them.)  This would certainly cause the handler to stop responding until openLuup.init() is up and running again.
Title: Re: openWeather plugin for openLuup
Post by: logread on March 10, 2016, 11:55:26 am
I addressed the startup and child devices comments from akbooer. Many thanks to him.

version 0.10 now on GitHub
Title: Re: openWeather plugin for openLuup
Post by: akbooer on March 10, 2016, 12:10:05 pm
Did you not remember to sync the repository?
Title: Re: openWeather plugin for openLuup
Post by: logread on March 10, 2016, 12:31:11 pm
You were faster than me...  ;D
Title: Re: openWeather plugin for openLuup
Post by: akbooer on July 23, 2016, 04:54:03 pm
Great to see this is now in the Alt App Store... downloaded to openLuup with one click of the download button... Plugged in my location and key and away we go.   Thanks!
Title: Re: openWeather plugin for openLuup
Post by: logread on July 23, 2016, 05:07:15 pm
Thanks Akbooer !
Not happy with the icon not rendering in the store though. Pointers welcome 🙂
Title: Re: openWeather plugin for openLuup
Post by: akbooer on July 23, 2016, 05:21:02 pm
Not happy with the icon not rendering in the store though. Pointers welcome 🙂

Fixed! You should have been using the "raw" file reference:

Code: [Select]
https://raw.githubusercontent.com/999LV/openWeather-plugin-for-openLuup/master/openWeather.gif
Title: Re: openWeather plugin for openLuup
Post by: a-lurker on July 23, 2016, 06:05:52 pm
@logread

You might be interested in this code.  If you see any benefit, feel free to use it:

http://forum.micasaverde.com/index.php/topic,15566.msg119956.html#msg119956
Title: Re: openWeather plugin for openLuup
Post by: akbooer on July 23, 2016, 06:17:22 pm
Or, equally, just use the JSON syntax call ?
Title: Re: openWeather plugin for openLuup
Post by: a-lurker on July 23, 2016, 06:47:28 pm
Yes that would probably be cleaner.
Title: Re: openWeather plugin for openLuup
Post by: logread on July 24, 2016, 02:00:23 am
Thanks to both @akbooer and @a-lurker ! Will take a look at the code (btw, I did not realize all the history about weather plugins)
Title: Re: openWeather plugin for openLuup
Post by: akbooer on July 24, 2016, 06:11:24 am
Or, equally, just use the JSON syntax call ?

This certainly works in openLuup:

Code: [Select]
local json = require "json"
local key  = "XXXXXXXXXX"
local req_fmt = "https://api.wunderground.com/api/%s/conditions/forecast/q/%0.6f,%0.6f.json"

local url = req_fmt: format (key, luup.latitude, luup.longitude)
local status, result = luup.inet.wget (url)
local info = json.decode (result)

print (pretty(info))
Title: Re: openWeather plugin for openLuup
Post by: akbooer on July 24, 2016, 07:52:30 am
...although if you're really an XML devotee, then you could (equally) use openLuup's XML parser to do the same thing...

Code: [Select]
local xml = require "xml"
local key  = "XXXXXXXXXX"
local req_fmt = "https://api.wunderground.com/api/%s/conditions/forecast/q/%0.6f,%0.6f.xml"

local url = req_fmt: format (key, luup.latitude, luup.longitude)
local status, result = luup.inet.wget (url,5)
local info = xml.decode (result)

print (pretty(info))
Title: Re: openWeather plugin for openLuup
Post by: a-lurker on July 24, 2016, 06:24:57 pm
Mmmm - certainly helps when a json and a xml decoder are "just" available. It took MCV sometime to distribute a JSON decoder with their firmware and I believe it still doesn't have a XML decoder as such? Presumably both these libraries are part of the Open Luup install?
Title: Re: openWeather plugin for openLuup
Post by: akbooer on July 24, 2016, 06:46:05 pm
Presumably both these libraries are part of the Open Luup install?

Absolutely!  Both XML and JSON required to read the UPnP files and respond to HTTP requests.  The JSON one is extremely well tested (about 200 test cases, both valid and illegal syntax, all available from the openLuup GitHub repository). The XML one is good enough for the job, but not so comprehensively tested.  Both are DOM-type, as you can see from the examples.
Title: Re: openWeather plugin for openLuup
Post by: logread on August 24, 2016, 07:12:25 am
Version 1.1 is available on the AltAppStore in AltUI and has been committed to GitHub https://github.com/999LV/openWeather-plugin-for-openLuup.
Major rewrite of code (taking into account some comments from this thread), paving the way for additional features soon...
Title: Re: openWeather plugin for openLuup
Post by: Mike Yeager on August 25, 2016, 09:56:07 am
Any chance you'd be interested in doing one for ForecastIO?
Title: Re: openWeather plugin for openLuup
Post by: logread on August 26, 2016, 02:17:30 am
I am afraid I am not planning to implement ForecastIO for now... I am rather soon to implement additional features offered by Weather Underground but not yet exploited by this plug-in.
Anything in particular you have in mind that is currently missed ?
Title: Re: openWeather plugin for openLuup
Post by: Mike Yeager on August 26, 2016, 11:06:58 am
I haven't looked at this plugin. I prefer the other due to being able to poll it more often...
Title: Re: openWeather plugin for openLuup
Post by: korttoma on September 22, 2016, 02:55:25 am
Hi @logread,

Would it be possible for your plugin to use of the "lang" parameter for the wunderground API call to get weather forecast in other language than English (Swedish for example)?
Title: Re: openWeather plugin for openLuup
Post by: logread on September 22, 2016, 03:03:17 am
Would it be possible for your plugin to use of the "lang" parameter for the wunderground API call to get weather forecast in other language than English (Swedish for example)?
Good suggestion... Should be very easy to implement via a user configured variable. I'll look into this when I get a chance.
Title: Re: openWeather plugin for openLuup
Post by: logread on September 22, 2016, 11:24:00 am
Version 1.2 is now available on the AltAppStore:
Title: Re: openWeather plugin for openLuup
Post by: korttoma on September 23, 2016, 04:24:44 am
Wow! Thanks @logread!

Now I will actually have to try your plugin :D
Title: Re: openWeather plugin for openLuup
Post by: korttoma on September 26, 2016, 01:19:33 am
Hi @logread,

I installed AltUI and the AltAppStore and then the 1.1 version of your openWeather (1.2 does not seem to be selectable to download in the AltAppStore).
Anyhow the 2 variables "Language" and "Metric" seems to be available and I do get forecast in Swedish so maybe I do have the correct version.

Thanks for making this even if it feels a bit excessive to install AltUI and AltAppStore just to get to your plugin.

Edit: I managed to install your openWeather plugin on my other Vera device manually without AltUI and AltAppStore. Seems to be working just fine :D
Title: Re: openWeather plugin for openLuup
Post by: logread on September 26, 2016, 01:47:15 am
@korttoma,

Thanks for the feeback... need to check the version mismatch.

BUT... you may not have noticed that this plugin discussion is in a subsection of the forum dedicated to openLuup... there is a weather plugin available as a regular Vera app and running under the regular UI (and AltUI). however that plugin cannot not run under openLuup as its developper chose to encrypt it.. this is why I wrote an opensource solution that can run

Hope this clarifies
Title: Re: openWeather plugin for openLuup
Post by: korttoma on September 26, 2016, 02:06:18 am
Yes, I know you made this plugin solely for openLuup and I respect that.
I also know about the regular weather plugin available for Vera in that app store but that plugin does not support the language parameter in the API cal. I did ask about supporting the language parameter but I don't think anyone is developing the plugin anymore.

Thanks again for providing the plugin and the addition I suggested ;)
Title: Re: openWeather plugin for openLuup
Post by: akbooer on November 03, 2016, 08:23:40 am
1.2 does not seem to be selectable to download in the AltAppStore).
Anyhow the 2 variables "Language" and "Metric" seems to be available and I do get forecast in Swedish so maybe I do have the correct version.

I noticed this problem too, and have just fixed it, so that 1.2 is now selectable.

The problem was that releases 1.0 and 1.1 were referencing the master repository, and 1.2 was not defined at all as a release.  As a result, selecting anything would download the latest version.  They now point towards their correct tagged releases.
Title: Re: openWeather plugin for openLuup
Post by: logread on November 03, 2016, 12:24:46 pm
I noticed this problem too, and have just fixed it, so that 1.2 is now selectable.

The problem was that releases 1.0 and 1.1 were referencing the master repository, and 1.2 was not defined at all as a release.  As a result, selecting anything would download the latest version.  They now point towards their correct tagged releases.
Thanks akbooer ! I am afraid I got confused at some point in time with Github  ???
Title: Re: openWeather plugin for openLuup
Post by: jswim788 on November 05, 2016, 01:19:15 am
Is there anything in particular I need to do to get Fahrenheit temperatures other than set the Metric to 0?  The plugin works fine for me, but stays in C regardless of the Metric value.
Title: Re: openWeather plugin for openLuup
Post by: logread on November 05, 2016, 02:40:38 am
Is there anything in particular I need to do to get Fahrenheit temperatures other than set the Metric to 0?  The plugin works fine for me, but stays in C regardless of the Metric value.
The 'Metric' variable is for wind or visibility data... temperature unit selection is automatic and based on the controller's system parameters. Can you please check in AltUI that in the /More/Controllers menu option you see 'TemperatureFormat' parameter set to 'F' ?
Title: Re: openWeather plugin for openLuup
Post by: a-lurker on November 05, 2016, 02:46:32 am
@logread - great to see you got this going. :D

I'm wondering if you considered naming your variables the same as used in the other weather plugin? The compatibility would be very useful. For example I have a plugin that reads the var 'Forecast.1.HighTemperature' where the forecast number can be 0 to 3 in my case. I think you use 'TomorrowHighTemp'

On a different issue, some of the variables the SID could be altered to be more standard but no big deal eg:

Code: [Select]
-- temperature vars
local TEMP_SENSOR_SID = 'urn:upnp-org:serviceId:TemperatureSensor1'

-- humidity var
local HUMIDITY_SENSOR_SID = 'urn:micasaverde-com:serviceId:HumiditySensor1'

Title: Re: openWeather plugin for openLuup
Post by: logread on November 05, 2016, 03:35:03 am
@a-lurker, thanks...

On the variables naming, it is on purpose that I chose 'TomorrowHighTemp' rather than 'Forecast.1.HighTemperature', to make it more user friendly... Also for now I discard forecast days 2 and 3. I did not realize one could have a plugin reading into the Weather device variables (as opposed to scenes/variable watches) rather than such plugin fetching the WU data directly ?

On the SID comment, I am confused. My plugin "CurrentTemperature" variable indeed has an SID =  "urn:upnp-org:serviceId:TemperatureSensor1" and the "CurrentLevel" humidity variable indeed has an SID =  "urn:micasaverde-com:serviceId:HumiditySensor1"... If you refer to the forecast values, it is right that I am using the plugin's own SID, but that was precisely because these are specific to the plugin v.s. 'standard' temperature and humidity devices... 

But I am open to making changes if that helps/makes more sense...
Title: Re: openWeather plugin for openLuup
Post by: jswim788 on November 06, 2016, 07:37:20 pm
@logread - you were correct about the F versus C.  Works now.  Thanks!

Request: can you add the weather station in the response from WU to a variable?  This helps to troubleshoot issues and to identify which station is being used when given a latitude and longitude.  I've seen cases where one station goes offline and WU redirects to the next closest, so it would be nice to have that tucked away in a variable to see which station is actually being used.  This also helps in cases where you accidentally put in an incorrect latitude and longitude.
Title: Re: openWeather plugin for openLuup
Post by: logread on November 07, 2016, 09:18:36 am
Request: can you add the weather station in the response from WU to a variable?
Interesting idea. I'll think about it for the next release
Title: Re: openWeather plugin for openLuup
Post by: logread on November 15, 2016, 12:31:50 pm
Version 1.4 has been released and available in the AltUI App Store.
First post of this thread has been updated accordingly.
Please let me know of issues/suggestions.
Title: Re: openWeather plugin for openLuup
Post by: korttoma on November 16, 2016, 12:40:19 am
Hi @logread just installed the updated L_openWeather.lua from github on my Vera test device.
So far everything is still working as expected except that I have found that some of the Variables are not according to the selected language (this is not something introduced in your latest version since it is the same in the previous one).

I don't know if this information is available from WUI for other languages than English but the variables I'm referring to are:

ConditionGroup
WindCondition

I don't think I will ever need to use "ConditionGroup" but it would be nice if "WindCondition" was available in the selected language.

In case you need to know I'm using SW for language.

Another nice to have feature would be the plugin version available as a variable also so that it would be easy to check what version is currently used. (this is just my opinion that you can ignore if you like since I do not belong to the intended user group using openLuup, AltUI and such).
Title: Re: openWeather plugin for openLuup
Post by: logread on January 19, 2017, 04:33:17 am
Version 1.5 has been released and available in the AltUI App Store.

It is a minor update suggested by @amg0 to allow for two icons to appear in the device in AltUI: Not only today's weather condition, but also tomorrow's. This change will be effective with a new release of AltUI by @amg0.

First post of this thread has been updated accordingly.
Title: Re: openWeather plugin for openLuup
Post by: logread on January 31, 2017, 04:33:37 am
Version 1.6 has been contributed by @amg0 to add windspeed variable and is available from the Alt App Store in AltUI.
Title: Re: openWeather plugin for openLuup
Post by: DesT on March 06, 2017, 10:16:16 am
Am I the only one having an issue when I try to update openWeather that it create all devices in double... instead of just updating ?
Title: Re: openWeather plugin for openLuup
Post by: akbooer on March 06, 2017, 11:03:32 am
Are there two parent devices, or are all these duplicates from a single parent?
 
Title: Re: openWeather plugin for openLuup
Post by: DesT on March 06, 2017, 11:05:55 am
I just test it again for you ;)

And it's a new parent with 2 new childs with no config!
Title: Re: openWeather plugin for openLuup
Post by: logread on March 06, 2017, 11:17:09 am
Are you seeing multiple plugin devices or only duplicate children (or both) ?

Are you running the plugin on Vera or on openLuup ?

The only instance I can think where children would be recreated is if you happen to change the existing children's Vera device ids (e.g. "OWT" for the temperature child and "OWH" for the humidity one), then new child devices will indeed be created at each restart... the plugin checks for these fixed ids to verify the children already exist or not.

In any case, easiest workaround could be to delete the existing plugin and reinstall the latest version.

I am afraid I cannot do better debugging on this since I no longer run any Vera, having moved all my HA to Domoticz since the beginning of the year after too much frustration with Vera... I just keep an eye on the forum to help as much as I can with the plugins I developed but please keep that limitation in mind.
Title: Re: openWeather plugin for openLuup
Post by: DesT on March 06, 2017, 11:19:22 am
I'm running it on openLuup!

And like I said before, it create a new parent with 2 new child!
Title: Re: openWeather plugin for openLuup
Post by: logread on March 06, 2017, 11:21:29 am
Sorry I missed the exchange you had with Akbooer... Can you please try the workaround I suggested ?
In any case, easiest workaround could be to delete the existing plugin and reinstall the latest version.
Title: Re: openWeather plugin for openLuup
Post by: DesT on March 06, 2017, 11:27:24 am
Looks like uninstalling/reinstall solved the problem!

thanks ;)