Python Script (set state) not working

Good day

This trigger fires okay, but input_boolean.ss_battery_charging is not set. Any help would be appreciated.

Thank you

- trigger:
    platform: state
    entity_id: sensor.ss_battery_power
  action:
    - service: python_script.set_state
      data_template:
        state: >-
          {% set charging = (states.sensor.ss_battery_power.state | int ) %}
          {% if charging < 0 %}
            on
          {% else %}  
            off
          {% endif %}
      entity_id: input_boolean.ss_battery_charging

Why are you using the python script? This is what template sensors are for, no automation needed.

template:
- binary_sensor:
  - name: SS Battery Charging
    unique_id: ss_battery_charging
    state: "{{ states('sensor.ss_battery_power') | int < 0 }}"
    availability: "{{ states('sensor.ss_battery_power') | is_number }}"

if you’re dead set on an automation, you still don’t need the python_Script.

trigger:
    platform: state
    entity_id: sensor.ss_battery_power
action:
  - service: homeassistant.turn_{{ iif(states('sensor.ss_battery_power') | int < 0, 'on', 'off') }}
    entity_id: input_boolean.ss_battery_charging

IMO that python script is 100% unnecessary in almost every circumstance that it’s used.

Thank you
I will try that