Rhasspy + Home Assistant + Appdeamon

Hello there,

i’m just trying out to use rhasspy with Appdeamon and trying to build some simply apps. But I don’t understand how to use the intent from rhasspy in Appdeamon. Has anyone experienced with Rhasspy and Appdeamon. Here a example:

I want to say : “hey Rhasspy … set a Timer for 5 minutes” . I use a intent in Rhasspy like this

[Timer]
set a timer for (0..100){time} minutes

Now I’m tryring to use tts to simple confirm my intent. But it’s not working. Here my Appdeamon timer.py

 import appdaemon.plugins.hass.hassapi as hass
 from requests import post


class timer(hass.Hass):

    def initialize(self):

        self.listen_event(self.rhasspy_tts, "rhasspy_Timer")
        

    def rhasspy_tts(self, data, *args):
        time = data['time']
        url = "http://192.168.0.37:12101/api/text-to-speech"
        payload = 'i set a timer for' + time + 'minutes'
        headers = {
            "content_type": 'text/plain'
        }
        post(url, headers=headers, json=payload)

The Error log of Appdeamon is “TypeError: string indices must be integers”. Without “time = data[‘time’]” it’s working well. Rhasspy speaks to me (of course payload without time).

Does anyone have an idea? I think Rhasspy is very powerful when i get it running. It would be awesome to create so many skills with Rhasspy.

kind regards

Don_Murphy

1 Like

hey,

i found the mistake. I forget the event_id. That’s working:

    def rhasspy_tts(self, event_id, payload_event, *args):
        self.log(payload_event)
        time = payload_event['time']
        url = "http://192.168.0.37:12101/api/text-to-speech"
        payload = 'i set a timer for' + time + 'minutes'
        headers = {
            "content_type": 'text/plain'
        }
        post(url, headers=headers, json=payload

Maybe it’s helps someone in the future

1 Like

TypeError: means that you are trying to perform an operation on a value whose type is not compatible with that operation. An Iterable is a collection of elements that can be accessed sequentially . In Python, iterable objects are indexed using numbers . When you try to access an iterable object using a string or a float as the index, an error will be returned as TypeError: string indices must be integers. This means that when you’re accessing an iterable object like a string or float value, you must do it using an integer value.

For example, str[hello"] and str[2.1] as indexes. As these are not integers, a TypeError exception is raised. This means that when you’re accessing an iterable object like a string or float value, you must do it using an integer value . If you are accessing items from a dictionary , make sure that you are accessing the dictionary itself and not a key in the dictionary.

Python supports slice notation for any sequential data type like lists, strings , tuples, bytes, bytearrays, and ranges. When working with strings and slice notation, it can happen that a TypeError: string indices must be integers is raised, pointing out that the indices must be integers, even if they obviously are.