Python Plugin: Volvo EV

Python and python framework

Moderator: leecollings

akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

rensbr wrote: Tuesday 15 October 2024 10:20
rensbr wrote: Friday 20 September 2024 13:22 Since every (post) function we try returns an error 500, it looks liket that someting is clearly wrong on the Volvo side, so I can report that to them.
To quote myself, It looks like Volvo has changed something at their side, because locking/unlocking the car seems to work now.
Tx, glad it works!

Unfortunately that is not the only thing Volvo changed: They also now enforce 2factor authentication. Fortunately i already built the support for that some time ago, but it more work to get the plugin up and running.

So if you get "unauthenticated" messages in the plugin logging: See the paragraph "2 Factor Authentication" in the docs (https://github.com/akamming/Domoticz_Vo ... rge_Plugin) on how to fix (basically running the authenticate.py script in the plugin directory and restart the plugin) to fix
Last edited by akamming on Tuesday 15 October 2024 10:37, edited 1 time in total.
rensbr
Posts: 61
Joined: Friday 27 July 2018 19:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by rensbr »

akamming wrote: Tuesday 15 October 2024 10:35
rensbr wrote: Tuesday 15 October 2024 10:20
rensbr wrote: Friday 20 September 2024 13:22 Since every (post) function we try returns an error 500, it looks liket that someting is clearly wrong on the Volvo side, so I can report that to them.
To quote myself, It looks like Volvo has changed something at their side, because locking/unlocking the car seems to work now.
Tx, glad it works!

Unfortunately that is not the only thing Volvo changed: They also now enforce 2factor authentication.

So if you get "unauthenticated" messages in the plugin logging: See the paragraph "2 Factor Authentication" in the docs (https://github.com/akamming/Domoticz_Vo ... rge_Plugin) on how to fix (basically running the authenticate.py script in the plugin directory and restart the plugin) to fix
I haven't expericied any problems, so far. But good to know that your plugin also supports 2FA now, great work!
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

rensbr wrote: Tuesday 15 October 2024 10:36
I haven't expericied any problems, so far. But good to know that your plugin also supports 2FA now, great work!
Very likely that's because you are already on the latest version which support 2FA and already made the tokens persistent for a restart. But if domoticz is down for about 2 hours, you will need to re-authenticate and then you will now need to use the 2FA authorization script
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Python Plugin: Volvo EV

Post by HvdW »

Since 09-10-2024 the plugin didn't update anymore.
Several times I reset the car,.... nothing
I just read the posts about 2FA and did the sequence.

Still,.... nothing
The logs:

Code: Select all

2024-10-15 11:00:59.692 Status: PluginSystem: Failed dynamic library load, install the latest libpython3.x library that is available for your platform.
2024-10-15 11:00:59.719 Status: PluginSystem: 'Volvo' Registration ignored, Plugins are not enabled.
Last edited by HvdW on Tuesday 15 October 2024 11:21, edited 1 time in total.
Bugs bug me.
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

HvdW wrote: Tuesday 15 October 2024 11:06 Since 09-10-2024 the plugin didn't update anymore.
Several times I reset the car,.... nothing
I just read the posts about 2FA and did the sequence.

Still,.... nothing
The logs:

Code: Select all

2024-10-15 11:00:59.692 Status: PluginSystem: Failed dynamic library load, install the latest libpython3.x library that is available for your platform.
2024-10-15 11:00:59.719 Status: PluginSystem: 'Volvo' Registration ignored, Plugins are not enabled.
What is the next step?
Your error has nothing to do with 2FA.

it's in the line:

Code: Select all

2024-10-15 11:00:59.692 Status: PluginSystem: Failed dynamic library load, install the latest libpython3.x library that is available for your platform.
Domoticz doesn't load any plugins, due to the fact there is something wrong with the python library on your system...

i am not a system administrator, maybe someone else can give a clue on how to fix this... (or do a google search on this error message, it does give a lot of hits with people who have had this issue before)
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Python Plugin: Volvo EV

Post by HvdW »

Problem solved:
Found this page.
Did:

Code: Select all

sudo apt-get install python3.11-dev
Why it did function normally befor the 9th of october?
No idea.

Hope this helps other in troubleshooting.

PS
Afrterwards everything gets clear.
I changed SD card for a new one, so python3.11-dev wasn't installed.
Positive:
I copied the old Domoticz directory to the new SD card as domoticz.bak directory to be able to copy domoticz.db to the newly install.
When installing Domoticz with

Code: Select all

sudo bash -c "$(curl -sSfL https://install.domoticz.com)"
to my surprise the 'Domoticz automated installer' found and used the former setup so all I had to do was nothing . Everything was back in place like before.
Everything, except python3.11-dev
Maybe the developers can add that one as well in the future like if imported plugins then install python3.11-dev
Bugs bug me.
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Remaining charging time

Post by HvdW »

The Volvo plugin offers new opportunities.
First of all it can be used to set a desired charging level.
Create a sensor , a slider to set a level from 0 to 100%
Compare the desired level with domoticz.devices('XC40-ChargeLevel').state and control when the battery charging should be stopped.

On the other hand it is nice to be able to see after how many hours and minutes the desired charging level will be reached an write this information in a Text sensor.

Code: Select all

  -------- AUTO OPLADEN  ----------------
 
        if domoticz.devices('Volvo-aangesloten').state ~= 'Disconnected' then
            carConnected = 'Connected'
        else
            carConnected = 'not Connected' 
        end
        
        if laadvermogen > 1000 then -- if charging is in progress
            laadvermogen = domoticz.devices('Laadpaal').actualWatt/1000
        else
            laadvermogen = 3600/1000  -- calculate using the max current of 16A (in my case)
        end
        -- x/1000  is Watt to kW
        
        local batteryCapacity = 79 -- kW
       
        -- laadtijd berekenen tot dynamisch
        local remainingTime = (batteryCapacity/100)*((domoticz.devices('XC40 battery charge set').levelVal - domoticz.devices('XC40-ChargeLevel').state))/laadvermogen
               
        uren, honderdsten = math.modf(remainingTime)
        minuten = honderdsten*60
        minuten = math.floor(minuten+0.5)
        
        domoticz.devices('Volvo').setIcon(107)
        domoticz.devices('Volvo').updateText('Charge level set     ' .. tostring(domoticz.devices('XC40 battery charge set').levelVal) ..'%'.. 
            '\n Charge level actual   ' .. tostring(domoticz.devices('XC40-ChargeLevel').nValue) ..'% '..
            '\n Plug connected    ' .. carConnected ..
            -- '\n Plug connected    ' .. chargingState ..
            '\n \n \n      Charging level     ' .. domoticz.devices('Charging Level').state ..
            '\n &emsp;&emsp;&emsp;&emsp; Charging state &nbsp;&emsp;&emsp;&emsp;' .. domoticz.devices('Volvo-Opladen').state ..'</font> '..
            '\n \n &emsp; Charging to '..tostring(domoticz.devices('XC40 battery charge set').levelVal)..'% : '.. tostring(uren) .. ' hours, ' .. tostring(minuten) .. ' minutes'..
            '\n &nbsp;')
Bugs bug me.
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Remaining charging time

Post by akamming »

HvdW wrote: Sunday 03 November 2024 1:18 The Volvo plugin offers new opportunities.
First of all it can be used to set a desired charging level.
Create a sensor , a slider to set a level from 0 to 100%
Compare the desired level with domoticz.devices('XC40-ChargeLevel').state and control when the battery charging should be stopped.

On the other hand it is nice to be able to see after how many hours and minutes the desired charging level will be reached an write this information in a Text sensor.

Code: Select all

  -------- AUTO OPLADEN  ----------------
 
        if domoticz.devices('Volvo-aangesloten').state ~= 'Disconnected' then
            carConnected = 'Connected'
        else
            carConnected = 'not Connected' 
        end
        
        if laadvermogen > 1000 then -- if charging is in progress
            laadvermogen = domoticz.devices('Laadpaal').actualWatt/1000
        else
            laadvermogen = 3600/1000  -- calculate using the max current of 16A (in my case)
        end
        -- x/1000  is Watt to kW
        
        local batteryCapacity = 79 -- kW
       
        -- laadtijd berekenen tot dynamisch
        local remainingTime = (batteryCapacity/100)*((domoticz.devices('XC40 battery charge set').levelVal - domoticz.devices('XC40-ChargeLevel').state))/laadvermogen
               
        uren, honderdsten = math.modf(remainingTime)
        minuten = honderdsten*60
        minuten = math.floor(minuten+0.5)
        
        domoticz.devices('Volvo').setIcon(107)
        domoticz.devices('Volvo').updateText('Charge level set &nbsp;&ensp;&emsp;&emsp;' .. tostring(domoticz.devices('XC40 battery charge set').levelVal) ..'%'.. 
            '\n Charge level actual &nbsp;&emsp;' .. tostring(domoticz.devices('XC40-ChargeLevel').nValue) ..'% '..
            '\n Plug connected &emsp;&emsp;&emsp;' .. carConnected ..
            -- '\n Plug connected &emsp;&emsp;&emsp;' .. chargingState ..
            '\n \n \n &emsp;&emsp;&emsp;&emsp; Charging level &ensp;&emsp;&emsp;&emsp;' .. domoticz.devices('Charging Level').state ..
            '\n &emsp;&emsp;&emsp;&emsp; Charging state &nbsp;&emsp;&emsp;&emsp;' .. domoticz.devices('Volvo-Opladen').state ..'</font> '..
            '\n \n &emsp; Charging to '..tostring(domoticz.devices('XC40 battery charge set').levelVal)..'% : '.. tostring(uren) .. ' hours, ' .. tostring(minuten) .. ' minutes'..
            '\n &nbsp;')
The volvo plugin (unfortunately) does not offer support to set the target charging level (i it is wish for me to implement it, but unfortunately the functionality is not available in the Volvo API). I assume you are referring to a custom script someone made which controls the wallbox based on the SoC level which is reported by the plugin..
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Python Plugin: Volvo EV

Post by HvdW »

Your assumption is correct.
I'm using the data received from the Volvo plugin about current charging level.
A slider switch in Domoticz sets the desired battery level.
SmartEVSE cuts off the charging when the reported charging level from the Volvo plugin matches the preset level from the slider.

Beforehand I used a relay like this one to switch mains to the charging box.
I have changed the charging box to be smart using a SmartEVSE device and now the charging can be started and charging current changed using MQTT.
Bugs bug me.
joostvanderlinde
Posts: 44
Joined: Tuesday 23 June 2015 23:06
Target OS: Linux
Domoticz version: 2023.2
Location: NL + SE
Contact:

Re: Python Plugin: Volvo EV

Post by joostvanderlinde »

akamming wrote: Tuesday 15 October 2024 10:35
rensbr wrote: Tuesday 15 October 2024 10:20
rensbr wrote: Friday 20 September 2024 13:22 Since every (post) function we try returns an error 500, it looks liket that someting is clearly wrong on the Volvo side, so I can report that to them.
To quote myself, It looks like Volvo has changed something at their side, because locking/unlocking the car seems to work now.
Tx, glad it works!

Unfortunately that is not the only thing Volvo changed: They also now enforce 2factor authentication. Fortunately i already built the support for that some time ago, but it more work to get the plugin up and running.

So if you get "unauthenticated" messages in the plugin logging: See the paragraph "2 Factor Authentication" in the docs (https://github.com/akamming/Domoticz_Vo ... rge_Plugin) on how to fix (basically running the authenticate.py script in the plugin directory and restart the plugin) to fix
When I first saw the mention of 2FA in this thread my plugin was till working so i did not pay much attention to it.... Today I noticed the data of my my C40 devices were outdated and I noticed a 'client not authorized' in the log.
Solution was indeed pretty simple: Update the plugin and run the authorize.py script. As per https://github.com/akamming/Domoticz_Vo ... rge_Plugin

Nice!!!
Domoticz on BPI-M2-Pro (compiled on Ubuntu 22.04) and RPI (binary on Raspian 10)
RFXCom, Sonoff Zigbee stick, eBusd Adapter 5, P1, S0, Husdata H60 integration
Zigbee2MQTT AD, MQTT local, AirconWithMe, Ebusd, VolvoRecharge, PSA Car Controller
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Python Plugin: Volvo EV

Post by HvdW »

I just wrote some new text for my Volvo text sensor.

Code: Select all

        if domoticz.devices('Volvo-aangesloten').state ~= 'Disconnected' then
            carConnected = 'Connected'
        else
            carConnected = 'not Connected' 
        end
           if laadvermogen > 1000 then 
            laadvermogen = domoticz.devices('Laadpaal').actualWatt/1000
        else
            laadvermogen = 3600/1000  -- Watt to kWh
        end
        
        -- calculate range
        local batteryCapacity = 79 -- kW
        local certainRange = 25    -- kWh/100km
        local currentRange = math.floor((domoticz.devices('XC40-ChargeLevel').state * batteryCapacity)/certainRange)
        local expectedRange = math.floor((domoticz.devices('XC40 battery charge set').levelVal * batteryCapacity)/certainRange)
        
        
        -- laadtijd berekenen tot dynamisch
        local resttijd = (batteryCapacity/100)*((domoticz.devices('XC40 battery charge set').levelVal - domoticz.devices('XC40-ChargeLevel').state))/laadvermogen
        domoticz.log('Battery set - Battery state '..domoticz.devices('XC40 battery charge set').levelVal..' - '.. domoticz.devices('XC40-ChargeLevel').state.. 'Laadvermogen : '..laadvermogen,domoticz.LOG_DEBUG)
        -- resttijd = round(resttijd,2)
        uren, honderdsten = math.modf(resttijd)
        minuten = honderdsten*60
        minuten = math.floor(minuten+0.5)
        -- certain range based on 25 kWh/100km
        
        domoticz.devices('Volvo').setIcon(107)
        domoticz.devices('Volvo').updateText('Charge level set &nbsp;&ensp;&emsp;&emsp;' .. tostring(domoticz.devices('XC40 battery charge set').levelVal) ..'%'.. 
            '\n Charge level actual &nbsp;&emsp;' .. tostring(domoticz.devices('XC40-ChargeLevel').nValue) ..'% '..
            '\n Plug connected &emsp;&emsp;&emsp;' .. carConnected ..
            -- '\n Plug connected &emsp;&emsp;&emsp;' .. chargingState ..
            '\n \n \n &emsp;&emsp;&emsp;&emsp; Expected range &ensp;&emsp;&emsp;' .. expectedRange ..' km '..
            '\n &emsp;&emsp;&emsp;&emsp; Current range &nbsp;&emsp;&emsp;&emsp;' .. currentRange ..' km'..
            '\n \n &emsp; Charging to '..tostring(domoticz.devices('XC40 battery charge set').levelVal)..'% : '.. tostring(uren) .. ' hours, ' .. tostring(minuten) .. ' minutes'..
            '\n &nbsp;')
     
Up till now it displayed Charging state and Set charging state.
volvo.jpg
volvo.jpg (16.82 KiB) Viewed 697 times
It now displays Expected Range and Actual Range as well.
Range is calculated using an electricity consumption of 25 kWh/100 km which is based on the Spritmonitor consumption.
In summer our Volvo uses 23 kWh/100 km, in winter 25 kWh/100 km
Bugs bug me.
rensbr
Posts: 61
Joined: Friday 27 July 2018 19:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by rensbr »

Updated the plugin today and runt the script, works like a charm with my EX30 now, thanks! @akamming
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Python Plugin: Volvo EV

Post by HvdW »

On tweakers I saw this:

Code: Select all

 "data": [
        {
            "command": "LOCK_REDUCED_GUARD",
            "href": "/v2/vehicles/vin/commands/lock-reduced-guard"
        },
        {
            "command": "LOCK",
            "href": "/v2/vehicles/vin/commands/lock"
        },
        {
            "command": "UNLOCK",
            "href": "/v2/vehicles/vin/commands/unlock"
        },
        {
            "command": "HONK",
            "href": "/v2/vehicles/vin/commands/honk"
        },
        {
            "command": "HONK_AND_FLASH",
            "href": "/v2/vehicles/vin/commands/honk-flash"
        },
        {
            "command": "FLASH",
            "href": "/v2/vehicles/vin/commands/flash"
        },
        {
            "command": "CLIMATIZATION_START",
            "href": "/v2/vehicles/vin/commands/climatization-start"
        },
        {
            "command": "CLIMATIZATION_STOP",
            "href": "/v2/vehicles/vin/commands/climatization-stop"
        }
    ]
}
Flash & Honk
Bugs bug me.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Python Plugin: Volvo EV

Post by FireWizard »

Hi @HvdW,

You can easily check, what commands are supported by your car, by querying the following endpoint:

https://api.volvocars.com/connected-veh ... >/commands

This will return an array of objects. Each element in the array will list the specific command and its endpoint.

For flash and honk it is:

https://api.volvocars.com/connected-veh ... honk-flash

Regards
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Volvo EV

Post by akamming »

HvdW wrote: Friday 13 December 2024 21:02 On tweakers I saw this:

Code: Select all

 "data": [
        {
            "command": "LOCK_REDUCED_GUARD",
            "href": "/v2/vehicles/vin/commands/lock-reduced-guard"
        },
        {
            "command": "LOCK",
            "href": "/v2/vehicles/vin/commands/lock"
        },
        {
            "command": "UNLOCK",
            "href": "/v2/vehicles/vin/commands/unlock"
        },
        {
            "command": "HONK",
            "href": "/v2/vehicles/vin/commands/honk"
        },
        {
            "command": "HONK_AND_FLASH",
            "href": "/v2/vehicles/vin/commands/honk-flash"
        },
        {
            "command": "FLASH",
            "href": "/v2/vehicles/vin/commands/flash"
        },
        {
            "command": "CLIMATIZATION_START",
            "href": "/v2/vehicles/vin/commands/climatization-start"
        },
        {
            "command": "CLIMATIZATION_STOP",
            "href": "/v2/vehicles/vin/commands/climatization-stop"
        }
    ]
}
Flash & Honk
This was my own message on tweakers (and already implemented flash-honk). So if you update to latest version it should work. (although it does require OTA update 3.3.16 on several cars before it works)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest