Difference between scene and script?

Can someone elaborate on the differences between Scene and Script?

From what I can understand, scripts execute the actions in a guaranteed sequence (one after the other).
Do Scenes perform the actions in random order or maybe simultaneously?

other differences?

I don’t think that execution order is guaranteed with scripts. For instance, if you turn off a group of lights, then trigger something else, the zwave stuff will happen asynchronously and may finish after the “something else”.

But scripts support delays, which is handy. And can be turned off/stopped. Also, scripts can be called directly as a service, ie:

 - service: script.scriptname

instead of

  - service: scene.turn_on
    entity_id: scene.scenename

You may not need this yet, but you can use service_template (choose by template) in place of service in an action or script which sometimes makes it easier to implement if/else logic.

TL;DR, I used scenes when I first started with HA because it matched up with ideas I was used to from Vera. But once I figured out the value of scripts, I rarely use scenes.

2 Likes

Seems to me like scripts are a slightly more verbose, but more powerful version of scenes. I never use scenes.

1 Like

Thats helpful… I was just starting to think about setting up scenes but never thought to think that scripts are basically the same thing except more powerful… looks like I will just stick to scripts.

In my testing (which I haven’t yet found clearly documented), scenes are also unable to control anything other than lights . . . which really threw me off for a while also!

Eventually I also realized that scripts can accomplish anythign a scene can, but was designed much better to support any entity, command, etc.

So in case anyone else finds this and wonders why a Scene can’t do something like set the volume of your media player . . . or even control a switch (e.g. not a “light”), then just switch over to using scripts completely and finally it’ll work intuitively as expected.

1 Like

I’m relatively new to HA, did a search on “scene vs script” and found this thread. The question arose for me when I was setting up Google Assistant routines. I quickly realized that routines are a per-account thing: if I set a custom routine that sets up the home theater for viewing, the routine exists only for me, not for my wife. This behavior makes sense, given that routines are a matter of preference, but that led me to reevaluate how I set routines. If I want to modify the effect of a routine to turn on another device, for instance, do I really want to have to edit the routine for me, and then edit it again for my wife? It would be nice to make the change once and have it automatically be picked up by both accounts.

At first I figured what scenes would be the ticket. I set one scene on HA and then have the Google Assistant routine select that scene. The initial creation of the routine has to be done twice but any future change to the set of devices affected by the routine has to only be done once on HA by editing the scene that the routine triggers.

As i was figuring out how scenes work, I wondered whether I should be using scripts instead. I quickly came to the conclusion that scripts would be more future-proof than scenes. Everything a scene can do, a script can also do. Conversely, scenes cannot do many things that scripts can. So my rules of thumb regarding scenes vs scripts are: a) use scripts over scenes, b) if for some reason an integration won’t work with a script but will work with a scene, still write a script and additionally create a scene that just triggers the script.

Before I tried it, I was a bit concerned that I’d have to create one scene per script because Google Assistant does not know what a script is, but I was pleasantly surprised: scripts created in HA appear as scenes in the Assistant! :+1:

fwiw, adding to the above experiences, I try to use scripts for the operation part of things, and use the scenes for setting lights into dedicated , well, scenes :wink:

the scripts call these scenes and do other operational stuff.

That way, if you ever want to change a light setting, you can do that without having to fiddle into the automation or script. Or vice versa of course.

i think in some case combination of scene and script is a good way.

for exemple, you have two scripts who each need to turn on five lights, you can make a scene who turn on your five lights, and each script will then turn on your scene in place of the five lights.

Here’s a setup which corresponds to what I understand you describing. You have something like scene.five_lights. And you have script.one which turns on scene.five_lights and a script.two which turns on scene.five_lights. Instead of having to list all five lights in each scripts, you use one scene and then if you want to make changes to what gets turned on or off you just edit your scene instead of having to edit each script individually. That’s great…

… but you could just as well replace scene.five_lights with a script called script.five_lights which turns on the same five lights and have your two scripts launch script.five_lights instead of turning on scene.five_lights.

I’m not seeing any advantage to using a scene over a script in your scenario.

Everything you can do with a scene you can do with a script. The reverse is not true.

I agree, it’s exactly the same result, but, i think using scene is more “realistic” and more “logic”.
in real life, without any connected device, if you want to do the same things, your brain will decide if you open the light one, the light two, power on the tv, etc, … it’s the script. Your body will do the repetitive job, it’s the scene.

for exemple, y have a tahoma box, and the scene in the thaoma are scene in home assistant.

a good exemple can be a watching TV script.
the script will decide to launch the scene (wake up the TV), and will decide to launch the scene (close the screen windows for tv ) or launch the scene (power on the “night” light).
and the different scene wake tv will now the tv, the volume to use, the brightness of the light, the color of the light, wihich screen to close, …)

script is for code, scene if for data