Disable EV charger to avoid overloading

I need to power off the evse if my house load is above 4.000W and after power on when it’s lower 800W. I’m trying this automation but it never re power on when house load is less than 800W.

alias: EVSE overload
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.power
    above: '4000'
  - platform: numeric_state
    entity_id: sensor.power
    below: '800'
condition:
  - condition: device
    type: is_on
    device_id: 88113544c585564e180645e49495c77c
    entity_id: switch.evse
    domain: switch
action:
  - type: turn_off
    device_id: 88113544c585564e180645e49495c77c
    entity_id: switch.evse
    domain: switch
mode: single

Anybody could help me to add a function?

You have no action to turn the switch on. You only have an action to turn it off. Try this:

alias: EVSE overload
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.power
    above: '4000'
    id: 'off'
  - platform: numeric_state
    entity_id: sensor.power
    below: '800'
    id: 'on'
action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.evse
mode: single
1 Like

Ok, your script work well but I need also to give priority to the manual toggle. What I mean is that the automation has to work only if the toggle was pravilusly on. Now if the toggle is off and power is below 800W it start to charge.

What is the entity id if your “toggle”?
You could do something like this:

alias: EVSE overload
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.power
    above: '4000'
    id: 'off'
  - platform: numeric_state
    entity_id: sensor.power
    below: '800'
    id: 'on'
condition:
  condition: state
  entity_id: input_boolean.enable_evse # you have to create this helper, see below
  state: 'on'
action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.evse
mode: single
input_boolean:
  enable_evse:
    name: Enable EVSE Charging
    icon: mdi:car

It’s switch.evse

No, you cant use that. See my edited ppost above.

The function of this boolean is enable the automation?

I don’t understand why I need the boolean input.

Because your statement is vague.

Previously on when?

In the last minute?
Hour?
Day?
Month?
Year?

I mean that the automation has to work only if “switch.evse” was previously on. This because sometime happens that I connect the ev charger when I come to home but I need to start to charge the car during night.

Yes and as I said that is a vague statement. Previously on when?

If it has ever been previously on then that is not a condition at all and the automation will always fire.

Do you mean previously on in the last hour, day or year?

Also, as the automation changes the state of the switch it can affect this.

So you may be better off with an “enable” input boolean. Unless you have a way to determine if the switch was switched on manually, or by the automation. I don’t.

I badly explained myself, the automation has to work only if “switch.evse” is on.

You can’t use that. The automation can turn the switch off, and if the switch is on there is no need to turn it on, only to turn it off.

Yes, I understand the problem. I tried the boolean input but now the automation doesn’t work.

Did you turn the input boolean on to enable the automation?

Are there any errors in you log relating to this?

Have you tried the automation trace to see what is going on?

Yes, it’s toggled on and I don’t see errors.

Then have a look at the automation trace.

My guess would be that OP is expecting the EV to start charging immediately after they turn the input_boolean on, but none of the triggers fires.
I’d also expect the input_boolean to only affect the turn on and not the turn off. Otherwise switch.evse might get stuck in the on state. Maybe OR the input_boolean condition with trigger id off.

Well that’s easy fixed.

alias: EVSE overload
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.power
    above: '4000'
    id: 'off'
  - platform: numeric_state
    entity_id: sensor.power
    below: '800'
    id: 'on'
  - platform: state
    entity_id: input_boolean.enable_evse
    to: 'on'
    id: 'on'
  - platform: state
    entity_id: input_boolean.enable_evse
    to: 'off'
    id: 'off'
condition:
  condition: state
  entity_id: input_boolean.enable_evse # you have to create this helper, see below
  state: 'on'
action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.evse
mode: single

At least I think you can have duplicate trigger ids…

Great, now I can power on the charger with the boolean input toggle but it isn’t able also to swich off the relay. The fourth trigger seem right but dosn’t work.