Help with automation to trun on light with 2 conditions

I have an automation to turn on a light in red when the load is about 2700W and turn it off when it is below 2000W for 3 minutes. The code is as follows

alias: Warning light on if the load is high
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.srne_current_load_power
    above: 2700
    id: Load is high
  - platform: numeric_state
    entity_id:
      - sensor.srne_current_load_power
    for:
      hours: 0
      minutes: 3
      seconds: 0
    below: 2000
action:
  - if:
      - condition: trigger
        id:
          - Load is high
    then:
      - service: light.turn_on
        data:
          color_name: red
        target:
          entity_id: light.warning
    else:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.warning

I have another automation to turn the same light when the battery SOC of the battery is below 20% and turn it off when the SOC is above 20%

alias: Warning light if Battery is low
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.jk_bms_state_of_charge
    id: Battery is low
    below: 19
  - platform: numeric_state
    entity_id:
      - sensor.jk_bms_state_of_charge
    for:
      hours: 0
      minutes: 3
      seconds: 0
    above: 20
condition: []
action:
  - if:
      - condition: trigger
        id:
          - Battery is low
    then:
      - service: light.turn_on
        data:
          color_name: red
        target:
          entity_id: light.warning
    else:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.warning
mode: single

But when these 2 are enabled together, one automation will turn on/off the light even when the other one is supposed to do the other way.

How can I merge this 2 automation to turn on the light if the load is above 2700W and/or battery SOC is below 20%. Also turn off when the load is below 2000W and/or battery SOC is above 20%.

following is the summary what I want to have.

Load is above 2700W and SOC below 20% - light on
Load is above 2700W and SOC above 20% - light on
Load is below 2000W and SOC below 20% - light on
Load is below 2000W and SOC above 20% - light off

Can someone please help me with the cording to achieve this?

alias: Warning light if Battery is low or Load is high
description: ""
trigger:
  - platform: template
    value_template: |
      {{ states('sensor.srne_current_load_power')|float(0) > 2700 or
      states('sensor.jk_bms_state_of_charge')|float(0) < 19) }}
    id: 'on'
  - platform: template
    value_template: |
      {{ states('sensor.srne_current_load_power')|float(0) < 2000 and
      states('sensor.jk_bms_state_of_charge')|float(0) > 20) }}
    for: "00:03:00"
    id: 'off'
condition: []
action:
  - if:
      - condition: trigger
        id: 'on'
    then:
      - service: light.turn_on
        data:
          color_name: red
        target:
          entity_id: light.warning
    else:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.warning

If you prefer a non-template method, that is possible as well:

Long-form version
alias: Warning light if Battery is low or Load is high
description: ""
trigger:
  - platform: template
    entity_id: sensor.srne_current_load_power
    above: 2700
    id: 'on'
  - platform: numeric_state
    entity_id: sensor.srne_current_load_power
    below: 2000
    for:
      hours: 0
      minutes: 3
      seconds: 0
    id: 'off'
  - platform: numeric_state
    entity_id: sensor.jk_bms_state_of_charge
    below: 19
    id: 'on'
  - platform: numeric_state
    entity_id: sensor.jk_bms_state_of_charge
    for:
      hours: 0
      minutes: 3
      seconds: 0
    above: 20
    id: 'off'
condition:
  - or:
      - alias: Either 'on' case true
        condition: trigger
        id: 'on'
      - alias: Both 'off' cases true
        and:
          - condition: numeric_state
	    entity_id: sensor.jk_bms_state_of_charge
	    above: 20
	  - condition: numeric_state
	    entity_id: sensor.srne_current_load_power
	    below: 2000
action:
  - if:
      - condition: trigger
        id: 'on'
    then:
      - service: light.turn_on
        data:
          color_name: red
        target:
          entity_id: light.warning
    else:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.warning
1 Like

That can even be shortened to

without if then :wink:

1 Like

Thank you @Didgeridrew & @aceindy They both working perfectly.

Thanks again