Running two scripts with on off button

Hi all, I have read a few previous post but I was not able to get this working! hopefully someone can help this newbie:
I have create two scripts and they both worked. and they show up on HA as two different scripts as expected.

I am now trying to make it show up on HA as ON OFF button to running the different scripts. I tried command_line and template platform and they did not work.

  - platform: template
    switches:
      modified_golf_2:
        friendly_name: "Modified Golf 2"
        turn_on: 
          service: script.turn_on
          entity_id: script.play_golf_on_2      
        turn_off: 
          service: script.turn_off
          entity_id: script.play_golf_off_2
  - platform: command_line
    switches:
      modified_golf:
        friendly_name: "Modified Golf"
        command_on: 
          service: script.turn_on
          entity_id: script.play_golf_on_2         
        command_off: 
          service: script.turn_off        
          entity_id: script.play_golf_off_2

template platform say “Invalid config for [switch]: required key not provided @ data”
command_line platform buttons show up but dont work

this is the exact error message for switch template:
ERROR:homeassistant.config:Invalid config for [switch.template]: required key not provided @ data[‘switches’][‘modified_golf_2’][‘value_template’]. Got None

That error ‘smells’ like badly structured yaml. If you validate the config first, you might get to see the line that is causing this.

thanks metbril, i will check it out tonight

both command_line and template validated no issues! wonder anyone can spot the error??

anyone out there have used command_line button to run two scripts? can you help me? yaml compiled and button show up; but don’t work when I click on button, but the script work.

  - platform: command_line
    switches:
      modified_golf:
        friendly_name: "Modified Golf"
        command_on: 
          service: script.turn_on
          entity_id: script.play_golf_on_2         
        command_off: 
          service: script.turn_off        
          entity_id: script.play_golf_off_2

You need a value_template that tells the switch what state it is in.

You could set up a separate input boolean and have your scripts additionally turn that on and off then refer to that boolean with your value template.

Can’t you just define an input_boolean switch and run an automation from that to run either script as they are just service calls?

something like this…

 - alias: "Turn On/Off Play Golf_switch"
   initial_state: 'on'
   trigger:
     - platform: state
       switch: input_boolean.playgolf_switch
   action:
     - service_template: >
         {% if is_state ('trigger.to_state' , 'on')%}
           script.turn_on
           entity_id: script.play_golf_on_2
         {% else %} 
           script.turn_off
           entity_id: script.play_golf_off_2
         {% endif %} 

I’m not sure if this will work or not but might give you some ideas :slight_smile:

I will try both yours and andrew option tonight, thank you all, have been busy on building site yesterday.

Hi all, I have got it working using a input-boolean switch to run two automation as shown below.

This HA switch I am using is for my TV where previously; if it is on and I use alexa to turn on tv again accidentally, it will turn it off. So I added a Sonoff power switch for my TV and the code shown below.
I now have a problem that if I turn tv on with HA and turn off with remote, boolean switch stays in ON mode. wondering if anyone can give me some suggestion

- alias: Living TV On
  trigger:
  - entity_id: input_boolean.living_tv_power_bool
    from: 'off'
    platform: state
    to: 'on'
  condition: 
  - condition: state
    entity_id: switch.living_tv_power
    state: 'off' 
  action:
  - service: switch.turn_on
    entity_id: switch.living_tv_power
  - delay: '00:00:03'
  - service: switch.turn_on
    entity_id: switch.tv_living
- alias: Living TV Off
  trigger:
  - entity_id: input_boolean.living_tv_power_bool
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - condition: state
    entity_id: switch.living_tv_power
    state: 'on'
  action:
  - service: switch.turn_off
    entity_id: switch.tv_living
  - delay: '00:00:03'    
  - service: switch.turn_off
    entity_id: switch.living_tv_powerinput_boolean: 

  living_tv_power_bool:
    name: TV Living
    initial: off

Hi all, I got it all working after reading some more exapmle and your suggestions.
thanks for all your help.
with living tv, it is old tv and have not internet connection.
I have many sonoffs, flashed with Tasmota.
Therefore I use the living TV usb port plus FT232RL 3.3V FTDI USB to TTL Serial Adapter to power up the sonoff.
I than use binary_sensor to ping the sonoff to check the status.
I don’t even have to have to worry about the power supply for the tv now, just normal power supply.
Then the input_boolean switch to activate the two automations.
code as below, i hope this might help others who has same issue.
Thank you all; until the next time! See you all again soon.

binary_sensor:
  - platform: ping
    host: 10.0.0.129
    scan_interval: 20
    name: living_tv_status  
######################	
- alias: Living TV On
  trigger:
  - entity_id: input_boolean.living_tv_power_bool
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: binary_sensor.living_tv_status
    state: 'off' 
  action:
  - delay: '00:00:02'
  - service: switch.turn_on
    entity_id: switch.tv_living  
	
###########################
- alias: Living TV Off
  trigger:
  - entity_id: input_boolean.living_tv_power_bool
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - condition: state
    entity_id: binary_sensor.living_tv_status
    state: 'on'
  action:
  - delay: '00:00:03'
  - service: switch.turn_off
    entity_id: switch.tv_living