Simple "Tell me today's weather forecast"

I’ll attempt on my own for NWS. I am curious how you discovered what you detail below for openweathermap:

I looked around, and couldn’t find this info.

Remember the Developer’s Tools / State / Entity / weather.openweathermap
If you look at it you’ll see:

forecast:
  - condition: sunny
    precipitation_probability: 0
    datetime: '2023-08-29T20:00:00+00:00'
    wind_bearing: 308
    cloud_coverage: 1
    temperature: 73
    apparent_temperature: 69
    templow: 58
    pressure: 30
    wind_speed: 16.53
    precipitation: 0
    humidity: 64
  - condition: sunny
    precipitation_probability: 0
    datetime: '2023-08-30T20:00:00+00:00'

Each “chunk” (or dictionary entry) is referenced in the payload template that pulls the information key value. So each “forecast - condition” dictionary entry can be referenced via the [1] or [2] etc.
Make sense?

Yes, I believe so. So:
[1] will return the info from 'datetime: ‘2023-08-29T20:00:00+00:00’
[2] will return the info from ‘datetime: 2023-08-30T20:00:00+00:00’

Right now, the response from OWM via rhasspy is “sunny”, based on that condition, right? The first time it worked, it replied, “Clear Night”. Wow! Underwhelmed, yet happy it replied!

OK, so I deleted the OWM automation and attempted to create an NWS automation like so:

- id: '1691331852755'
  alias: Rhasspy-Weather
  description: ''
  trigger:
   - platform: mqtt
     topic: hermes/intent/Weather
  condition: []
  action:
   - service: mqtt.publish
     data:
      qos: 0
      retain: false
      topic: hermes/dialogueManager/endSession
      payload_template: '{"text": "{{(states.weather.khaf_daynight.attributes.forecast[0].detailed_description)}}", "siteId": "default", "lang": null, "id": "", "sessionId": "", "volume": 1.0}'
  mode: single

When trying to save it, I get:

Message malformed: extra keys not allowed @ data['0']

I copy / pasted your OWM automation back in and got the same error. Not sure what’s happening here.

You’ve got the payload template from the topic: hermes/tts/say

payload_template: '{"text": "{{(states.weather.khaf_daynight.attributes.forecast[0].detailed_description)}}", "siteId": "default", "lang": null, "id": "", "sessionId": "", "volume": 1.0}'

when you should have the payload template for topic: hermes/dialogueManager/endSession

payload_template: '{"sessionId": "{{ trigger.payload_json.sessionId }}", "text":"The forecast is ({{(states.weather.khaf_daynight.attributes.forecast[0].detailed_description)}})"}'

Here’s how it looks now:

- id: '1691331852755'
  alias: Rhasspy-Weather
  description: ''
  trigger:
   - platform: mqtt
     topic: hermes/intent/Weather
  condition: []
  action:
   - service: mqtt.publish
     data:
      qos: 0
      retain: false
      topic: hermes/dialogueManager/endSession
      payload_template:  '{"sessionId": "{{ trigger.payload_json.sessionId }}", "text":"The forecast is ({{(states.weather.khaf_daynight.attributes.forecast[0].detailed_description)}})"}'
  mode: single

When I attempt to save, I get the following:

Message malformed: extra keys not allowed @ data[‘0’]

Are you editing the automations.yaml via the GUI? Although HA has really, really improved what can be done via the GUI, there’s still sometimes issues. Read through this thread in HA:

I just checked your automation (copy it directly, and compared against mine), and its the same as mine, and correct (except for the single quote, double quote issue I mentioned previously).
I think you’ve got an issue with white space for some non-visible character somewhere in your automations.yaml.

You’ll should try to edit you automations.yaml directly, I use WinSCP to connect to my HA instance and to edit files. WinSCP is free:

There are linux tools that are similar.

Use WindSCP to connect to your box that running HA, edit the automations.yaml, first, delete the whole automation and save the file, then edit it again, copy and paste my automation into it and save. You’ll need to reload your automations.

This should fix things.

1 Like

No windows here in the house. Well, we have windows, but not Windows. Just linux.

I deleted the automation, and instead added your block in the automations.yaml file. I checked the file with a tool called ‘yamllint’. It parses the yaml file and spits out any error in positioning or formatting. (If you’re using a Debian based linux for your homeassistant, you should be able to install yamllint with apt: apt install yamllint).

Reloaded homeassistant, and tried the rhasspy command.

Here’s the error now:

2023-09-07 13:29:06.341 INFO (MainThread) [homeassistant.components.automation.rhasspy_weather] Rhasspy-Weather: Executing step call service
2023-09-07 13:29:06.350 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'attributes' when rendering '{"sessionId": "{{ trigger.payload_json.sessionId }}", "text":"The forecast is ({{(states.weather.khaf_daynight.attributes.forecast[0].detailed_description)}})"}'
2023-09-07 13:29:06.361 ERROR (MainThread) [homeassistant.components.automation.rhasspy_weather] Rhasspy-Weather: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'None' has no attribute 'attributes'
2023-09-07 13:29:06.363 ERROR (MainThread) [homeassistant.components.automation.rhasspy_weather] Error while executing automation automation.rhasspy_weather: Error rendering data template: UndefinedError: 'None' has no attribute 'attributes'
2023-09-07 13:29:06.368 ERROR (MainThread) [aiohttp.server] Error handling request

Looks like I’m getting close!

Woo Hoo!!
Can you try entering this into Developers Tools, Template:

{{(states.weather.khaf_daynight.attributes.forecast[0].detailed_description)}}

Returns:

UndefinedError: ‘None’ has no attribute ‘attributes’

So the problem lies somewhere in the formatting of that string, right?

Thanks for teaching me. I appreciate what you were doing.

Here’s the working line:

{{(states.weather.kful_daynight.attributes.forecast[1].detailed_description)}}

Looked at Developer Tools | States to find the correct attribute. Checked it on the Template page, and got the text returned.

Very happy!

Yep, you’re in a different local than me, and your NWS station is different. Super glad that its working for you now. Want to take the win and post your full automation with a note about checking the NWS entity in developers tools?

1 Like

FTW, Here’s the automation for NWS weather in my area (Near Los Angeles)*.

- id: '1691331852755'
  alias: Rhasspy-Weather
  description: ''
  trigger:
   - platform: mqtt
     topic: hermes/intent/Weather
  condition: []
  action:
   - service: mqtt.publish
     data:
      qos: 0
      retain: false
      topic: hermes/dialogueManager/endSession
      payload_template: '{"sessionId": "{{ trigger.payload_json.sessionId }}", "text":"The forecast is ({{(states.weather.kful_daynight.attributes.forecas>
  mode: single

This goes in the automations.yaml file (at the end is fine), NOT in the Automations UI.

You’ll need a corresponding Rhasspy Sentence (found in the Sentences tab). Should look similar to this:

[Weather]
what’s the weather forecast
what is the weather forecast
weather forecast please
tell me the weather forecast
tell me today’s weather
what will the weather be like today
what will the weather be today

Restart Rhasspy and Homeassistant, and you should be golden!

* the attribute that provides the weather for my area was found in the Homeassistant UI | Developer Tools | States. Search for “weather”. You should see something like “weather.kful_daynight” . Yours may look different. Whatever that difference, replace my “weather.kful” with whatever yours shows.

So cool!

1 Like

Just to add, as regards NWS; they do have a rate limit - too many requests (which I ran into). If you reach the limit, the State of the Entity will return “unavailable”.

Here’s the paragraph:

As a public service of the United States Government, we do not charge any fees for the usage of this service, although there are reasonable rate limits in place to prevent abuse and help ensure that everyone has access. The rate limit is not public information, but allows a generous amount for typical use. If the rate limit is execeed a request will return with an error, and may be retried after the limit clears (typically within 5 seconds).

This is the source:
https://www.weather.gov/documentation/services-web-api