Automation, read value from counter

Hi

Just started with HA, and it’s working great for simple things, on/off stuff. I now want to get a bit more advanced and start cycling through scenes with a single button press.
I figured I could just increment a counter every time I hit the button and use ‘choose’ to check this value then set the appropriate scene.

Counter part works fine but I can’t see how to read the current value of the counter in an automation. There does not appear to be an attribute for the current value, just min, max etc.

what am I missing. Wasn’t obvious from the help files.

Thanks

Rich

Isn’t the state the count/value?

I would use this: Input Select - Home Assistant.

It has a service to cycle through the options.

Let me know if I need to expand more on this, but basically you can have a UI button that calls a script. The script would cycle to the next option, and in that script you can then use the input select’s current value as an argument to the scene service to apply it. If you have a physical button, make an automation that triggers on a button press and then call the same script.

1 Like

@Hellis81 I figured so, but when I go to the automation I can only select min,max,initial etc?

@parautenbach that sounds interesting, if you have time more info would be appreciated thanks. In the meantime I’ll go read about it.

Rich

Don’t select anything there. The assumption is that you are using the state of the entity (the counter’s value). You only pick an attribute if you want to use something other then the state in that spot.

Fwiw I would do this more along the lines of what Pieter suggested. Something like this:

input_select:
  name: Scene picker
  options:
    - Scene 1
    - Scene 2
    - Scene 3

For the script what I would do to make it easy is make it so those options turned into the entity ID when “slugified” (all lowercase and every character besides letters, numbers and underscores replaced with an underscore). So then my script would look like this:

script:
  next_scene:
    alias: Next scene
    sequence:
      - service: scene.turn_on
        data:
          entity_id: >-
            {% set options = state_attr('input_select.scene_picker', 'options') %}
            {% set curr = options.index(states('input_select.scene_picker')) %}
            scene.{{ options[(curr + 1) % options | count] | slugify }}

The other thing you should do is in each one of these scenes add this:

scene:
  - name: Scene 1
    entities:
      input_select.scene_picker: Scene 1
      ... other scene stuff
  - name: Scene 2
    entities:
      input_select.scene_picker: Scene 2
      ... other scene stuff
  ...

That way any time one of those scenes gets executed the picker gets set to the current scene name regardless of how the scene was executed. If you select the next option as part of the next_scene script then the picker will get out of sync if someone or something turns on one of the scenes somewhere else.

Then just drop script.next_scene in a dashboard and you have a next scene button.

Alternatively if you actually want to use the select that can work as well. Just have to rework it a bit. Instead of having the script kick off the scene the script should select the next option in the list of options. Then have an automation which turns on the scene whenever the select changes.

@CentralCommand thanks, that’s really helpful. Not obvious you can miss out the attribute! I’ll try a script out on the weekend. Cheers

Thanks for typing out the solution, @CentralCommand. It’s exactly what I had in mind, but I’m only catching up on notifications now. Good luck, @Cadjockey!

It says optional on the app at least.
I have a slight memory that the documentations mention it also.
But perhaps it could be clearer?
I don’t have any suggestions though.

@CentralCommand thanks, it works great.

@Hellis81 odd, my iOS app does not say optional on any of these!

Thanks all

I have never bothered to install the app on an Apple. But the web version says optional too.

@Hellis81 weird. On both safari and the app I don’t get that