Help automation

I’m trying to turn off my pi
My script did work, but now it stopped.
Can some one help me to make it work again?
I think some update bricked my script, i am lost in fixing it.
I validate all the switches, sensors and links they are all fine.

platform: template
switches:
  switch_ender3_pi:
    friendly_name: 'Ender3 Killer'
    value_template: "{{ is_state('binary_sensor.ping_ender3_pi', 'on') }}"
    turn_on:
      service: switch.energy_temp_relay_2
    turn_off:
      data_template:
        entity_id: >
          {% if is_state('binary_sensor.ping_ender3_pi', 'on') %}
            url: "http://xx.xx.xx.xx:2345?KillThisPi"
            delay: '00:00:30'
            entity_id: switch.energy_temp_relay_2
          {% else %}
            entity_id: switch.energy_temp_relay_2
          {% endif %}

That’s surprising because this Template Switch is invalid:

  • turn_on contains an invalid service and no entity_id.
  • turn_off contains an entity_id but no service.

See the documentation for an example of a properly configured Template Switch.

I’ve been trying different things.
Got turn on working, that was easy.
But i cannot get the turn_off to work

I got this now

platform: template
switches:
  switch_ender3_pi:
    friendly_name: 'Ender3 Killer'
    value_template: "{{ is_state('binary_sensor.ping_ender3_pi', 'on') }}"
    turn_on:
      service: switch.turn_on
      data:
        entity_id: switch.energy_temp_relay_2
    turn_off:
      service_template: >
          {% if is_state('binary_sensor.ping_ender3_pi', 'on') %}
            script.script_kill_ender3
          {% else %}
            script.script_pwr_ender_off
          {% endif %}

Scripts are

script_kill_ender3:
    sequence:
      # This is written using the Script Syntax
      - service: rest_command.ender3_pi_request
      - wait_template: "{{ is_state('binary_sensor.ping_ender3_pi', 'off') }}"
      - delay: '00:01:00'
      - service: switch.turn_off
        entity_id: switch.energy_temp_relay_3
script_pwr_ender_off:
    sequence:
          # This is written using the Script Syntax
         - service: switch.turn_off
           entity_id: switch.energy_temp_relay_3

I’m on it for days now and cannot get it to work.
Where am i going wrong?

The indenting is incorrect. Your scripts are not following the standard of using two spaces to indent a line. Look at the examples in the Script documentation and you’ll see everything is neatly indented by two spaces.

none still nothing, i’m really lost here
I think i have all indents correct now

platform: template
switches:
  switch_ender3_pi:
    friendly_name: 'Ender3 Killer'
    value_template: "{{ is_state('binary_sensor.ping_ender3_pi', 'on') }}"
    turn_on:
      service: switch.turn_on
      data:
        entity_id: switch.energy_temp_relay_2
    turn_off:
      service_template: >
        {% if is_state('binary_sensor.ping_ender3_pi', 'on') %}
          script.script_kill_ender3
        {% else %}
          script.script_pwr_ender_off
        {% endif %}
script_kill_ender3:
  sequence:
    # This is written using the Script Syntax
    - service: rest_command.ender3_pi_request
    - wait_template: "{{ is_state('binary_sensor.ping_ender3_pi', 'off') }}"
    - delay: '00:01:00'
    - service: switch.turn_off
      data:
        entity_id: switch.energy_temp_relay_3
script_pwr_ender_off:
  sequence:
    # This is written using the Script Syntax
    service: switch.turn_off
    data:
      entity_id: switch.energy_temp_relay_3

Do the two scripts work if you call them manually from the Services page?

in services i can run them all and they work.
now only the automation has to play along.
For the life of me i can not get this to work!

    turn_off:
      service: script.turn_on
      data_template:
        entity_id: >
          {% if is_state('binary_sensor.ping_ender3_pi', 'on') %}
            script.script_kill_ender3
          {% else %}
            script.script_pwr_ender_off
          {% endif %}

in this code

platform: template
switches:
  switch_ender3_pi:
    friendly_name: 'Ender3 Killer'
    value_template: "{{ is_state('binary_sensor.ping_ender3_pi', 'on') }}"
    turn_on:
      service: switch.turn_on
      data:
        entity_id: switch.energy_temp_relay_2
    turn_off:
      service: script.turn_on
      data_template:
        entity_id: >
          {% if is_state('binary_sensor.ping_ender3_pi', 'on') %}
            script.script_kill_ender3
          {% else %}
            script.script_pwr_ender_off
          {% endif %}