DarkSky forecast language, other than english

Hi all!
DarkSky API allows to receive hourly, daily and weekly forecasts in language other than english.
Now I’m using this dirty hack:
In file <config_dir>/deps/forecastio/api.py lines 26 and 30

url = 'https://api.darksky.net/forecast/%s/%s,%s' \
          '?units=%s' % (key, lat, lng, units,)

url = 'https://api.darksky.net/forecast/%s/%s,%s,%s' \
          '?units=%s' % (key, lat, lng, url_time,
          units,)

Adding lang=<preferred_lang>& in API request URL (after question mark) gives us a forecasts in preferred language.

For example, I’m using russian:

url = 'https://api.darksky.net/forecast/%s/%s,%s' \
          '?lang=it&units=%s' % (key, lat, lng, units,)

url = 'https://api.darksky.net/forecast/%s/%s,%s,%s' \
          '?lang=it&units=%s' % (key, lat, lng, url_time,
          units,)

List of available languages is in DarkSky API Docs.

Maybe it’s not very difficult to add this feature in HomeAssistant component as native, so we just set the language in config of darksky sensor, like units.

2 Likes

There is already an open request for this

1 Like

thanks for this trick,

Hi all,

this trick stil work.

Can it be emplemented into the sensor?

Thank you for the trick, still working very well…

I posted a comment on the github of the dark sky library to see if there is any news on the issue. ( https://github.com/ZeevG/python-forecast.io/issues/26#issuecomment-294379923 )

For those who want the little letters to put on the code, here is the doc : https://darksky.net/dev/docs/forecast

1 Like

UP hope to see it native

Any news on that?

Although I’m using DarkSky sensors, the folder " <config_dir>/deps/forecastio" does not exist. Is this trick no longer available?

Yes, unfortunately.
Maybe the structure of folders has changed with some release, my ‘deps’ folder is empty.

see at /srv/homeassistant/lib/python3.4/site-packages/forecastio

2 Likes

It’s here, thanks!

I Also found it here. Great! Thanks.

I use Hass.io- how can I get access to the file?

OK and how to get this into HADASHBOARD?

I don’t know if this is the best solution, but facing the same problem this is the best solution I could come up with for hassio:

  1. Download the python-forecast library from the github repo

  2. Copy the forecastio folder to any folder hassio has access to. I put it into /config/deps, i.e. the path of api.py is /config/deps/forecastio/api.py. Make sure to copy the whole folder, especially the __init__.py.

  3. Make the changes in api.py described by omeasire

  4. Create a custom component (here’s how) which adds the folder containing forecastio to the beginning of the python search paths. My file looks as follows:

     import sys
     sys.path.insert(0, "/config/deps")    
    
     DOMAIN = 'init_deps'
    
     def setup(hass, config):
         return True
    

This makes Python look for the library in /config/deps first and thus import your edited library. This should allow you to replace any library that can be installed by simply copying the scripts.

1 Like

@nodomain submitted a pull for this a while ago. Maybe he can push for the merge? :grinning:

https://github.com/ZeevG/python-forecast.io/pull/53

Hi Yipyip,

Followed your steps 1 till 3. At step 4 I’ve created a file ‘init_deps.py’ in ‘/config/custom_components/’. Contents of the file ‘init_deps.py’ is:

> import sys
> sys.path.insert(0, "/config/deps")
> 
> DOMAIN = 'init_deps'
> 
> def setup(hass, config):
>     return True

But after a restart of Hassio, the preferred language isn’t Dutch (nl), but still English. No errors in the logs or anything. What am I doing wrong?

Hi doubleUS,

have you added the line

init_deps:

to your configuration.yaml as described in the Creating components guide?
Without this line, your script won’t be called. I put it to the the very beginning of the file, right after the homeassistant: part.

Yes, I did. Have the following config:

And in configuration.yaml I have:

homeassistant:
  name: Thuis
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: !secret elevation
  unit_system: metric
  temperature_unit: C
  time_zone: Europe/Amsterdam
  customize: !include customize.yaml
  packages: !include_dir_named packages

init_deps:

Everything as it should. I think…

This looks correct (or at least like my solution which is working on my machine). To narrow down the problem, could you add logger statements in the init_deps.py and in the api.py (maybe somewhere around lines 26 and 30) to see if the two scripts are called?