Overloads Control Automation

Hi,
I need an automation that turn off lights when house power consumption exceeds the allowed limit and turn it on when power consumption back to normal, I made an automation that turn off the lights but i have no idea how to made automation that turn the lights back on only if it,s turned off by the automation,
any idea?
thanks a lot.

alias: Lights Overloads Control
description: ‘’
trigger:

  • platform: numeric_state
    entity_id: sensor.tasmota_energy_current
    for:
    hours: 0
    minutes: 0
    seconds: 30
    above: ‘21’
    condition: []
    action:
  • service: light.turn_off
    data: {}
    target:
    entity_id:
    - light.interance_139617ce_on_off_4
    - light.interance_139617ce_on_off_3
    - int
    - light.front_lights_dc24b67e_on_off
    - light.front_lights_dc24b67e_on_off_4
    - light.front_lights_dc24b67e_on_off_2
    - light.lobby_88fbb9f7_on_off_2
    - light.lobby_88fbb9f7_on_off_3
  • service: notify.mobile_app_sm_a325f
    data:
    message: >-
    لا توجد طاقة كافية, تم إطفاء ألإنارة ألخارجية, سيتم إعادة تشغيلها عند
    توفر ألطاقة
    mode: restart

Have the automation turn on an input boolean when it runs and then use the state of that input boolean in the turn back on automation (only turn back on if input boolean is also on).

good idea, but it required three automations for each individual light, which makes the it too complicated