#Toggling through scenes?

1 messages · Page 1 of 1 (latest)

rigid bobcat
#

I’ve got three scenes for possible lighting conditions: all lights on, just the lamp, all lights off. What I want is an automation where I can press a button to cycle through from one scene to another. (Or if we want to get more complex, two buttons where I can cycle in either direction). I have the first version of this working where I manually set the conditions based on the device status. But I’m wondering if there’s a cleaner way to do it.
I think I could have one automation increment/decrement a counter, and another automation mapping the counter to a scene. But ideally I’d like the counter to be modified if someone changes the device state outside that automation. (Such as flipping the light switch off and on, which will reset the smart bulbs to on.) Is there a perfect way to do this?

#

It seems like I can use Scene on automations, but I can’t access whether they’re active or not. And it doesn’t seem like the scene gets marked as active if the devices go to that state without the scene being activated anyway.

sonic jewel
# rigid bobcat It seems like I can use Scene on automations, but I can’t access whether they’re...

So a scene is not "active" per se, It is stored set of states which get set when its "activated" but it itself is not active.

You could template an input select (dropdown) helper with your 3 options.
Then have an automation that triggers on this changing, which sets the right scene for what the input select has been changed to.

Then for your cycling you can have the button automation call input_select.select_next with the cycle flag targeting your helper. which will cycle the input select and therefore the above will active the scene you have cycled to.

This means you can have a dropdown to select easily on a dashboard too.

rigid bobcat
#

That’s slightly nicer than the counter, thanks. But is there no way to easily do the last bit (update the state so the input_select advances if the devices are adjusted to match another scene)?

wild pine
sonic jewel
rigid bobcat
#

Lets say the scenes are

  • lights on + lamp on
  • lights off + lamp on
  • lights off + lamp off
    In that order.

Let’s say you’re on input_selext 2 (lights off + lamp off) and then instead of using the HA automation, someone manually presses the button on the smart outlet for the lamp to turn it off. Now the input_select is still on 2, but the actual state of the entities is equivalent to state 3. If you trigger the automation again, it will move the input_select to 3 (which won’t do anything) and then you have to trigger it again to get back to input_select 1 and go to lights on+lamp on.

#

Essentially what I’d want is some generic way to recognize that the devices have set in a way that matches a particular Scene, programmatically

wild pine
rigid bobcat
#

That’s why I want a programmatic way to do it. Essentially some kind of trigger like “the devices were changed and now match the scene” that I could use to change the input_select to match. (Especially because if you do this wrong there’s a risk of an infinite loop)

wild pine
sonic jewel
hardy cliff
rigid bobcat
hardy cliff
#

Makes sense. Fair enough

sonic jewel
#

it is not exactly great...

#

so... in a template you can get a list of entities that are in a scene and therefore find their current state. but there is no way to get the scene state from templating...
so you could call a script that calls a shell_command that cats the scenes.yaml file then you use templating to pass that yaml to find a specified scene you want and get the target entities and states. then check the current states of those entities and return true/false.

so you then call this script with the scene name as a parameter. you trigger this when any of the entities in the scene change. so: light on -> does scene match? -> if true set input_select.

#

If there was a way of pulling the target states of a scenes entities in templating directly then it wouldn't be "THAT" hard to do...

#

would be something like this

{% set scene_match = namespace(match=true) %}
{% for entity in state_attr("scene.test_match", "entity_id") %}
  {% set current_state = states(entity) %}
  {% set target_state = "WE NEED THIS INFORMATION" %}  
  {% if current_state != target_state %}
    {% set scene_match.match = false %}    
  {% endif %}
{% endfor %}
{{ scene_match.match }}

except with a way to fill in the obvious blank...

#

Pulling the yaml and parsing it is the only way I can think of to get the info. but that is a bit messy.
But... If you want to go down that road, I am sure its "doable"...

wild pine
#

In programming, almost anything is possible 🙂

jolly lynx
#
rigid bobcat
jolly lynx
#

No, you're right, that isn't in there. I kinda remember also writing up something for that

jolly lynx
#
sonic jewel
# jolly lynx found it https://community.home-assistant.io/t/wth-why-doesnt-home-assistant-kno...

This tracks if devices have changed since the scene being activated to see if its still "active".
However I believe (and I could be wrong here) the question was more along the lines of, if I manually set everything to the same as what is in a scene how can I get it to detect "this setup is the same as scene xyz" and set my the selector to that.
simple example with 1 device:

scene a: light is off
scene b: light is on
scene selector helper set to scene a
someone then turns on the light
**magic happens**
scene selector knows that although a scene action was not called that scene b is now active.

That magic is where we would need to trigger on a device changing and it checking the current states against target states of a scene to know what is happening.

jolly lynx
#

Ah okay. That will be more difficult

wild pine
sonic jewel
sonic jewel
jolly lynx
sonic jewel
rigid bobcat
#

Home Assistant did that back in the days. It doesn’t work.
For example, transitions on lights, rounding differences in brightness or color temperatures, slight changes in color interpretation (and many more of these). These cause them to be almost never active.
This was my fear. I could see that happening very easily.

#

I think the answer is either “accept that you’ll get weirdness” or try to do something clever with checking to see if entities have changed and just making the next transition to set the scene that you think it’s already in?

wild pine
#

Anyway, I think it's a nice way of learning and to use the brain

rigid bobcat
wild pine
#

I'm sure it can be done, as I said earlier. The level of complexity is the thing 🙂

full heart
#

It'd be nice if templates could pull the paired list of entities/states set in the scene so you could pretty easily query if you're currently in that scene

floral bison
#

I made a simple automation to cycle scenes. I'm was not at all interested in it taking into account manual adjustment, just activate the scene that was called the longest ago for in the area.

  - variables:
      s_id: >-
        {% set area = 'Hall' %}
        {% set scenes = area_entities(area)
            | select('match', '^scene\.')
            | list %}
        {% set sorted = states
            | selectattr('entity_id', 'in', scenes)
            | sort(attribute='state', reverse=false)
            | map(attribute='entity_id')
            | list %}
        {{ sorted[0] | default(None) }}
  - action: scene.turn_on
    metadata: {}
    target:
      entity_id: "{{ s_id }}"
    data: {}