Automation to trigger above value but jumping values

Hi there.
I try to stop loading my bev at specific SoC. So far so good, but the car-implementation is buggy, so the values update only every now and then, so the SoC „jumps“. Let’s say one time it’s 68%, next state is 71%. I want to trigger at 70%, but HA doesn’t fire the trigger when doing like that.
Any hints? I think it’s because it doesn’t cross the value.

Sounds like you are using a state trigger rather than a numeric state trigger. You want something like this:

trigger:
  - platform: numeric_state
    entity_id: sensor.soc
    above: 70

This will trigger when the SoC changes from below 70 to above 70%.

That is what i am Using right now, that doesn’t work. I think i will need a Template-Sensor if i have googled it correctly…

if:
  - condition: numeric_state
    entity_id: sensor.mybevcar_soc
    below: 90
then:
  - service: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.wallbox

This should turn on when below 90, there is no problem. else was turning off the switch, but this got never fired…
Maybe i have something different wrong?

That’s a part of your action, not the trigger. Please post the entire code.

Its just a little more complex:

alias: Auto auf 90% laden nach connect
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.wallbox_state
    to: "2: Car connected"
    from: "1: Standby"
condition: []
action:
  - service: hassio.addon_restart
    metadata: {}
    data:
      addon: 877f2300_saic_python_mqtt_gateway
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: sensor.mybevcar_soc_kwh
        above: 32
    then:
      - service: switch.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: switch.wallbox_charging_rules_enabled
      - service: notify.mobile_app_phone
        data:
          message: Fertig geladen!
          title: Yay!
    else:
      - service: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: switch.wallbox_charging_rules_enabled
      - delay:
          hours: 0
          minutes: 2
          seconds: 0
          milliseconds: 0
      - service: automation.trigger
        metadata: {}
        data:
          skip_condition: false
        target:
          entity_id: automation.auto_auf_90_laden_nach_connect
mode: single

Right, so this is a test for capacity rather than percentage and switching on the “rules enabled” turns the charger off?. What isn’t working?

If this is an MG, the MQTT gateway works brilliantly and allows for dynamic adjustment of charge state:

image

Thats already a mod for testing with capacity-switching. Switching rules off starts charging, switching rules on turns to PV-Charge only.
In an older version i had switched turning on and of, so “if below 90% SOC turn off, else turn switch on” and it didn’t stop at 90% SoC. Now i try this version with turn off when not above capacity X. I am really prying to see if this works. Sorry for my bad description, i am not to good in english description, not a pro with HA, just testing around to get things to work :smiley:

So this:

  1. triggers when the wallbox goes to “2: Car connected”
  2. restarts the addon
  3. waits two minutes
  4. checks the state of the battery: if over 32kWh, stops charging, notifies you and quits.
  5. otherwise starts charging
  6. waits two minutes
  7. goes back to step 2.

…thus restarting the addon every four minutes whilst charging.

What is not working? Have you looked at the automation traces?

What state does the wallbox go to when you turn charging off? If it goes to “2: Car connected” then it’ll re-trigger the automation.

There must be something wrong with your setup, too. Here’s my car discharging in use and charging:

I occasionally find the gateway stops working, so I have a Docker script to restart it every five hours. That’s the MQTT gateway in a separate container from HA on my NAS.

Yeah, the gateway sometimes stop working, most times when i just connected the car. So the 2 min is just for the testing, it was 15 minutes and can go to 30 afterwards, don’t need to stop on point. just have to find a good time.
I can’t say yet what really doesn’t work. Just found out about the “traces” thing and have look into it, will see if actual code works. Thumbs are pressed ^^

1 Like