Home » Blog » How To Cycle through Scenes using a Button in Home Assistant

How To Cycle through Scenes using a Button in Home Assistant

Hi!
Look at this! (show button that cycles through scenes). I created an automation that cycles through scenes in Home Assistant. Cool isn’t it? I will show you how to set this up in Home Assistant using a select helper and as a bonus I will show you how variables work in automations. Let’s do this!


⭐⭐⭐ NOTE: ⭐⭐⭐

This article accompanies a YouTube video. I wrote it for people who would rather read than watch a video. In order to keep doing this, I would like to ask you to also check out the video, leave a comment under the video, give the video a thumbs up and subscribe to my YouTube channel. This means that the video is offered more often to new visitors so that they also stay informed of the latest tutorials about Home Assistant.

Thank you for your support!

Ed

Click here to watch the video

Introduction

Wouldn’t it be great if you can cycle through scenes by simply clicking a button so that you and your partner can easily change the ambiance of your room? This is actually not very difficult to do and super handy. You only need a smart button for this like this Zigbee button, but any other button that you can connect to Home Assistant will do.

The steps that we are going to take in this Home Assistant tutorial are as follows:

  1. Creating scenes for a room
  2. Creating a Select Helper
  3. Creating an automation to switch between scenes
  4. and… creating an advanced automation that switches between scenes and makes it also possible to create a scene selector on your dashboard.

But, before we move on, please like this video and subscribe to my channel. I need your support so that I can keep creating these videos for you!

Creating the Scenes

Let me first show you the scenes that I created in Home Assistant for my office.

So we go to Settings and then we go to automations and scenes. We go to 
scenes and let’s go to the scenes that I created.
Those are these three scenes: Office Scene Cold, Office Scene Cosy, and Office Scene Green. Office Scene Cosy looks like this. I have some lights in here and 
some entities. The entities are my light groups.  Office Scene Cold is bluer and Office Scene Green is greener. So these are my office scenes and you see that the names are Office Scene Cosy, Office Scene Cold, and Office Scene Green.  

Did you know that scenes are not only limited to lights but that you can also add other devices to scenes? And that you can create scenes on the fly to quickly restore all your devices to a previous state? I published this video that explains exactly how scenes work. Check it out!

Creating the Select Helper

Our scenes are now set up. The next thing that we are going to set up is a select Helper. We can create a list of scenes in a select helper and we will use this select helper in our automation. Let’s set it up.

For helpers, we are going to settings, devices, and services. We click on helpers and we click on create Helper and we are going to create a drop-down helper which is our select helper. 
We’re going to give it a name Scene Entities, and we are going to give it an icon, for instance, palette. As for the options we are going to add the entity IDs for the three helpers that I’ve just shown so the scene cold, scene green, and scene cozy. So we’re going to add an option and the option is scene DOT office scene cold. We are going to add another option scene DOT office scene green and we’re going to add another option scene DOT office scene cosy.

So these are the three scenes that I just showed you in the scenes overview.
Click on create and now our scene selector is created.

Creating the Automation that cycles through our scenes

Now that we’ve set up the Select helper, we can start building our automation. The automation will automatically cycle through our scenes and activate each scene. Let’s set the automation up now.

For automations we go to settings, automations and scenes. We click create automation, we click start with an empty automation. We’re going to add 
a trigger and the trigger is our physical button so in this case, it’s a device and the device is called in my case office Tuya switch. And we are going to trigger on the single action trigger, and I’m giving it a trigger ID.  
I always give triggers a trigger ID so the trigger ID is button underscore press.
Now we are going to actions. We are going to add an action and the action is a call service, and the service is input select next so we are going to select the next scene in our select helper.  

The target is called scene entities. And we leave cycle on On so that if we are on the last option in the drop-down box it will go to the first one next. Now we’re going to add another action and that is the action that will actually activate the scene. So click add action. We are going to call our service again and the service in this case is scene Dot turn on. And now we cannot select a Target because we need a little bit of yaml here and for that. I’m going to click on the 
three dots and I’m going to click on edit in yaml and now I’m going to add the following code.
Remove this. Paste this. So what I’m doing here is targeting The Entity ID and the entity ID is taken from the drop down box so it takes the current state of the drop down box which is selected and that is input underscore select dot scene underscore entities. Our drop down box is called 
scene underscore entities. Let’s save this. 
I’m going to give this automation a name and now our automation is created.

Okay, the automation is set up! Let’s test this. Exiting! Yes! it works! Superb! We can now assign buttons in every room in our house to switch scenes. Isn’t that awesome?
Well, I think we can push this a little further and make sure that our select helper also works on a dashboard in Home Assistant. And in the progress, I will teach you how you can use variables in automations in Home Assistant. For this, we are going to create a slightly different select helper and our automation will also look a bit different.

Profile Picture Ed

If my videos help you and if you want to stay up to date with my tutorials and not miss anything to increase your knowledge of Home Assistant and Smart Home, subscribe to my channel and tick the bell. It also helps if you post a comment. This way more people get notified about these videos. I need your support so that I can keep creating these videos for you.

Oh, and don’t forget to hit the thumbs up for this video. This allows me to make more tutorials for you.

By supporting me, you also support my work as a music therapist to help people with mental issues.

Thank you!

Create the new Select Helper

Because of the fact that we want to show our select helper in a dashboard, we are going to use friendly names in our select helper like so.

We go to settings, we go to devices and services, we go to helpers and we’re going to create a new Helper. And again we’re going to create the drop-down Helper and this time we are going to call this the Scene Selector. We are giving it an icon palette.
And now we are going to add some friendly names so let’s say cosy, work,
and let’s say green. And now we created a new drop-down with 
only names in there. Let’s click on create and the new helper is saved.

Create a more advanced Automation

Our new select helper is now ready. Let’s create a new automation that uses this select helper as input for cycling through the scenes. This new automation will work with our physical button and our dashboard scene selector.

For our Advanced automation we go to settings, automations and scenes, create automation. We’re going to start with an empty automation.  
I’m going to add a trigger. the trigger is device and the device is again Office Tuya Switch.

The trigger is single action. I’m going to give it an ID. The trigger ID is button press, and I’m going to add another trigger because that trigger is needed for our dashboards. And that trigger is a state trigger. So we’re choosing 
for State this time and I’m going to say I want to trigger on the state of our input 
select scene selector which we just created. 
Now we go to actions. We’re going to add an action and the first action is an If-Then action. In the If we are going to click on Add Condition. If triggered by button press, then we want to go to the next option in our drop down list. So we are going to click on Then. We are going to call a service and the service is inputs select next and we are going to say the entity is our scene selector. 
And now we are going to Else. Let’s close these two, click Add Else and what I want to do here is that I actually want to turn the scene on. So I’m going to click on Add Action. I’m going to call our service again and the service is scene dot turn on. 
And now I have to select the target. The thing is that our drop-down list only consists of friendly names, so the name cosy, work and green and not 
of entity IDs. So here is where we are going to use variables to connect the friendly names to our entity IDs. For that, we go to the three dots right on the top. We click on edit in YAML and I’m going to add the variables somewhere here.  

I’m going to add the following code: variables. Then I’m going to declare the variable. The variable is called scene mapper in my case, colon. And now 
I’m going to fill the scene mapper with the three options that we have. And the first option is cosy colon and the entity ID of cosy is scene dot office underscore scene underscore cosy. We do the same for the other two. So we have work
and the entity ID is scene dot office scene cold and we had green. And the entity ID is scene Dot office scene green. So now we declared a scene mapper which contains a list of three values. But I will do that in the visual editor because that  
might be more clear to see. So I’m going to the three dots again. Click on edit in visual editor.  
We open the actions again. Scroll down to Else.
Click Scene Activate and now I’m going to click on 
the three dots over here. I’m clicking on edit in YAML again and I’m going to change the code data here by this code. What this code is doing is again targeting an entity ID but now it’s using our variable which is scene mapper and it’s picking the index of our scene mapper so either cosy, work, or green. Because the trigger to state is, if we look here, when scene selector changes, so the scene selector is our state trigger, which is our drop-down list that returns either cosy, cold, or green.
And so this will contain the value cosy, work or green. But because of the fact that we have the scene mapper, it will translate that to the 
corresponding entity ID. So to scene.office underscore scene underscore cosy or scene.office underscore scene underscore cold or scene.office  underscore scene underscore green. And that is how variables work. So let’s save this. Give it a name.

Click save and our new automation is saved. 
One thing which is really important to make this work is that we have to change the mode of this automation so we are going to the three dots over here. We click on change mode and we’re going to change it from single to queued.  Now we’re going to click on change mode and save it again.  
And now it will work. This is really important because if you leave it on single it will not work, because it needs the actions in the If and Else 
after each other immediately if you click on the button.

Our new automation is now ready. Let’s make sure that we disable our old automation, so that it won’t interfere with our new automation.

Let’s disable it. We go to settings, we go to automations and scenes. I’m going to search for our old automation which is scene cycle based on entity ID.  
I’m going to disable this automation so now that one is disabled.  

Okay, let’s test if our new automation works with our physical button. Here we go! One, two, three! Yes, it works! That’s great! Now let’s see if it also works on a dashboard. Let’s create that.

In my case, I’m going to tutorials. I’m going to click on the three dots. Edit dashboard. I’m going to add another view. Let’s call this Scenes. We make this really simple. Save it.  
I’m going to add the cards. Let’s do the entities cards. Remove these three.
We’re going to add the entity which is our drop-down input select scene selector. Save this, and now I can switch, let’s click done. I can switch scenes here and it will switch automatically to the correct colour too because of the automation that we just created.

We’ve created the dashboard and it works. So, we managed to create one automation that triggers based on a physical button and that also works together with our dashboard. And you learned how variables work in the process.

If you don’t want to type the code from the screen, you can download the code that I’ve created for this video via the ko-fi link in the description below. With this, you sponsor me, and make it possible for me to keep creating these videos for you.

I hope that I managed to explain how you can create your own automations using variables to cycle through scenes in Home Assistant. This is just one example of how you can use select helpers in Home Assistant. I bet you can think of much more use cases. Please let me know in the comments what your use cases are!

Oh, and a big shoutout to theFes for helping me to get my head around variables in Home Assistant!

I want to thank everyone who has supported me in making these videos and tutorials so far. I could never have done this without you. Thank you! You can support me through Patreon, Ko-Fi, or by joining my channel. If you also want to support me, look in the description of this video for the links. With that, you make it possible that I can continue to make these videos for you.

Oh, don’t forget to give this video a thumbs up, subscribe to my channel, and hit the notification bell.

I will see you soon!

Bye bye!



, ,

Back to all articles