Dark Sky - Yawb4oH2 (Yet another weather binding for openHAB 2)

Hello,

sorry for maybe asking a silly question (don’t know how binding’s work), but currently DarkSky binding fetch data i.e. current:time-stamp out from Data Point Object - currently (just reading API Docs) delivering us a time.
What if I’d need moonPhase which is optional, only on daily Data Point Object? is it the only way to do GET https://api.darksky.net/forecast/[apikey]/[long,lat]?units=si ?

thanks

You can get moon phase from the astro binding I believe.

Hi @Bruce_Osborne,

yes, that’s possible, however my interest to have all data from one source :slight_smile: at least what I’m trying to achieve here.

I was reading those API Docs and there seem to be more interesting (to me) info, that’s why trying to understand if binding development is required or just .things / .items need to be written.

thanks

Hi Antanas,

In general it is no big deal to add any of those missing data be exposed via the binding. During development I did not see relevance to do so because there are other bindings providing similar information. Just list what you are interested in and I will submit an enhancement. Or may I invite you to add it on your own?

Hi Christoph @cweitkamp,
fully agree with you that other bindings might overlap, however I see some potential to use most of the available data from one binding rather install few more.
I would be happy if at least you could share some info how I could do that (honestly never developed Openhab bindings).

thanks

Here is a link to our developer documentation and you can find a simple PR which adds some new channels to a binding:

I recently migrated to 2.5M5 and thought I would give the DarkSky binding a try. I am currently using HTTP binding and JSON parsing to gather weather data by accessing the DarkSky API. However the HTTP binding is 1.x so it may be deprecated in OpenHAB 3.

My question is simple: How do I get the DarkSky binding to return weather data in Imperial not SI units? I’m sure I missed this, but I spent all afternoon looking for the answer and came up blank. BTW I’m using PaperUI for Thing setup, discovery and item paring to channels, and an .items file for the actual items.

Thanks for your help.

Hi John,

There is no specific configuration for the binding to return Imperial units. You have to configure it globally in your Regional Settings. In Paper UI: Configuration -> System -> Regional Settings: Click on “Show more”.

1 Like

Thanks Christoph,

Your help is much appreciated. That is a setting that I had not given any attention to. I also uncovered another issue that was causing me a problem. In my items I had not used any dimensions (Temperature, Dimensionless, etc) so the values being returned were apparently SI. When I added dimensions, then the Imperial values were returned but these values are not pure numbers but also include units as part of the string. As a result I had to recode items in the HabPanel to strip out the dimensions and display only the numbers, otherwise it would be treated as a Null. This is just an FYI for anyone else encountering such issues in the future. If there is a better way to handle this please let me know, as I am still learning all of these different coding languages, mostly by example.

<h4 class="text-left">Currently {{(itemValue('vWeather_TempF').split(' ')[0] | number: 0 || 0)}} °F</h4>

Update: with some minor recoding and refactoring I was able to get everything to work and fully migrated away from HTTP scraping to a full implementation of the DarkSky binding. Thanks for your help and the effort you put into making this binding. Great work!

Hi @cweitkamp I am wondering if there is some way to use this icon-id to set the icon on an item in a BasicUI sitemap?

Hi Andrew,

I am pretty sure you can use this guide for DarkSky too:

It’s actually a tad different in DaskSky for some reason I don’t understand. In OWM, the icon Channel gives you a link to the icon so the rule at that post just needs to wget the file and convert it from gif to png.

DarkSky, on the other hand, populates the icon Channel with the actual base64 encoded png file. So to do the same for DarkSky I set up a pipe command to strip the first 22 characters or so from the base 64 (it’s a mine type) and decode the result into a png file.

My rule, which shows both approaches, is as follows:


from core.rules import rule
from core.triggers import when
from configuration import weather_icon_path              import subprocess
from javax.imageio import ImageIO                        from java.io import File                                 @rule("Weather Icon",
      description="Copy the current weather conditions icon",
      tags=["weather"])
@when("Item vWeather_Conditions_Icon changed")           @when("System started")                                  def cond_icon(event):
    """
    Download the weather conditions icon from DarkSky and convert it from gif to
    png.                                                     """
    # OpenWeatherMap                                     #    cond_icon.log.info("Fetching weather conditions icon to {} from {}"
#                  .format(weather_icon_path, items["vWeather_Conditions_Icon"]))                                 #
#    results = subprocess.check_output(['/usr/bin/wget', '-q', '-O',
#                                       weather_icon_path,
#                                       str(items["vWeather_Conditions_Icon"])])
#
#    input_file  = File(weather_icon_path)
#    if not input_file.exists():
#        cond_icon.log.warn("Failed to fetch the weather icon!")
#        return
#
#    output_file = File(weather_icon_path.replace('gif', 'png'))
#    ImageIO.write( ImageIO.read(input_file), 'png', output_file)
#
#    results = subprocess.check_output(['rm', weather_icon_path])

    # DarkSky
    cond_icon.log.info("Fetching the weather conditions icon... {}".format(ir.getItem("vWeather_Conditions_Icon").state))
    dl = subprocess.Popen(['/usr/bin/wget', '-qO-',
                  'http://argus:8080/rest/items/vWeather_Conditions_Icon/state'],
                  stdout=subprocess.PIPE)
    dd = subprocess.Popen(['/bin/dd', 'bs=22', 'skip=1'], stdin=dl.stdout, stdout=subprocess.PIPE)
    dl.wait()
    f = open(weather_icon_path, "w")
    subprocess.call(['/usr/bin/base64', '-d'], stdout=f, stdin=dd.stdout)
    dd.wait()

Note, it’s in Python using Scripted Automation and it uses subprocess rather than executeCommandLine. It works for me so far but ymmv. I plan on submitting something a little more robust to the Helper libraries sometime soon.

Thank you to both @cweitkamp and @rlkoshak for your very helpful advice; based on your inputs, I developed my definitive solution as follows…

From my .items file…

String Local_Weather_Current_Condition "Synopsis [%s]" <g24weather> {channel="darksky:weather-and-forecast:g24:local:current#condition"}
String Local_Weather_Current_Icon_Id {channel="darksky:weather-and-forecast:g24:local:current#icon-id"}

From my .rules file…

rule "Download Weather Icon"
when
    System started or
    Item Local_Weather_Current_Icon_Id changed
then
    val icon = "/etc/openhab2/icons/classic/g24weather.png" 
    val path = "https://darksky.net/images/weather-icons/"
    executeCommandLine(String.format("wget -O %s %s%s.png", icon, path, Local_Weather_Current_Icon_Id.state.toString), 5000)
end

Note: that DarkSky supplies theses images openly in .png format from their user website, so the download is taken from that site, and not from their API site

1 Like

Hi @cweitkamp and @rlkoshak, it seems that I spoke too soon – it appears that the system (BasicUI or the Item itself) is caching the icon, so although my rule is downloading new weather images in a timely manner, and saving the new weather icon as “/etc/openhab2/icons/classic/g24weather.png”, nevertheless the BasicUI web page display often shows an older version of the weather icon.

Note: I tried adding a “touch” command to the rule to update the icon file’s timestamp, but this makes no difference…

=> Is there some way to force BasicUI (or the Item itself) to refresh it’s icon image cache??

PS I wonder if the problem is because the Current_Icon-Id Item changes its value (e.g. from “clear-day” to “clear-night”) thus triggering the Icon-Id rule to download the respective image, whereas the Current_Condition Item did NOT change its value (e.g. from “Clear” to “Clear”) so that the Current_Condition Item is not aware that it needs to reload its icon. Or something like that :slight_smile:

So I did wonder if adding something like this to the rule would force a refresh of the Current_Condition Item’s text and thus force a refresh of its icon too. But perhaps you can suggest a neater way to do that?

..
    val temp = Local_Weather_Current_Condition.state.toString
    Local_Weather_Current_Condition.sendCommand("..")
    Local_Weather_Current_Condition.sendCommand(temp)
..

I’ve never looked that closely at the icon changing. All I can suggest is to try it out and see if it’s makes a difference.

I am currently testing it; but it’s going to take a long time because occurrences where Icon-Id does change and Condition doesn’t (e.g. “clear-day” plus “Clear” => “clear-night” plus “Clear”) will be rather few and far between :slight_smile:

I added the binding to OH2 with the PaperUI and i get a ton of values, which are great, but i would only like to use a few. When i go to Things in OH2 and select the binding i see no channels at all (not even after a while) I am used to deselect all i do not need in the channels and then add the ones i want through .items so i can use these in my sitemap as well.

As you can see i’m pretty new to this. How can i add only the 5 or so channels i want from Darksky and make sure i dont get the other 100 channels?

Review openHAB concepts. The Thing will have whatever predefined channels.
You usually make an Item linked to a particular Thing Channel you wish to read or control.
Some “event” type channels can be referenced directly.

You don’t. A Thing will present all the available Channels. To pick and choose what Channels you actually use, you need to create and link Items to those Channels. If you have Simple Mode turned on, you have no control over this at all. All Channels will have Items created for them automatically.

1 Like