Rhasspy can tell you the weather

Hmm, I am currenty trying to get into your WeatherReport class. Not understanding all the details, I get the feeling that switching this to English will be really hard as sentence construction is slightly different - there is a lot of hardcoded German in here. I might take a closer look at https://github.com/MycroftAI/skill-weather and see if I can extract some command line weather forecast reporter from there.

Keep up the good work. Unfortunately using hass is also not really an option for me as writing control logic is much easier for me in node-red (java script), c, and python.

I will also still study your grammar and code a bit more as inspiration for good questions to ask and answer regarding the weather, but I think turning your tool into a multi lingual weather reporter that runs from the command line is at the moment a bit out of my league and I need to fast track some other projects first.

Most of the hardcoded German is moved already, just the preamble for the detailed report is still in there. It just took a while because it was so much. Basically there are 3 parameters that can be used in sentences, and those are formatted by functions in the locale file. I will do a basic English translation that I ran out of time for yesterday either today or tomorrow so there is at least one sentence for each scenario which will make it easier to understand for you. The translation was always part of my plan for the script so it is no extra work for me.

If you find something that suits you more go for it, this script can be adapted for console arguments but it was never really intended for that so you might get lucky and find something that already does that.

Ah, I see a locale/english.py :smiley:

I like the userdefined functions.

Ok, convinced, I need to take another look. If I can understand all your slots an argparser should be easy and hopefully done in a day.

The slots will be translated in a few days also, I just need to fix my setup first. Hassio had an update and that broke my audio for rhasspy (again) so I need to learn how to use docker better and move away from hassio and to homeassistant.

So, I tried to create cli_weather.py module in the main directory that I want to call from __init__.py at one point if this modules is executed from the command line, but for starting I would like to just test cli_weather.py [args] alone first.

I am now a bit confused about the package structure. Most of your other modules refer to rhasspy_weather.globals which is not in the modules searchpath if I run anything from the main directory as there is “only” a rhasspy_weather.py file but not a package directory.

So if not moving things around too much, I can’t get around the error:

ModuleNotFoundError: No module named 'rhasspy_weather.globals'; 'rhasspy_weather' is not a package

Can you explain a bit more how the package structure is supposed to work - it might have to do with the whole thing being called a different way than I think?

That happens because I normally call the whole script from outside the folder that is on github. What is on github is in a folder called rhasspy_weather for me and that is the package that globals.py is in and that rhasspy_weather.py is in.

I am not very good at working with modules in python and sometimes refer to stuff by package name and sometimes just in a relative way. Python imports work kinda strange and I take it the way I can get it to work instead of trying for 2 hours to get a different way to work.

The exact way I call it is in the readme as custom_commands.py. That is on the same level as the rhasspy_weather folder that contains everything from the repository.

Thank you for your work! That looked perfect to me, so I tried it - starting with copying the sentences to my sentences.ini. (My profile is german as well. I use hass.io too, but did not get this far.)

Strangely, after saving the Sentences and retraining Rhasspy, Rhasspy understands me a lot worse than before.

Before I had mainly a few sentences to switch my lights on and off, which worked just fine. STT is Pocketsphinx and my Speech was transcribed and handled correctly.

After adding your sentences STT only understands gibberish - if any.

What did I do wrong?

Ok, not sure why you have to add rhasspy_weather. to things as it should also work without that (and also the .data_types should actually work as data_types without .), but that is no real show stopper here.

However, having a locale package actually breaks the use of gettext as there is a system locale package:

File "/usr/lib/python3.8/argparse.py", line 1671, in __init__
    self._positionals = add_group(_('positional arguments'))
  File "/usr/lib/python3.8/gettext.py", line 736, in gettext
    return dgettext(_current_domain, message)
  File "/usr/lib/python3.8/gettext.py", line 662, in dgettext
    t = translation(domain, _localedirs.get(domain, None))
  File "/usr/lib/python3.8/gettext.py", line 583, in translation
    mofiles = find(domain, localedir, languages, all=True)
  File "/usr/lib/python3.8/gettext.py", line 554, in find
    for nelang in _expand_lang(lang):
  File "/usr/lib/python3.8/gettext.py", line 213, in _expand_lang
    loc = locale.normalize(loc)
AttributeError: module 'locale' has no attribute 'normalize'

Can you rename (or I can refactor it too) the locale package into something different like manage_locales?

Shall we take this discussion to the issues in github?

Managed to hack it with this preamble:

import sys

import logging
log = logging.getLogger(__name__)

import globals
from data_types.config import WeatherConfig
from data_types.report import WeatherReport

# hack to allow correct locale to be used in argparse
syspath_backup = sys.path
sys.path=[]
for p in syspath_backup:
    if "weather" not in p:
        sys.path.append(p)
import argparse

I am restoring then sys.path when finished with parsing the arguments.

Ok, stuck again.
Was hoping to offer you a command line version, that can be inside you package, but that will not work.
So I will make another github project that is dependent on my fork of your project and uses it as is as package - that might still be messy with the location of the config.ini or the selected locale, but I will report back.

Can we assume that your license will be permissive (so not GPL! It should be at least LGPL, better MIT or BSD)? Else I am not allowed to use it in my code.

I never had any problem with that but I also don’t use rhasspy outside of testing right now. It might be because the sentences are to similar and it can’t differentiate between them. I myself use kaldi so far so it might work better for you, or it might not.

I will do so the next time I work on the script. Right now I am solving basic linux issues and docker stuff because hassio broke my rhasspy and I always find 3 things to solve for everything that works again.

Basically the way I set it up it needs to be called from outside the project, so that is basically intended. What you can write is a parser file that is basically a function wich takes everything as a parameter that you call from your console script and puts it into a WeatherRequest. But since there is not that much parsing for console that might not be needed.

This is the first thing on github that is actually my work and not some fork of other stuff that someone wants to actually use so I have not even thought about a license but it is intended to be copied, used and so on so yes, you can assume an permissive licence.

A very initial version of my command line parser using rhasspy_weather is up and working here:

not sure that I did understand everything right in adapting my parser, so feedback is appreciated.

Also parts of the answer are still in German, so I need to see, what still needs to be translated and forwarded upstream to @Deanara

Okay, I thought I got everything but I know where the German is coming from. I take the weather description from openweathermap and I thought I got everything but the language setting is part of the URL and I missed that. I thought my test was a mix of English and German because they get the language from the country code but it is an extra setting. Will be fixed.

The only German that should still happen if everything is working like I intend it to is when detail is set to true because I did not translate that part because I plan to rewrite it completely anyway.

EDIT: I put out a quick fix for the language issue. It is not tested because I am not home but it should work for now. country_code needs to be set to something in this list. And you need to put something in the zipcode setting because otherwise it will not set the country_code. I will move that into the lang file as soon as I get to my pc.

Switching to issues on github. at least one mini pull-request for you is waiting.

My parser is already working, I have integrated it into node-red using my --json '<json-string>' option. You have though to remember to send the json enclosed in single quotation marks (via JSONata "'" & json_message & "'") to the exec node running cli_weather --json

The repo also has some English language files (sentences and slots), you can use (as well as Deanara’s supplied English language file) to run Deanara’s software in English.

Thanks @Daenara, there are still some small bugs to catch and features to implement, but it’s already a lot of fun to use! Thanks for sharing.

I was thinking about a universal connection between intentHandlers and Rhasspy without Hassio.
her you can see my Idea
Connecting command line parser to mqtt

Maybee it’s usefull

My project also focuses on this area. My solution takes a different approach from yours though.

Forum topic: A generic HTTP server for handling Intents (not completely up to date).

Github page, with latest documentation: https://github.com/Wil-Peters/HomeAutomation

Continuing the discussion from Rhasspy can tell you the weather (at least if you speak German):

I would be happy with a way to just call a script for a specific intent instead of having to call one script for everything and filter out what I want to use a script for. I can handle mqtt output, if I want that, myself and I already found a python script that uses mqtt for something else where I can copy how it is done.

… and Apple buys darksky - so all these services will stop working soon.

(This doesn’t impact @Daenara’s module, but the idea to use darksky from node-red directly as mentioned by @jrb5665.)

@Daenara

Are you interested in a dutch translation?

Also, if you want I can have a look whether I can add some test coverage to your code. That’s what I usually do during the day :wink: