EV car power management

#1

Hello every body :wave:
Maybe idea is to put there the power management of the autopi for EV car
Project is still close to success, but it is not clear for every body, and me !:grimacing: :thinking:

For me, this I understand is:

To start autopi:

1 - We need wake up -> if power is change ?

Seem ok but problem is BMS, this for saving 12v battery in good health wake up the autopi too because when 12v battery is less than x-volt, and at anytime. last time, my car was park and not connect to 220v, and I saw light on the Hyundai logo. autopi was at home and battery was not drained by anything. Just BMS start because 12v need.

2 - We need stay awake -> if something work ?

If new data, then stay awake, but only if car is really in mode ON or charging.
How to do this ?

If no data = go to sleep mode after x time, this is ok

3 - We need stay awake -> if charging ?

Plord custom code work well for this job “my_charge_status” send info to telegram and kill sleeping command of the dongle

4 - Sleep or go to hibernate

If no data, then go to sleep, how to do this ?
Go to hibernate too, if 12v battery is to low Voltage, this is ok
but how to wake up if hibernate ?

Last question: we have new section for it
But how it is working ?
It is the solution ? we don’t need anything other ?
36

#2

As far as hibernation is concerned, the device shouldn’t be woken up by anything else than 12 V going higher.
I have Hibernation set to 12,1V and this is how it looks like:


This is via AutoPi voltage reading, if I look at 12 V PID (from car) this is what I get (and my car is plugged to Type2 charger at the moment):

Currently my AutoPi is in sleep mode - it can be woken up by a call or SMS.

#3

Hi.
This is my config
It is working well
Wake up for 1 hour.
You can change for more. But I never use my car more than 1 hour.
Other config work well. When I put my car off, the voltage is low so, it is automatiquely go to hibernation. Or few minute later. It is not drain the batterie.
Then, when I put my car on, then the voltage change, and wifi go on quickely and after 3 minute the car is on, data come.
So I think it’s good way to use autopi before do by other way.

#4

hello
Nobody have a solution to lets the autopi awake when drive ?
still update for it not come …:pleading_face:
I search another solution, like telegram do it well for charging…:sweat_smile:

#5

You could try tweaking the charge status custom code … maybe -

...
def poll():

    # enable sleep in case anything goes wrong below
    #
    enable_sleep()

    # load previous status
    #
    persistance = load()

    # check if we are driving or charging
    #
    driving = get_driving()

    # disable sleep if driving or charging
    #
    if driving == 1 or driving == 0:
        disable_sleep()

    if driving == 1 or driving == -1:
...
#6

Ok. Thanks.
Like that:

def poll():

# enable sleep in case anything goes wrong below
#
enable_sleep()

# load previous status
#
persistance = load()

# check if we are driving or charging
#
driving = get_driving()
if driving == 1 or driving == 0:
    disable_sleep()
if driving == 1 or driving == -1:
    if persistance['charging'] == True:
        bot_sendtext("Charge arrete. Derniere charge connu "+format(persistance['SOC'],'.1f')+"%")
        persistance['charging'] = False
        save(persistance)
    return {"msg": "Not charging"}

# now we are charging
#

disable_sleep()
batt_power = get_charging_power()
soc = get_soc()

I try it tomorrow :wink: :sunny:

#7

Well, remove the last disable_sleep() … this is now handled above.

I’ve made this change on my autopi as well, but I don’t suppose I’ll get to test it until Saturday ( driving to fully charged live ! )

#8

Ok. Like this.
I will test on Friday. I will drive more than 40 minute, so i will see ;).

def poll():

# enable sleep in case anything goes wrong below
#
enable_sleep()

# load previous status
#
persistance = load()

# check if we are driving or charging
#
driving = get_driving()
if driving == 1 or driving == 0:
    disable_sleep()
if driving == 1 or driving == -1:
    if persistance['charging'] == True:
        bot_sendtext("Charge arrete. Derniere charge connu "+format(persistance['SOC'],'.1f')+"%")
        persistance['charging'] = False
        save(persistance)
    return {"msg": "Not charging"}

# now we are charging
#

# disable_sleep()
batt_power = get_charging_power()
soc = get_soc()

# alert if just started to charge
#
if persistance['charging'] == False:
    bot_sendtext("Voiture en charge a "+format(batt_power,'.2f')+"kW. Etat de la batterie "+format(soc,'.1f')+"%")

Etc…

#9

Hello.
I have configured the autopi power as defaults value.

I drive from 3 hours from now and autopi stay awake. So it seem working.

I also charge last day and he stay awake too.

I just configure he should sleep (hibernate) at 12,4 v (12,5v is too highly). Corresponding aproximatively at 80% battery level.

Si, wake up by 300
And shut down when 12,4v
And stay awake if charge and drive

@plord good job !!
Thanks.

(My custom code sometime died but not all. I should search why and all is perfect )

#10

Great !

I’ll be testing tomorrow as well, so all being well I’ll update github over the weekend.

1 Like
#11

This is work:

  • Wake up quickly also wifi
  • Data come quick when car is on
  • Autopi stay awake when charge or driving
  • Shut down when battery is 80% 12,4V (90% 12,5V is too hight)

The only problem is the dongle should go to hibernation more quickly when car is off. If you make short trip, it is ok. he go quick to hibernation. around 5 minute (the battery go from 90% to 80%). But if you make long trip, the dongle stay awake 30-40 minute more, because the battery go from 100% to 90% and then to 80% that is normal. But sometime (I see in the event) it is not exactly like that, because maybe the “power saver mode” from Kona work ?? and charge the 12V battery.
I don’t know, but it look like 100% to 90% and 100% again, then again 90% and 100%. again and again 5 or 6 times. then, 100% to 90% to 80% (12,4V) and go to hibernation.
maybe you can have a look at this, and we can exchange there about it later.

I already try to put 12,5V, but seem to hight. and sometime shut down when drive. (maybe because use air con or other accessoires)

So, my conclusion:
Autopi manage well to wake up the device
Your new script (telegram V1 modified by you) work well to stay awake when charge or stay awake when drive (tested yesterday 4 hours drive)
Autopi not work well to shut down autopi, but this we already know from long time (wait update)

This is my config power:



#12

I just updated the script on github after a test run today.

1 Like
#13

Very good work :slight_smile:
Where are you write that code?

#14

I have the following issue; the autopi does not go to sleep when enabling sleep.

There are two custom codes both run by jobs every 7 minutes based on the above posts.
One that sends charge status every 10% via Telegram.
Another that disables sleep when driving or charging and enables sleep when not.

Dongle settings are all default:
e.g. PERIOD (How long time should the device sleep due to inactivity?) = 300
Except one; DURATION (How long should the specified voltage change be observed before the device powers up on engine start?) = 300
So that I am sure that it starts up when I start the car.

It works fine for disabling sleep (stays awake when driving and charging).
But when the job enables sleep it doesnt go to sleep after the expected 5 minutes, instead it goes down when the lower setting for voltage is reached and shuts the dongle down (CRITICAL LIMIT = 12.3V).

I send the sleep enabled/disabled via telegram and it sends as expected (except that the enabled should stop being sent after aproximatly 5 minutes).

def poll():
    charging_ccs = get_charging_ccs()
    charging_normal = get_charging_normal()
    soc = get_soc()
    if charging_ccs == 1 or charging_normal == 1 or soc != -1:
        disable_sleep()
        #bot_sendtext("sleep disabled")
        return {"msg": "sleep disabled"}
    else:
        enable_sleep()
        bot_sendtext("sleep enabled")
        return {"msg": "sleep enabled"}

#enable autopi sleep
def enable_sleep():
    args = ['sleep']
    kwargs = {
        'enable': True,
    }
    __ salt__['power.sleep_timer'] (**kwargs)

 #disable autopi sleep
def disable_sleep():
    args = ['sleep']
    kwargs = {
        'enable': False,
    }
   __ salt__ [ 'power.sleep_timer'] (**kwargs) 

Anyone that knows why it is not goint to sleep?

#15

Found it.
When enabling the sleep mode by script it reverts to a setting for sleep that is very long.
I found the solution in plords post where he sets the time:

def enable_sleep():
    args = ['sleep']
    kwargs = {
        'enable': True,
        'period': 300,
        'reason': 'charge status',
    }
    __salt__['power.sleep_timer'](**kwargs)
#16

This works now for Hyundai Ioniq
Stays awake when driving and charging.

import os
import requests

BOT_TOKEN = '8888888888AAAAAAAAAA88888888'
BOT_CHATID = '888888888'

def poll():
    charging_ccs = get_charging_ccs()
    charging_normal = get_charging_normal()
    soc = get_soc()
    #if charging_ccs == 1 or (charging_normal != 1 and soc != -1):
    if charging_ccs == 1 or charging_normal == 1 or soc != -1:
        disable_sleep()
        #bot_sendtext("sleep disabled")
        return {"msg": "sleep disabled"}
    else:
        enable_sleep()
        bot_sendtext("sleep enabled")
        return {"msg": "sleep enabled"}

# enable autopi sleep
def enable_sleep():
    args = ['sleep']
    kwargs = {
        'enable': True,
        'period': 300,
        'reason': 'charge status',
    }
    __salt__['power.sleep_timer'](**kwargs)

# disable autopi sleep
def disable_sleep():
    args = ['sleep']
    kwargs = {
        'enable': False,
    }
    __salt__['power.sleep_timer'](**kwargs)

def get_charging():
    try:
        args = ['charging']
        kwargs = {
        'mode': '21',
        'pid': '01',
        'header': '7E4',
        'baudrate': 500000,
        'formula': 'bytes_to_int(message.data[11:12])',
        'protocol': '6',
        'verify': False,
        'force': True,
        }
        return (int(__salt__['obd.query'](*args, **kwargs)['value'])&128)/128
    except:
        return -1

# get display state of charge
#
def get_soc():
    try:
        args = ['soc']
        kwargs = {
            'mode': '21',
            'pid': '05',
            'header': '7E4',
            'baudrate': 500000,
            'formula': 'bytes_to_int(message.data[33:34])',
            'protocol': '6',
            'verify': False,
            'force': True,
            }
        return __salt__['obd.query'](*args, **kwargs)['value']/2.0
    except:
        return -1

# Weird response, always seem to be true
def get_charging_ccs():
    try:
        args = ['CCS Plug']
        kwargs = {
        'mode': '21',
        'pid': '01',
        'header': '7E4',
        'baudrate': 500000,
        'formula': 'bytes_to_int(message.data[11:12])',
        'protocol': '6',
        'verify': False,
        'force': True,
        }
        return (int(__salt__['obd.query'](*args, **kwargs)['value'])&64)/64
    except:
        return -1

# Weird response, always seem to be true
def get_charging_normal():
    try:
        args = ['J1772 Plug']
        kwargs = {
        'mode': '21',
        'pid': '01',
        'header': '7E4',
        'baudrate': 500000,
        'formula': 'bytes_to_int(message.data[11:12])',
        'protocol': '6',
        'verify': False,
        'force': True,
        }
        return (int(__salt__['obd.query'](*args, **kwargs)['value'])&32)/32
    except:
        return -1

def bot_sendtext(message):
    send_text = 'https://api.telegram.org/bot' + BOT_TOKEN + '/sendMessage?chat_id=' + BOT_CHATID + '&parse_mode=Markdown&text=' + message
    requests.get(send_text)
1 Like
#17

I have a Ioniq to , and this looks great :slight_smile:
But i am novice in this so i don´t now where i copy that code to work?
Can you explain please so will i be very grateful :pray::pray::pray:

#18

@jorgeli
Hi,

The code goes into custom code (just copy paste):


Like this:

Then you have to add a job that executes the code ([package/custom code name].[function], the function is poll):

The way my job is is set to every 6 minutes:

That together with setting the sleep times of the dongle to 5 minutes (300 seconds) works fine (I think the timings can be fine tuned a bit more). I am still working on that.
Times for sleep are set under settings:
41%20PM
Then go to Dongle-Adbvanced-Power. Mine looks at the moment like this:
.

To be noted the
BOT_TOKEN = ‘8888888888AAAAAAAAAA88888888’
BOT_CHATID = ‘888888888’
Are a telegram bot and a chat id to send info to my phone and not real, they need to be replaced with real values if used. Telegram (https://web.telegram.org).
Check out the following to create a bot: https://www.sohamkamani.com/blog/2016/09/21/making-a-telegram-bot/
The #bot_sendtext("… will send the text in the quotes if the # is removed, e.g. bot_sendtext(“sleep disabled”).
If left with the # then it will do nothing and you can skip the telegram part. I have used it for testing and then just turned it off.
However i use it when charging to get messages when passing 10% levels 40, 50…

Hope this helps :slight_smile:

#19

Thank you so much for your time to explain I am so grateful :smiley:
I will test today .
Thanks again :+1::+1::+1::grinning:

#20

Hmm It is not working for me so I think I have miss something?