Help with Rhasspy+Home Assistant using intent

That is a bit strange indeed. 127 really is a file not found issue, but your mapping seems ok.
Is there a particular reason you do not use the Addon? It might help, even though the mapping seems ok there might be some issue we do not see. I use this exact file in the addon and that works without issues.

Try == instead of =

Just to have full power coming from my host while just the cpu destinated to the VM.

In the meantime I found out how to use it. I rewrite it here for noobs like me :slight_smile:

sentences.ini

[ChangeLightState]
room_name = (soggiorno | cucina | camera da letto | camera di adele | bagno principale | bagno secondario | corridoio | studio) {room}
light_name = (lampadario | striscia led| lampada scrivania | lampada simonasalvo | lampada fiore | piantana | razzo | jack lamp) {light}
light_cmd = (accendi| spegni){command}

<light_cmd> [il] [la] <light_name> [in] [ <room_name> ]

intent_script:

ChangeLightState:
    action:
      - service_template: >-
          {% if command == "accendi" %}
            light.turn_on
          {% else %}
            light.turn_off
          {% endif %}
        target:
          area_id: "{{ room }}"
          entity_id:
            - "light.{{ light }}"

Now I go test the addon to see how it changes. In the meantime another question. Rhasspy allow to use aliases? Basically call a light with different names.

EDIT: it works with lights with one word (es: piantana). Lights with composite word are not managed correctly (es: jack lamp is managed as light.jack lamp, without the "_" so the intent script doesn’t work)

Nice that you have found a way :slight_smile:

yes but it is still partial.

Can you help me understand how to manage light with complex name?

yeah ok,

What are the entity_id’s of your lights in Home Assistant?

For example

light.jack_lamp
light.lampada_fiore
light.lampada_scrivania

Have as friendly name:

Jack Lamp
Lampada Fiore
Lampada Scrivania

while other lights like

light.bagno_principale
light.bagno_secondario

But also
light.soggiorno
light.corridoio

Are ceiling lamps so friendly name is always

Lampadario (that’s why it’s important for me managing rooms)

With templates, you van apply a lot of code.
If you have a space in a lightname, you can replace it with an underscore

entity_id: light.{{ light | replace(" ","_") }}

I do not know if the friendly names are converted to lower case, but you can do that as well:

entity_id: light.{{ light.lower() | replace(" ","_") }}

1 Like

WOW! Templates are so powerful!

Now I can manage also those lights like:

light.jack_lamp
light.lampada_fiore
light.lampada_scrivania

for

light.bagno_principale
light.bagno_secondario
light.soggiorno
light.corridoio

still does not works. I cannot rename all those entities as light.lampadario so I think I need to use condition as well here.

Based on your example I made this.

it works! :slight_smile:

ChangeLightState:
    action:
      - service_template: >-
          {% if command == "accendi" %}
            light.turn_on
          {% else %}
            light.turn_off
          {% endif %}
        target:
          area_id: "{{ room }}"
          entity_id: >-
            {% if light == "lampadario" %}
              light.{{ room.lower() | replace(" ","_") }}
            {% else %}
              light.{{ light.lower() | replace(" ","_") }}
            {% endif %}

As promised the update for the script.

I added the rhasspy addon in HA VM and basically copy-paste profile folder into share in order to have same enviroment.

I then added entities in the slot_programs/hass/ folder but it doesn’t works neither.

When I first add it the error was

PermissionError: [Errno 13] Permission denied: '/share/rhasspy/profiles/it/slot_programs/hass/entities'

So I changed permissions to 0777 and the error changed to

CalledProcessError: Command '['/share/rhasspy/profiles/it/slot_programs/hass/entities', 'light']' returned non-zero exit status 127.

So maybe I made the same error again or there’s something that does no work anymore (I think the first)

Why not call them light.lampadario_corrido and such?

Good point LOL

In the meantime as written before I tried also with addon failing as well. At this point I think is clear it’s something I’m missing.

I think the addon fullfill the requirements ( curl and jq)
I added entities in this path /share/rhasspy/profiles/it/slot_programs/hass
I make it executable (rwxr–r–) : 0744

I restarted the addon and then added this to sentences.ini


[HassOpenCover]
covers = $hass/entities,cover
open [the] (<covers>){name}

[HassCloseCover]
close [the] (<HassOpenCover.covers>){name}

Same error when saving:

CalledProcessError: Command '['/share/rhasspy/profiles/it/slot_programs/hass/entities', 'cover']' returned non-zero exit status 127.

That is strange indeed, because I actually use that script as well

I do not know how good you are with a command line, but this line should output the states:
(replace token and url)

curl -X GET \
     -H "Authorization: Bearer ${token}" \
     -H 'Content-Type: application/json' \
     "${url}/api/states"

Yes it is. I also recreated it from scratch (the whole addon) but everything works now exept the script. Can I somehow manually trigger it?

See comment above.

You can create a temporary token if needed, unless you have written down your Rhasspy one

Just to be sure I should leave {} in url and token?

{192.168.2.101:8123}
{mysupersecretoken}

No, it should be this:


curl -X GET -H "Authorization: Bearer eyJ0eXAiandtherestofthetoke" -H 'Content-Type: application/json' "http://192.168.2.101:8123/api/states"

Also with http:// :slight_smile:
That should printout all states for all entities.

1 Like

OK when I use it in the docker console I see as response a wall of infinite text with A LOT of things (shopping list, sonarr tv shows and all my stuff).

But the again if I readd

[HassOpenCover]
covers = $hass/entities,cover
open [the] (<covers>){name}

[HassCloseCover]
close [the] (<HassOpenCover.covers>){name}

I see the same error… :frowning:

good start :slight_smile:
You token and url works
I do not know on what machine you are, but you can add the token and url in the script itself and run it from the command line.
You need to have jq installed.

It seems installed by default:

# apt-get install jq
Reading package lists... Done
Building dependency tree       
Reading state information... Done
jq is already the newest version (1.5+dfsg-2+b1).
E: Archives directory /var/cache/apt/amd64/archives/partial is missing. - Acquire (2: No such file or directory)

To run the script via command line I tried with

bash entitiesredo (I changed the name)

The values I changed:

# Read Rhasspy profile JSON
profile="${RHASSPY_PROFILE_DIR}/profile.json"

# Example: http://localhost:8123
url="http://192.168.2.101:8123/api/states"

# Long-lived access token
token="eyJ0eXAiOiJKxxxxxxxxxxxxxx"

No error

So I readded


[HassTurnOn]
lights = $hass/entities,light
switches = $hass/entities,switch
entities = <lights> <switches>

turn on [the] (<entities>){name}

[HassTurnOff]
turn off [the] (<HassTurnOn.entities>){name}

Same error.