EV car power management

Got it up and running now :slight_smile:

My Autopi has been on repair for 1 month,but now back in my Hyundai Ioniq electric again :slight_smile:
I have the stay awake code and for telegram when charging from AndersO.
But now it has been a few updates with new futures that the stay awake code is not optimal anymore?

Have some one find out another solution for Ioniq after updates to stay awake the autopi when driving?

Regard Jörgen

@jorgeli
Hi, I noticed the same.
I disabled the script I was using and instead configured the power management. It works ok, not perfect but most of the time it is kept awake correctly.
Supress sleep event regex i set to:
^vehicle/(obd|battery|battery)/(interface_connected|charging|charging_slow)

I tried changing the go to sleep event, but it doesn’t work as it resets it everytime the event happens. Instead i set the Critical level Voltage to 12.5 (and safety cut out to 12.4) so it goes to sleep when the car is not running or charging as the voltage drops below 12.5 almost immediatly.

Thanks :slight_smile:
I have tried that now but Autopi stay awake all the time anyway when set the Critical level Voltage to 12.5 (and safety cut out to 12.4).

Or maybe i miss something else in the power managment?
Think i get back to the stay awake script and see for another solution .
Regard Jörgen

@jorgeli
It should cut out when it goes under those levels, maybe your battery is better than mine. I looked at the battery levels and it never goes below around 12.9 when driving or charging and when not it drops pritty quickly to around 12.3 on my car. I assume that it will differ between 12V batteries in different cars.

@Malte
Could that be a solution for EV power management. To have an optional setting that disregards the other power settings and only checks the 12V battery voltage;
“12V battery power wake/sleep limit”: default 12.8 if above autopi on if below autopi sleep.

Regards
Anders

After testing over weeks I am happy with my solution for the Hyundai Kona:
I created the new events “vehicle/pwr/on” and “vehicle/pwr/off” and put them into the settings.

Custom code “my_powerevent” (run by cronjob every 1 minute but not on startup!):

import logging
import shelve
import time

log = logging.getLogger(__name__)

#started by cronjob every minute
def powerevent():
    #load global variables
    sh = shelve.open("ManfredsPowerEvent.slv")
    #read bms-relay from OBD
    try:
        args = ['Relay_BMS']
        kwargs = {
        'mode': '220',
        'pid': '101',
        'header': '7E4',
        'bytes': 64,
        'baudrate': 500000,
        'formula': 'bytes_to_int(message.data[12:13])',
        'protocol': '6',
        'verify': False,
        'force': True,
        }
        sh["bms"]=(int(__salt__['obd.query'](*args, **kwargs)['value'])&1)/1
    except:
        sh["bms"]=-1
    tnow=time.time()
    tdiff=tnow-sh["pwr_lastcall"]
    #reset power-state to unknown when last call was more than 7000sec
    #better to have more "power off" events than an empty battery!
    if tdiff>7000:
        sh["power_state"]=-1
    #check power status
    if sh["bms"]==1 and sh["power_state"]!=1:
        sh["power_state"]=1
        sh["cnt_power"] = 0
        __salt__["event.fire"]({}, "vehicle/pwr/on")
    if sh["bms"]!=1 and sh["power_state"]!=0:
        sh["cnt_power"] += 1
        #give me 10 minutes before power off event
        if sh["cnt_power"] >= 10:
            sh["power_state"]=0
            __salt__["event.fire"]({}, "vehicle/pwr/off")
    #close global variables
    #ret = {"bms":sh["bms"],"cnt_power":sh["cnt_power"], "power_state":sh["power_state"], "last_call":tdiff}
    ret = {"power_state":sh["power_state"],"call_duration":(time.time()-tnow)}
    sh["pwr_lastcall"]=tnow
    sh.close()
    return (ret)

Custom code “my_autostart” (run by cronjob on startup and once every month)

import logging
import shelve

log = logging.getLogger(__name__)


# autostart is cronjob only on startup (and 1 time every month)
def autostart():
    dummy = init_powershelf()
    return 1


# initialize global variables
# otherwise error if you read it and they are not present
def init_powershelf():
    try:
        sh = shelve.open("ManfredsPowerEvent.slv")
        sh["bms"] = -1
        sh["cnt_power"] = 0
        sh["pwr_lastcall"] = 14000.2
        # power state -1 is "unknown" -> on every reboot power event on or off will be fired
        sh["power_state"] = -1
        sh.close
    except:
        pass
    return 1

I am using the following under “settings/advanced/power”:

Critical Level
    Duration = 180
    Voltage = 12.3
Safety Cut-out
    Duration = 150
    Voltage = 12.20
Event Driven
    Delay = 120
    Event Regex = ^vehicle/pwr/off
    Period = 600
Suppress
    Event Regex = ^vehicle/pwr/on
Wake Trigger
    Voltage Change = +0.40
    Voltage Change Duration = 2000ms
    Voltage Level > 13.30
2 Likes

Hi Manfred,

I’m testing out your custom code on my Kona Ev, but I’m struggling in getting the cronjobs work: could you post/send me your configuration parameters for those as well?

Thanks for your time, cheers.

Hi,

image

image

Manfred

1 Like

Thanks, I’ll give it a try tomorrow: I guess I should see the cronjob description inside the events log, correct?

Update01: thanks a lot Manfred, I tested it and it works like a charm while driving, I’m testing with a charge in a couple of hours.

Update02: It’s working great during charging as well!

Great sharing from your side!

1 Like

@Manfred,

Great stuff, thanks

A couple of questions have you configured the RPM PID and use the RPM/vehicle/motor/running option or do you use your own configuration for power management ?

I have found the RPM mechanism pretty stable (It seems to miss some vehicle/motor messages very occasionally) but works pretty well so I am going to stay with that for core power management however still would like to stay awake during charging.

I have found when charging the 12 v battery is normally kept at ~13.2 v. This means although the AutoPi sleeps it is woken by a power event ~ 2 minutes. This means I am still getting charging data (power_of_charge and bbm) for my 5 minute data extract although I would rather keep the AutoPI awake during care natively.

I will look at your my_powerevent.py job. Do you have any suggestions to only use it for charging status (not vehicle running ?)

Thanks

Hi Chris,

I don´t use the RPM mechanism. Instead I have created my own events:
vehicle/pwr/on + off
vehicle/drive/start + end
vehicle/charge/start + end
And I use these events in my dongle settings also.

see here:

1 Like

Manfred,

Thanks - do you find it pretty stable ? Does the vehicle reliably stay on during charging ?

yes and yes.
my_powerevent runs for 3 months now, no problems. I never change it, so it stays stable.
Sometimes the dongle goes to power off while driving, because my Hyundai stops talking -> better power off than staying on…

@Manfred absolutely agree Hyundai stops talking -> better power off than staying on…

When, this happens does it reset by itself or do you need to unplug plug . I have seen this once and looking for a solution to reboot the dongle

Thanks

After sleep of Autopi, it works again. No need to unplug.

great thanks. …

Thanks @Manfred for your github package :slight_smile:

But I have a problem, I think that none of my cron are running, (exact configuration of your picture) and I added a cron for telegram alert for charging Receive charging alerts on your phone ( and smart watch ) but no telegram message (but i correctly tested my token and ID with a text command from a web brother) !

Is there a special action to activate cron system on autopi ? Because none of the event you created appears in the event log :frowning:

Thanks

Hi,

There is nothing special on cron jobs.
does anything work on my.autopi.io (Dashboard, Loggers) ?
Try reboot the dongle.

The rpi temp is working but none of my jobs. I will try to physically disconect the autopi to check if it is better :zipper_mouth_face:

But it’s a pain because I fixed it on the insolator of the under dash. Then I have to remove it

IMG_20200209_135503|666x500

@Manfred, I see that your cron_autostart is : “on the first day of every months at 01h00” but does it mean that I have to wait march 1st 01h00 for my job to start ? :thinking: It could explain why it is not actually working ? :face_with_raised_eyebrow:

My rpi temperature is working but with " * * * * * " which means “every minutes all the time”.