Custom sentence with condition

Hi,

When asking assist sattelite “turn on the lights”, it switches all lights in that room. However I like only that the main light switches on. I have not found any possibility to configure which lights should be switched on when using the turn on the lights command.

Therefore, I created an automation with the sentence and action to the turn on the required light. To limit the action only for the specific room I added template condition

{{ area_id(trigger.device_id) == “my_room” }}

The problem is, that now when somebody in a different room (or using web interface) asks “turn on the lights” it just responses “Done” and nothing happens. How to adjust the automation, so that if the condition is not met, a default sentence is processed (as if the automation is not enabled)?

Modify your automation to use an If/then action. Move your existing template condition to the If and your desired action to the Then. Then use the else to handle the rest with an area target:

...
actions:
  - if:
      - condition: template
        value_template: "{{ area_id(trigger.device_id) == 'my_room' }}"
    then:
      #Your room action
    else:
      - action: light.turn_on
        target:
          area_id: "{{ area_id(trigger.device_id) }}"
...  

I had the same problem and solved it with the area name.
Everything that act automatic such as turning the lights on via a motion sensor I placed in (area)_automated.
Example: kitchen_automated

The light that I want to control I place in the area I would like to use in a voice command
Example: kitchen

This way things work for voice commands and automations. The last one can ofcourse use any area.

Thanks for the good question.

I had this idea. We can use a label ‘mainlight’ to assign the main light in the rooms.
Then we reassign one phrase to turn on the selected lights, as you said.
The action looks like this:

actions:
  - if:
      - condition: template
        value_template: >-
          {{ (states.light |selectattr('entity_id', 'in',
          label_entities('mainlight'))|selectattr('entity_id', 'in',
          area_entities(area_id(trigger.device_id))) |map(attribute='entity_id')
          |list |count) > 0}}
    then:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: >-
            {{ states.light |selectattr('entity_id', 'in',
            label_entities('mainlight'))|selectattr('entity_id', 'in',
            area_entities(area_id(trigger.device_id)))
            |map(attribute='entity_id') |list }}
    else:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          area_id: "{{ area_id(trigger.device_id) }}"

Now the satellite in each of the rooms will turn on its main light.

"turn on all the lights " phrase still includes all the lights

Can’t you just give that specific light a voice alias (e.g. “main light”) and say “turn off the main light”?

1 Like

This won’t work for multiple rooms.
There will be a name conflict.

What do you mean by “conflict”.
I have multiple lights with the same alias in different rooms…

You are using an extra word for the command.
You cannot assign multiple master lights without using a group.

I was wrong about the error, the satellite already knows how to limit names within a area. Previously, it was impossible to control identical names without specifying a area.

Yes, I have multiple time the same alias in different areas.
When saying “turn on the main light”:

  • or you are using an area-aware satellite and it will turn off the light in the area the satellite is in
  • or you have to specify the area: “turn off the main light in the office”