Start a TIMER script for different switches

Hi,

I want to add a feature that let me choose 2 values in HA (switch and time) and then start a timer to turn off the selected switch.

I’m stuck at the part of passing the selected switch to a “timer script”.

Here’s my script :

scripttimeroff:
  sequence:
    - delay: "00:{{ states('input_number.boxtimerlampesalon')| int }}:00"    
    - service: switch.turn_off
      entity_id: "{{ states('input_select.listswitches') }}" 

I have my input box :

  boxtimerlampesalon:
    name: Lampe salon timer 2 (minutes)                                                                             
    initial: 5
    min: 1
    max: 120
    step: 1
    mode: box

Here’s my input_select :

input_select:
  listswitches:
    name: List Switches
    options:
      - switch.sonoffsalon
      - switch.tv_lg 

For the “time” part, everything’s ok. My problem is with the switch name.

Trying to get the entity_id from the state of my switches list do not work.

Somebody have an idea how I can achieve my goal ?

My final goal is to have this working on my HADASBOARD wallpanel.

image

Try…

scripttimeroff:
  sequence:
    - delay: "00:{{ states('input_number.boxtimerlampesalon')| int }}:00"    
    - service: switch.turn_off
      data_template:
        entity_id: "{{ states('input_select.listswitches') }}" 
1 Like

Awesome, that did the job !

Thanks a lot for your fast and nice answer !

1 Like

No worries.

If you want to make it a bit neater in the UI you can change the options of the input_select to just sonoffsalon and tv_lg, and then make the last line of the script:

entity_id:"switch.{{ states('input_select.listswitches') }}" 

Again, good job ! Thanks that’s nicer like this :slight_smile:

1 Like