How to use site id in HA automations

Im struggling to find the right formatting here.

i am using events to integrate with Home assistant

What i want to do is to trigger an automation if it matches an event “rhasspy_TurnOnLight” and also matches a specific site id.

I believe (perhaps incorrectly) that i should be able to do this by adding somethign like event.data._intent.site_id = 1
where the satellite i want to trigger this is called 1

End goal is i want a sentence matched to “turn off the lights” and for that command to only turn off the lights in the room the satellite is in.

If anyone has an example on the right formatting to target a site id in the event data that would be most appreciated.

Dunno if you are aware of the WIKI, so I post it here again :slight_smile:

About using the siteId, I think it will be trigger.event.data._intent.siteId but you can listen to incoming events in the developer section of HA

Go to the developer options → events → add rhasspy_TurnOnLight and click on Start Listening
When you trigger that event, it will show you all the details :slight_smile:

Hi, Yep i have that general setup in most of my Rhasspy based automations. This is the only one where im trying to only run an automation if the event is triggered AND siteID = “1”

I use the dev tools to listen to events so i know that the siteID is nested in the event as data._intent.siteID but i cant find the right way to use this as a condition as i find the HA documentation very confusing when it comes to how it needs to be written.

I will play try using trigger. in front of the data dict and see where i can get to.

So it was just formatting in the event data.
I was trying to access the site id by using event.data._intent.siteId

but this doesnt work in the event data section.
what works there is to base yourself from the data. point and then write the structure as you would see it in the dev tools output of the event.

so you put the following into the event data

_intent:
  siteId: "1"

thats it.

really good to have finally got it and hopefully this could be added to the docs somewhere.

1 Like

You can add a template condition and use {{trigger.event.data._intent.siteId}}

Most probably you have more than 1 sat, so I would add a Choose action in the automation or you could also switch an area instead of a light :slight_smile:

Ok. so a template condition. Could you show me a full example of this please.

And yes i have several sats. the reason for this is i want to just say “dim the lights” when im in the office and for it to dim the office lights.

so the office light automation will take “Turn off the office lights” from anywhere but will also allow “turn off the lights” if the office siteid is correct.

I’ll see if I can work something out :slight_smile:

1 Like

This works for me

alias: EventLights
description: ""
trigger:
  - event_data: {}
    event_type: rhasspy_Lights
    platform: event
condition: []
action:
  - service: mqtt.publish
    data:
      topic: hermes/dialogueManager/endSession
      payload_template: >-
        {"sessionId": "{{trigger.event.data._intent.sessionId}}", "text": "Ok,
        {{trigger.event.data.location}} {{trigger.event.data.action}} "}
  - if:
      - condition: template
        value_template: "{{trigger.event.data.location is defined}}"
    then:
      - service: light.turn_{{trigger.event.data.action}}
        data: {}
        target:
          area_id: "{{ area_id(trigger.event.data.location) }}"
    else:
      - service: light.turn_{{trigger.event.data.action}}
        data: {}
        target:
          area_id: "{{ area_id(trigger.event.data._site_id) }}"
mode: single

sentences:

[Lights]
turn ($actions){action} the ($areas){location} lights
turn the light ($actions){action}
turn ($actions){action} the light 
lights ($actions){action} 

“Turn on the light” will result in the EventLights event to be triggered.
Since trigger.event.data.location is not defined, it will call light.turn_on in the area trigger.event.data.location

The ID of that area can be found by area_id(‘office’)

Result without location:

With location:

Note the area_id can be a generated number or the name.

1 Like

Had to look up area_id lol.
Looks good. so using the template in the conditional to check if the location is defined and if not get the site id and use that as the area id. so the satellite would need to be named the same as the area and this would work from this single automation and sentence set.

Thanks for taking the time to explain it so well. has helped me a lot.

yes, but you could do it with entity_id as well. Or with a light group or whatever.
Everything which can be turned on or off basically.

Key is to check on the location and if not defined, go with the siteId. Lots of possibilities here :slight_smile:

I was originally going with the site id and translating that after but renaming the siteid to be the area name it is in makes more sense. as they wont move from where they are after.
for my purposes using a light group makes the most sense as if i say lights off then i dont want one or two i want them all off.
now just to figure out how to manage esppresence so it doesnt turn them back on when i want them off.
I am thinking a helper that manages the current wanted state until a reset time each morning.

Here is another example. Not sure if that is exactly what you want.

automation:

# WhereAmI
  - alias: rhasspy_WhereAmI
    trigger:
    - event_data: {}
      event_type: rhasspy_WhereAmI
      platform: event
    condition: []
    action:
    - data_template:
        text: You are in {{trigger.event.data._intent.siteId}}
        siteId: '{{trigger.event.data._intent.siteId}}'
      service: script.rhasspy_speak

# office light on
  - alias: rhasspy_ChangeLightState_office_light_on
    trigger:
    - event_data:
        state: 'on'
        name: 'light'
        _intent:
          siteId: 'sat-pi3'
      event_type: rhasspy_ChangeLightState
      platform: event
    condition: []
    action:
    - data_template:
        text: Ok
        siteId: '{{trigger.event.data._intent.siteId}}'
      service: script.rhasspy_speak
    - service: switch.turn_on
      entity_id: switch.office_main_light

1 Like

yep that looks great. and should help me with testign also.
Thanks!!