Automation Restarting

Hi there,

Relative newbie…

I’m looking to create an automation that involves a basic on/off smart switch which once pressed on, will then once pressed subsequently cycle through a variety of scenes with each press until it gets to the last one when it then turns off.

Whilst there are probably a few ways to achieve this, I wanted to start with the basics of keeping the switch on when a press of the switch would normally turn it off. The basic script I have using the automation wizard is this…

- id: '1729005437354'
  alias: New Automation
  description: ''
  triggers:
  - type: turned_off
    device_id: 6ac7500208bfe62c1e8b2259dbea9af1
    entity_id: 0d90ddb8c508a129cd2ec79c93a121e1
    domain: switch
    trigger: device
  conditions: []
  actions:
  - type: turn_on
    device_id: 6ac7500208bfe62c1e8b2259dbea9af1
    entity_id: 0d90ddb8c508a129cd2ec79c93a121e1
    domain: switch
  mode: restart

Of course, it’s a bit agricultural at present (have got plans using other triggers as well as the button press) but does the job - but only once. My (mis) understanding is that by setting the mode to restart, the automation would then be reset and available for subsequent presses. As it stands, when I select the switch off the first time, the automation works. Any subsequent presses when the switch is on, just turn the switch off and no reset to on occurs.

I appreciate that this is perhaps a basic issue and I’m sure it’s my misunderstanding of some basic concepts - would anybody be kind enough to give me a pointer as to where I may be going wrong?

Thanks,
Rich

Just to bring this one back up, further tinkering seems to show that after a period of about 10 seconds, the automation is available again for a one-time only process. Is there a default delay somewhere in the background?

i might be misunderstanding what you want this to do, but it feels a bit off.

first off though, you sould be avoiding device_id’s. here’s why and how:

since you’re new(ish) to home assistant, do your future self a favor and follow that page now before you get too deep.

ok, so for the thing you’re asking… what i think you’re asking is…

  • you want to use a smart on/off switch, but you’re not actually using the on/off. you’re just using it like a button. and each time you press it, you want to cycle through a set of scenes (including on and off… )
  • are those scenes about some other devices? i presume they aren’t setting this smart switch?

if that’s the right understanding, then i think you should have a different approach. if that’s the wrong understanding, please clarify.

i think you also might have a misunderstanding of mode: restart. restart tells what to do in the script if you invoke it while the script is in the middle of running. restart means cancel the current running and start over again. since your script is super fast and only turns on the switch, you’ll pretty much never restart.

ok, so if my understanding of what you want is correct, then here’s what i’d do:

  1. create a dropdown helper (this will create an input_select entity). populate that with the name of your scenes that you want to cycle through.
  2. create an automation that triggers when the state of the button (use state trigger) turn either to: on or off and from: on or off. (do this to avoid triggering when it goes to/from unavailable or other things like that)
    2a) when it triggers, call input_select.next to cycle through the different scenes.
  3. create another automation (or you can overload the automation above… but i’d do a separate one. have this one trigger on a change of state of your input_select helper.
    3a) when it triggers, get the new select value and activate the corresponding scene.
1 Like

Thank you @armedad !

Firstly, what that link describes makes a lot of sense. I’ll certainly be using that knowledge going forward.

Re: the scenes selection. Excellent suggestions. I think going forward, I’m going to change the switch for a 3 button option. One in the middle for on/off and then the others for cycling up and down the scenes.

I’ve got the automation for cycling through scenes working perfectly. Only issue I’ve now got is the using the value of the input select as the name of the scene to be activated. I appreciate this may be basic stuff, but any pointers to complete this final stage would be very much appreciated!

Thanks again

this example maybe will get you going. on the trigger for when the input_select changes, it sets the scene by grabbing the new value of the input_select and turning on that scene.

this means that you have to name the input_select options to be the same as the scene entity_id name… depending on what you’ve named those entity_id’s that might or might not be something you want… we can get more fancy from there, but this hopefully gets you started.

trigger:
  - platform: state
    entity_id:
      - input_select.test_dropdown
condition: []
action:
  - action: scene.turn_on
    target:
      entity_id: >
        scene.{{ trigger.to_state.state }}