Rhasspy can tell you the weather

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:

A dutch translation sounds great but it needs to wait for a bit because I still need to finish one rewrite. I can maintain the german and english translation if I change anything or add to it but since I can’t speak dutch that translation would break when I do the rewrite.

Test coverage would be nice and I might even learn how to do that in more than the most basic theory. I study computer science but we didn’t learn such practical skills at all. We only learned they existed and did an example on 10 lines of python code in the very first semester and that does not help with anything.

I am having major issues with the imports in your project. When I clone the repo, by default none of the imports in rhasspy_intent.py work:

afbeelding

When I remove the rhasspy_weather from all these lines, the errors disappear, however I’m not sure it actually works.

I have similar issues when I’m trying to add a test file. I’ve added a file in the parser called test_rhasspy_intent.py.

I’m using PyCharm to do development. Any idea what’s going on here?

Not the imports again… I hate imports.

Basically the script only works if it is called from specific places. Calling it from within does not work. The part that is on github actually is the module rhasspy_weather so starting the script from inside the folder always results in that module not being found. I would fix it but so far every time I tried I either broke it or made a worse but still working chaos.

As for the parser part. There is a reason everything is imported via from … Import. For some reason just import never seems to work. I have no idea why and as far as I understand it should work but it just doesn’t. Import as sometimes works, even when import doesn’t.

There is a reason I started out with I hate imports. Nothing seems to work like I would expect.

Feel free to check out https://github.com/ulno/cli_weather it uses a fork from @Daenara as dependency - however, I pulled the newest changes from upstream and after all the changes things are completely broken now - however, maybe it can still serve as a reference how to use rhasspy_weather from outside.

The thing that most likely broke stuff was the new loading system for the config. I removed the globals file in favor of using get_config from config.py.

The only other change that could have broken stuff in your script would be pathing issues. I had to change how I get the config folder because it only worked if called a specific way and I needed to read the config from somewhere else. It worked way better than before for me so that one should not break stuff.

I did some more work today and added slot programs for most slots (location still missing, I have hope something like that will be added by rhasspy in 2.5 eventually) and I did quite a bit of work on the readme.

There now is a section detailing the project structure, what is included in the git and what not as well as a “what not to do” section that basically documents the weird behavior this script has. Both can be found under development.

I also rewrote the setup instructions and would love it if someone that has no idea how to set this up tries it and gives feedback.

Also there is a basic English translation for the sentences.ini but ulno’s is most likely better.
@ulno can I have permission to adapt yours to the new changes and include it in my readme?

Please feel free to use anything from my code/repo that you want (maybe give some credit :wink: )

I also updated my repo with the command line interpreter to work with the latest version from @Daenara. However, I am currently investigating mycroft’s weather skill and building a bridge to mycroft from rhasspy. It will use a mycroft instance that doesn’t need to be connected to the net.

Hi there, your custom weather seems awesome.
Is there any update on how to install this with Rhasspy 2.5?

I tried just following the 2.4 guide, but Im stuck because there are no more custom slot programs in the github. Are these no longer required?

I have reworked quite a bit of the project and the setup instructions are a bit out of date. I added a setup console script that generates the slot programs and automatically creates the symlinks needed. Make sure to edit the setup script because it defaults to a German profile at the moment if you want to use it. You can also just execute generate_slots.py. To get the slot programs, you need to add a ‘-x’ flag to it, otherwise it will create a slot file.

If you don’t plan on changing the contents of the language file you use on a regular basis you can just generate regular slot lists and copy them in the correct folder in your profile. That in combination with the usage of rhasspy hermes app negates the need to install rhasspy_weather inside the docker (if you use that, if you just have both installed on your system you don’t have that problem).

I also would suggest you try out the testing branch which started out as exactly what it is named but ended up being a, almost complete, rewrite. I still have some tiding up to do and, as you noticed, I need to update the documentation, but it should be feature complete by now.

There is also no need for a custom command script anymore, since 2.5 supports mqtt. Here is my current test setup for the rhasspy hermes app:

import logging
from datetime import datetime

from rhasspyhermes.nlu import NluIntent

from rhasspyhermes_app import EndSession, HermesApp

from rhasspy_weather import weather

_LOGGER = logging.getLogger("SkillListener")

app = HermesApp("SkillListener", host="redacted", port=1883, username="redacted", password="redacted")

@app.on_intent("GetWeatherForecast")
@app.on_intent("GetWeatherForecastTemperature")
@app.on_intent("GetWeatherForecastCondition")
@app.on_intent("GetWeatherForecastItem")
async def get_weather(intent: NluIntent):
    """Get weather"""
    forecast = weather.get_weather_forecast(intent, config_path="../rhasspy_weather_config.ini")
    return EndSession(forecast)

app.run()

To use the weather script with the hermesApp you need to set the output to rhasspy_tts because unlike with the command script rhasspy won’t read the text on its own.

1 Like

Hallo,
vielen Dank für das Bereitstellen. Da ich aber noch ein blutiger Anfänger bin, brauche ich doch dringend Hilfe, wie ich genau vorgehen muss.
Ich habe nun pip3 install rhasspy-hermes-app installiert. Aber jetzt fangen die Probleme an: wo und wie muss ich das hier hinkopieren:
@app.on_intent(“GetWeatherForecast”)
@app.on_intent(“GetWeatherForecastTemperature”)
@app.on_intent(“GetWeatherForecastCondition”)
@app.on_intent(“GetWeatherForecastItem”)
async def get_weather(intent: NluIntent):
“”“Get weather”""
forecast = weather.get_weather_forecast(intent, config_path=PATH_TO_RHASSPY_WEATHER_CONFIG)
return EndSession(forecast)

Ich hoffe, du kannst einem Anfänger auf die Sprünge helfen. Vielen Dank!

Ich vermute du hast den Teil aus dem github wiki kopiert. Der Artikel dort setzt voraus das du schon ein funktionierendes Setup für rhasspy-hermes-app hast und gibt nur an, was man dort ergänzen muss damit rhasspy_weather funtioniert. Wenn du den Forenpost über deinem anguckst, siehst du dort mein komplettes Skript. Das kannst du einfach kopieren und in eine python Datei einfügen (pass auf die Formatierung auf, Einrückung ist wichtig). Damit dieses Skript funktioniert musst du rhasspy-hermes-app und rhasspy_weather installiert haben. Wenn du das gemacht hast, kannst du das Skript auf der Konsole ausführen und es sollte was tun. Falls du vorher noch nicht mit python gearbeitet hast würde ich dir empfehlen dir die Grundlagen zum installieren und ausführen anzulesen, das ist zum arbeiten mit rhasspy recht gut zu wissen.

Ich persönlich benutze das Skript mit docker-compose um es in einem Container laufen zu lassen. Das hat vor allem für mich den Vorteil, dass ich sonst in recht große Probleme mit verschiedenen python Versionen laufen würde da rhasspy_weather nicht mit python 3.9 läuft, andere Software das aber braucht. Alles in seinem eigenen Container und es läuft problemlos.

Wenn du es mit docker versuchen möchtest ist hier der Inhalt meines Dockerfile:

FROM python:3.7
RUN apt-get update && apt-get install -y git python3-pip && \
	pip install rhasspy-hermes-app rhasspy-hermes && \
	git clone https://github.com/Daenara/rhasspy_weather.git && \
	pip install ./rhasspy_weather

COPY rhasspy_weather_config.ini /
COPY SkillListener.py /
COPY config.ini /
	
WORKDIR /
ENTRYPOINT ["python", "-u", "SkillListener.py"]

Diese Datei installiert einen Container mit rhasspy-hermes-app und der aktuellsten Version von rhasspy_weather, kopiert SkillListener.py (das python script vom Post über deinem), rhasspy_weather_config.ini (die Config für rhasspy_weather) und config.ini (Config für rhasspy-hermes-app, siehe unten) in den Container und führt dann SkillListener.py aus. Die drei Dateien müssen dazu im selben Ordner liegen wie das Dockerfile. Ich habe alle diese Dateien in einem Ordner namens mqtt_skill_listener was relevant ist weil dieser Ordner in der docker-compose.yml steht.

config.ini

[mqtt]
client=MQTTSkillListener
server=
port=
user=
password=

[rhasspy_weather]
config=rhasspy_weather_config.ini

Um die config.ini zu benutzen musst du unter mqtt die Daten von deinem mqtt Server eintragen.

Um das Ganze mit Docker zu benutzen kannst du entweder docker-compose benutzen, hier meine (gekürzte) docker-compose.yml:

version: '3'
services:
  mqtt_skill_listener:
    container_name: mqtt_skill_listener
    build: 
      context: ./mqtt_skill_listener/
      dockerfile: ./Dockerfile
    restart: unless-stopped
    network_mode: host

Es geht auch nur mit docker, dafür kenne ich mich mit docker allerdings zu wenig aus.

Grundsätzlich musst du rhasspy-hermes-app und rhasspy_weather installieren und dann muss in irgendeiner Form ein python Skript laufen für rhasspy-hermes-app was die Funktion die du in deinem Post hast beinhaltet (auch in abgeänderter Form).

Da du blutiger Anfänger bist solltest du dich etwas in python einlesen und entweder in python venv oder in docker da du sonst in Probleme laufen wirst wenn du verschiedene Python Programme hast deren Voraussetzungen inkompatibel sind. Meine Wahl ist dafür auf docker und docker-compose gefallen da venv nur für python funktioniert und es aber auch mit Linux Paketen Probleme geben kann.

Ich hoffe meine zusammenkopierte Anleitung hilft dir, ich bin für Fragen offen aber ich bin selbst noch relativer Anfänger was Linux angeht, ich arbeite sehr viel mit google um vorwärts zu kommen. Das Setup mit docker was ich beschrieben habe läuft bei mit, ist aber noch recht neu und ich finde vermutlich noch einiges daran was ich ändern werde wenn ich wieder aktiv an rhasspy_weather arbeite, deshalb ist das nicht in der wiki enthalten. Die wiki selbst setzt python Kenntnisse voraus (es steht soweit ich weiß nirgends wie man rhasspy_weather überhaupt installiert) und gehört verbessert, im Moment liegt mein Fokus aber eher auf anderen Projekten und ein Tag hat nur eine begrenzte Anzahl an Stunden daher beantworte ich lieber Setupfragen im Forum wenn jemand rhasspy_weather benutzen will statt Stunden in ein wiki zu investieren was vermutlich eh kaum jemand benutzt.

Daenara

Short English explanation for anyone trying to use the docker stuff provided here. Take the script from two posts above, name it SkillIstener.py, put it in the same folder as the Dockerfile (first codeblock above). copy the content of the 2nd codeblock to a file named config.ini, that is the config used for rhasspy-hermes-app. Add your mqtt credentials in that file abd said file in the same folder as the Dockerfile. Put a rhasspy_config file named rhasspy_weather_config.ini in the same folder. 3rd codeblock is my docker-compose.yms stripped to only contain the skill listener stuff. Rename your folder that contains that stuff mqtt_skill_listener (or change the foldername in the docker-compose.yml) and you should be good to go. This setup works for me but is pretty untested (which is why it is not in the wiki)

old thread, i know, just wanted to let you know that i installed rhasspy weather as a hermes app and it’s working like a charm.

1 Like

There is some bug in the logic that happens close to midnight that I haven’t managed to track down, but otherwise this should still work fine. I only update if there is something to update. Good to know others still find this useful

yes i heard the weather skill talk about midnight from time to time, i guess i’ll change that to a more generic error message: „sorry, can’t get that info“ or something …

Hi Kay,

im quite new to rhasspy, node-red and HA.
I’m using these 3 all in docker-compose.
My problem is to get all of the spoken text to node-red.
Example: Wie ist das wetter in klein-ober-unterhausen
How do you make it, to get “klein-ober-unterhausen” to your msg.slots.city in node-red?