This opens new oportunities.
Let me explain.
The car allows to set a maximum battery charging level.
Problem is that it can only be set from inside the car.
This script allows to set the charging level in the car at 78% from within Domoticz and let Domoticz limit the max charging level.
Code: Select all
-- Volvo XC40 charging limiter
local MINIMUM_BATTERY_LEVEL = 20
local CHARGING_SPEED = 3.5 -- kWh
local BATTERY_CAPACITY = 80 -- Kw
return {
on = {
timer = {'every 12 minutes'},
},
data = {},
logging = {
level = domoticz.LOG_ERROR,
-- change LOG_DEBUG to LOG_ERROR to stop logging in the log
marker = 'XC40 charging limiter',
},
execute = function(domoticz, triggeredItem)
-- domoticz.log(domoticz.devices('XC40 battery %').dump(),domoticz.LOG_DEBUG)
-- domoticz.log(domoticz.devices('XC40-ChargeLevel').dump(),domoticz.LOG_DEBUG)
local current_time = os.date("%c")
local MINIMUM_BATTERY_LEVEL = domoticz.devices('XC40 battery %').levelVal
local chargeLevel = domoticz.devices('XC40-ChargeLevel').percentage
local range = domoticz.devices('XC40-fullRange').state
domoticz.log('Volvo calculated full range is : ' .. range, domoticz.LOG_DEBUG)
domoticz.log('Volvo current battery level is : ' .. chargeLevel, domoticz.LOG_DEBUG)
if chargeLevel >= MINIMUM_BATTERY_LEVEL then
domoticz.devices('Auto laden').switchOff()
local subject = 'The Volvo battery has been charged. '
local message =
' ' .. current_time .. '\n'..
'Volvo current battery level is : ' .. chargeLevel .. '\n'
domoticz.notify(subject, message, domoticz.PRIORITY_NORMAL)
end
if chargeLevel < MINIMUM_BATTERY_LEVEL then
domoticz.devices('Auto laden').switchOn()
local subject = 'The Volvo battery has started charging. '
local message =
' ' .. current_time .. '\n'..
'Volvo current battery level is : ' .. chargeLevel .. '\n'
domoticz.notify(subject, message, domoticz.PRIORITY_NORMAL)
end
end
}
- First addition will be a dimmer switch to set the charging level on the Domoticz Switch page.
If BMW, Dacia, Hyundai, Kia, Renault, Tesla,Toyota, Volvo drivers and others have code to share, please do.