Help on controlling more than one entity with button

Hello,

I am in the process of migrating from SmartThings to Home Assistant. Until I get a Zigbee stick I will be using the SmartThings integration. I was able to configure in automations.yaml a button that turns on a light on or off depending on the state of the button (value = pushed, or double)

What I haven’t figured out is how to control more than one light with the push of a button. Could I replace the entity with a scene, for example called MezzanineLights? I was able to configure scenes that does this, works great in Lovelace.

Also, how would I go about if I would like to associate more than one entity to the push of a button?

Would it be possible to adjust the code snippet below for both scenarios? Trying to learn, perhaps I didn’t look at the right place, but as a beginner I feel that often the documentation assumes one is past the beginner stage and knows what to do. As others pointed out, the learning curve is very steep for a beginner, every step is a struggle (in my case that included setting up duckdns, getting a smarthings token, figuring out how to edit automations.yaml…).

Thanks!

Code snippet:

  • id: MezzanineButtonPressedOnce
    alias: Mezzanine Button Pressed Once
    trigger:
    platform: event
    event_type: smartthings.button
    event_data:
    device_id: xxxxxxxx-xxxxx-xxxxx-xxxx-xxxxxxx
    value: pushed
    action:
    • data_template:
      entity_id: light.mezzanine
      service_template: light.turn_on

You don’t need data template.

action:
  - service: light.turn_on
    target:
      entity_id:
        - light.mezzanine
        - light.another_light
        - light.a_third_light

You can also turn on an entire area (if you have set up areas). Go in to developer tools and service calls, and choose light.turn_on, and then pick the area you want, and then change the view in to YAML mode and copy the area id. Then your automation would look something like this:

action:
  - service: light.turn_on
    target:
      area_id:
        - 9db86a674f6c49b6aa33f7c65ade7b3c

Many thanks! First code snippet worked great! I do have areas setup, but was not able to find out how to get the area ID. In developer tools and service calls, when choosing light.turn_on, I don’t seem to have an option to to choose areas. Out of curiosity I’ll try to find out the area ID and try out the second code snippet!

1 Like

I’m on my phone now, so I apologize about the screenshot but you don’t have something like this:

with the orangey/yellow area button?

Edit:

Go to configuration > areas
Click on the area you want and then click on the settings icon (cog). It tells you the area id there.

I was able to get the area ID with the settings icon (cog) — I guess it is intuitive now that I know where to look! :wink: Thank you !

I don’t have the targets option in Developer Tools : Services. Perhaps it’s because I am running Home Assistant Operating System instead of Home Assistant Supervised (or Core)?

Anyway, I now realize that a lot of powerful stuff can be done with the help of the Developer Tools menu. Learning curb is steep, but very powerful and impressive software!

No, you should definitely have the area target thing - that’s part of Home Assistant Core, it doesn’t matter how Home Assistant is installed. You are definitely running the latest version of Home Assistant?

Can you actually turn on the whole area now that you have the area id?

I think we can now get the area id from the template editor too… Let me test…

Yup

{{ area_id('living room') }}

Gives me the area id for the area called living room

I’m heading to bed now, but in theory that means that using data_template you should be able to use area_id: "{{ area_id('living room') }}"

Without needing to know it’s actual id

I can now control the area with the technique you have explained, awesome thank you !

I am running the latest version of Home Assistant as of now (core-2021.10.6, supervisor-2021.10.0). I was finally able to access to area and target section in Developer Tools : Services after clicking on the Go to UI Mode button (and as you mentioned it was very easy to get the area ID from there). It looks like I clicked on Go to YAML mode and in this mode the area and target section are unavailable.

Thanks again for your help!