Need To Confirm Scene As Automation Condition

Good evening,

I need to verify that a scene is active in an automation… In other words, if I have a scene called “Late Nite”, I have some automations I only want to run if the “Late Nite” scene is currently active.

I can’t find what condition to use. The state of the scene only allows me to select “Unknown” or “Unavailable” as a state, possibly because the scenes are managed by the Hue app, and not created in Home Asssistant. Another option would be to specify the color and brightness of a light as a condition, set to the color/brightness that would only be present when a certain scene is active?

Any thoughts how to make this work?

Thanks!

Because there isn’t one. Scenes do not have a very useful state*. They are like scripts. They run and set the devices to the required states and finish.

The way I work around this is by using an automation that sets the scene I want when an input select option is chosen.

In my other automations rather than calling the scene directly, I just set the state of the input select.

The advantage of doing it this way is that you can put the input select in a dashboard to select a scene manually as well as checking the state of the input select in automation conditions. e.g.

input select

lounge_scene:
  name: Lounge Scene
  options:
  - 'Off'
  - 'Automatic'
  - 'Manual'
  - 'Bright'
  - 'Night Light'
  - 'Watch Movie'
  icon: mdi:format-list-bulleted

automation:

- id: 3c6e8948-47f7-49ba-bc69-f78135315f98
  alias: 'Lounge Scene Select'
  trigger:
    platform: state
    entity_id: input_select.lounge_scene
    to: # null to triggers on all state changes
  action:
  - service: homeassistant.turn_on
    data:
      entity_id: >
        {% if is_state('input_select.lounge_scene','Off') %}
          scene.lounge_off
        {% elif is_state('input_select.lounge_scene','Manual') %}
          script.lounge_manual
        {% elif is_state('input_select.lounge_scene','Automatic') %}
          scene.lounge_automatic
        {% elif is_state('input_select.lounge_scene','Bright') %}
          scene.lounge_bright
        {% elif is_state('input_select.lounge_scene','Night Light') %}
          scene.lounge_night_light
        {% elif is_state('input_select.lounge_scene','Watch Movie') %}
          scene.lounge_watch_movie
        {% else %}
          scene.lounge_automatic
        {% endif %}

If you look closely you will see I am using the homeassistant.turn_on service instead of the scene.turn_on service because one of the options is a script not a scene. If all your options are scenes you do not have to do this.

Example, used in an automation condition:

- condition: state
  entity_id: input_select.lounge_scene
  state: Watch Movie

Or setting a scene in an automation action:

- service: input_select.select_option
  target:
    entity_id: input_select.lounge_scene
  data:
    option: Automatic

* Scene states show when they were last run. However this is not useful for determining if the state is actually in effect right now.

1 Like

I have to say, Tom, very neat. The problem you’ve solved here is one that has so far made me avoid scenes. Now I can start to reconsider using them.

1 Like

Tom,

Thanks, I can definitely see the benefit of doing it this way. Making this happen will be some work as I will have to change a lot of the flow of how I’ve already set things up (automations, interface buttons, etc…). I will try this with one room, and see how it goes.

One challenge I can see is that my Hue light switches are generally what sets the light scenes. You walk into a room, press once for the lights to come on, twice if you want “Late Night” (a little more relaxed lighting). These switches are going to be what sets the lights, not the HA interface in most cases. What I was trying to expand on from there is to have certain other things react differently depending on the lighting scene.

And what card do you use to have the dropdown show up? I’m trying different ones, but haven’t found it yet. I have a custom selector from the mushroom pack, but I try to use third-party elements only when they provide a function HA doesn’t. I’d rather use the built in lovelace as much as possible.

Still tinkering…
Thanks!

In my case I have many scenes that can be active. I use “old style” groups with mixes of lights and switches so I can use “all” which sets the state to true/false only when all lights/switches and in on/off state. And you have the added benefit of being able to include groups in other groups.

Then you can use custom:button-card or mushroom-entity to display and colorize icons based on the state. And you can trigger automations or apply conditions on the group state:

image

Snippet of YAML for first row:

type: custom:stack-in-card
mode: vertical
title: Light Groups
cards:
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-entity-card
        entity: group.doglights
        tap_action:
          action: toggle
        hold_action:
          action: none
        double_tap_action:
          action: none
      - type: custom:mushroom-entity-card
        entity: group.couchlights
        tap_action:
          action: toggle
        hold_action:
          action: none
        double_tap_action:
          action: none
      - type: custom:mushroom-entity-card
        entity: group.kitchenlights
        tap_action:
          action: toggle
        hold_action:
          action: none
        double_tap_action:
          action: none

An old style group would be defined in YAML like this (you can see that Pergola is contained inside of Dogs) which makes things very easy.

#
# Pergola
#
pergolalights:
    name: Pergola
    icon: 'mdi:home-variant'
    entities:
      - switch.switchlinc_relay_dual_band_1f_ad_f7
      - switch.switchlinc_relay_dual_band_1f_a8_f1
    all: true
# 
# Dogs
#
doglights:
    name: Dogs
    icon: mdi:dog
    entities:
      - group.pergolalights
      - switch.keypadlinc_on_off_1f_15_0a_main
      - light.in_linelinc_dimmer_4a_ad_d3
      - light.in_linelinc_dimmer_4a_ab_70
    all: true
1 Like

I’m using the mushroom card because it’s slightly prettier.

I suppose for the Hue switches I can look into automating setting the input select based on what those light switches do, to solve that… I’ll look at that variable later.

Groups could be handy in some instances… Specifically, what sent me down this rabbit hole is that I’d like my ambient lighting to work differently depending on the scene. So, under normal circumstances, the accent lights may automatically set one way if your lights are fully bright, but may set differently if you have a late night (dimmed) lighting scene applied. It makes no sense to have a dimmed environment, and than have an accent light still be super bright when you’re in dimmed mode, etc…

Still working on it…

I use an entities card with button cards and the input select:

Screenshot 2023-08-18 at 22-00-26 Overview – Home Assistant

1 Like

The input selector method definitely adds flexibility, but as Jeff Spicoli once said… “It’s gnarly, dude”. LOL

Essentially, I had to add a second automation for each task. I need an automation that triggers the input selection (like time of day or motion), and then an automation which sets the scene when the input selector is triggered.

The issue I’ve yet to solve is the Hue light switch. Essentially, depending on how many clicks you do, it sets the scene you created in the hue app (like “Late Nite”). But I need those button clicks to set the input selector in addition to turning on the lights.

Any thoughts on that one? I appreciate the suggestions.

Does the Hue light tell you which scene is selected in its attributes (Developer Tools → States), or does it generate an event that tells you what scene is selected?

You can listen for events in Developer Tools → Events

Of course not. LOL

event_types: initial_press, repeat, short_release, long_press, long_release
event_type: short_release
device_class: button
friendly_name: Guest Bedroom Switch Button 1

It would seem that the Hue hub does all the “thinking” here. The only thing that seems to register is “short_release”. If I press it twice it sets different lights than if I press it once. But I’m not sure how you would differentiate between two presses or three, etc… It doesn’t look like “repeat” is used; if I press twice it still registers “short_release”… It’s not setting a “scene”, just the light colors/brightness are applied.

Of course, a zigbee scene switch would fix this, but I would have to scrap my Hue switches, which defeat the purpose of “integration”. I’d rather work around this somehow.

Screenshot_20230818_113301

Yeah tricky. Maybe a counter with a maximum that matches your number of Hue scenes (minus one, it will start at 0). Create an automation that increments the counter on every short_release event?

You could then make a template sensor that converts the count to the scene.

Not sure how reliable that would be.

Also regarding this:

Here are the home assistant input theme variables so you can make that select box match your theme:

### Inputs ###
  input-ink-color: 'var(--primary-text-color)'
  input-label-ink-color: 'var(--secondary-text-color)'
  input-disabled-ink-color: 'var(--secondary-text-color)'
  input-fill-color: 'rgba(0, 0, 0, 0)' # transparent
  input-dropdown-icon-color: 'var(--primary-text-color)'
  input-idle-line-color: 'var(--secondary-text-color)'
  input-hover-line-color: 'var(--primary-text-color)'
  input-disabled-line-color: 'var(--disabled-text-color)'
  input-outlined-idle-border-color: 'var(--disabled-text-color)'
  input-outlined-hover-border-color: 'var(--disabled-text-color)'
  input-outlined-disabled-border-color: 'var(--disabled-text-color)'
  input-disabled-fill-color: 'rgba(0, 0, 0, 0)' # transparent

I cant remember exactly what is what but I think this one would be the select box background:

  input-fill-color:
1 Like

Applied the theme variables… Looks a bit more refined now, thanks for that…! I’ve been meaning to tweak some theme stuff, but I never found a list of all the variables. When I last messed with it, some of the elements were in flux because of the lovelace transition. So I never went too far down that rabbit hole. These changes take care of a few gaps I had, for sure…

Screenshot_20230818_172225

Right now, I need to make a checklist, and make sure I’ve got all the scenes covered and working right… Then I’ll experiment with the Hue issue. If I can’t figure it out, I’ll get a zigbee scene button and mess with it. I can probably repurpose the Hue switches in other places if need be…

Thanks for the help!

I don’t mean to keep dragging up this thread, but those who stumble upon this might run into this issue, so I’ll ask here. Maybe @tom_l has a suggestion?

For simplicity, let’s say “day” and “night” scenes are what I got. I made all those automations to determine when to set that day scene input selector, and one for the night scene input selector. Then I made all those automations that make things happen as a result of when that input selector is in effect. Mine is more complicated than that, but that’s the idea, and it works great.

Now the problem… When the sun comes up in the morning and night mode becomes day mode… how do I reset that input selector to day mode without the lights coming on? Are there any creative ideas to reset the input_select to a state without triggering the automation that runs when I select that input? It only needs to happen once a day to get back to a default point (day).

Thanks!

So I think I’ll just create an automation that disables the one automation, sets the selector, and re-enable the automation…

Duh. :slight_smile:

That will work.

But:

Elaborate on that.

Your input select should be the main control. If you always use the input select, whether manually or in an automation, it will already be in the correct state. Or is it the case that you are setting some scene otherwise and now want the input select to reflect that?

In other words: you always ever only change the input select. Everything else then triggers off the input select’s state changes.

Hi @parautenbach ,

Sure… What I have set up are “scenes” or “moods”, if you will. A general collection of related things, mostly lighting, but also other things… These moods (“scenes”) were just set by clicking a “scene_activate” toggle button. You clicked the toggle button, and the scene activated.

The problem I ran into is that I wanted automations to trigger only for specific scenes, which sent me down this more advanced way of doing things. It makes sense, and works great…

So the problem isn’t the original activation of the scene. If I set “Bright” for lighting (during the day), the main lights come on bright and there is an automation for the closet to light up bright when the door opens (based on the “bright” mood being set). That is because this scene would be activated when the sun is up, and you would want a bright light in there… But if you set the “Relaxed” scene for more subdued lighting, the main lights might be dim, and the closet would light up dimmer and in a color more suitable for that mood lighting… etc…

So the original way, you set a scene and done… This more advanced way, your button activates the selector and you need a second automation. You clicking the button doesn’t activate the scene, it sets the selector which requires another automation. So that second automation looks at the selector choosing the scene and sets the lights accordingly. That’s it right there. When you set back to the default “bright” scene again, it turns the lights on. I don’t need the lights on, I just want all the other things to know it’s back to default without triggering the actions, so automations work as expected again. Otherwise, you just stay in the last setting. In my case, the night lights keep coming on when I wake up in the morning, and when I open the closet, it lights as a night light instead of bright like you’d want in the morning…

Hope that makes sense…

So I created a “Sunrise” mood which now turns off the automation which triggers turning on the lights, sets the selector, then re-enables the automation so the rest of the accessories react properly to it being day again. And I can also set things specific to sunrise, like shades or whatever… at the same time.

My goal is to have each room react differently depending on time of day/mood… If I have nice mood lights set for after sunset, I don’t want to be blinded when I open the closet. And if I’m sleeping, I want specific things to act as night lights when moving around the house.

For those that stumble in and are curious, for lighting I have…

High Alert… Full bright…
Relaxed… Subdued mood lights…
Night… Very dim, can still see, but more geared towards sleep.
Night Light… Everything off, accent lights come on very dim when movement detected.

Sunrise… Reset to High Alert, without turning everything on…
Sunset… Reset to Relaxed, without turning everything on…

There are also some “maintenance” type scenes, which turn everything off if everyone leaves the house, but they aren’t manually selectable.

Any suggestions/criticisms are always welcome.

Thanks!

I don’t understand this. What’s the point if you set it to “bright” if it’s not supposed to do anything?

Like I said before:

This mechanism (how I understand it) makes the input select the main way of controlling things. You seem to be applying a scene directly (not as a consequence of changing the input select), which means the input select doesn’t control everything.

Looks like you need another state in your input select, but it’s hard to tell.

It might be better if you shared your actual configs and point out exactly where you want this different behaviour.

I know… Explaining it is tough.

The input_select IS the controlling mechanism. Think a 4-button scene switch on the wall.

Button 1, Bright…
Button 2, Relaxed…
Button 3, Night…
Button 4, Night Light…

They set the selector, which runs an automation based on that which turns on the light as desired… So you press Button 4 when you go to bed, and the main lights turn off. At that point, automations that run night lights would be enabled based on the fact that the input selector “Night Light” is active.

But the various automations based on the “Night Light” input selector keep running until you select something different… So in this case, I need them to start understanding it’s daytime again. I have to reselect “Button 1”, but I don’t need the lights to come on during the reset. For example, set a room back to the default “Button 1” when the sun comes up, but I don’t need the lights to come back on at that point, I just want the automations based on daytime to start firing again.

Hope that helps…
Thanks!

So you want one function (bright) to behave in two ways? I.e. if you were to select it manually lights must go bright, but then under these other conditions where you want to auto-select it you want it to do nothing?