Http Binding to get Renault Zoe status

Hi,
I migrated from OH 2.5 to OH 3 and now I have a problem with my http binding to integrate the Zoe in my OH environment. With 2.5 it worked, I created a website that gets the information from Renault based on a script: [GitHub - jamesremuscat/pyze: Unofficial Python client and API for Renault ZE] https://github.com/jamesremuscat/pyze

The website runs on an Apache Webserver (Docker). With the following, items it worked like a charm with OH 2.5:

Number ZOE_actual_km "Gesamtkilometer [%s km]" <km> { http="<[http://192.168.18.115:8005{Authorization=Basic}:240000:REGEX(.*.Kilometerstand:.........([0-9]+) km.*.)]" } //240000=240000 Millisekunden Abfrageintervall

String ZOE_plug_connected "Mit eCharger verbunden? [%s]" <goe> { http="<[http://192.168.18.115:8005{Authorization=Basic}:250000:REGEX(.*.Angeschlossen:.........([a-zA-Z]+).*.)]" }

String ZOE_charge_end "Ladungsende [%s h]" <finish> { http="<[http://192.168.18.115:8005{Authorization=Basic}:260000:REGEX(.*.Fertig:.........([0-9]+:[0-9]+).*.)]" }

String ZOE_charging "Wird geladen? [%s]" <charge> { http="<[http://192.168.18.115:8005{Authorization=Basic}:270000:REGEX(.*.Wird geladen:.........([a-zA-Z]+).*.)]" }

Number ZOE_current_battery "Akkustand [%s %%]" <battery> { http="<[http://192.168.18.115:8005{Authorization=Basic}:280000:REGEX(.*.Akkustand:.........([0-9]+).*.)]" }

Number ZOE_energy "Energie [%s kWh]" <energy> { http="<[http://192.168.18.115:8005{Authorization=Basic}:290000:REGEX(.*.Verf&uuml;gbare Energie:.........([0-9]+).*.)]" }

Number ZOE_distance "Reichweite [%s km]" <entfernung> { http="<[http://192.168.18.115:8005{Authorization=Basic}:300000:REGEX(.*.Reichweite:.........([0-9]+).*.)]" }

String ZOE_status_update "Status vom [%s]" <time> { http="<[http://192.168.18.115:8005{Authorization=Basic}:310000:REGEX(.*.Statusupdate:.........([0-9]+.[0-9]+.[0-9]+.[0-9]+ [0-9]+:[0-9]+).*.)]" }

Number ZOE_position_north "Position Nord [%s]" { http="<[http://192.168.18.115:8005{Authorization=Basic}:320000:REGEX(.*.Fahrzeugposition:.........<......=......:..www.google.com.maps.place.([0-9]+.[0-9]+),.*.)]" }

Number ZOE_position_east "Position Ost [%s]" { http="<[http://192.168.18.115:8005{Authorization=Basic}:330000:REGEX(.*.Fahrzeugposition:.........<......=......:..www.google.com.maps.place.[0-9]+.[0-9]+,([0-9]+.[0-9]+).*.)]" }

String ZOE_position_update "Position vom [%s]" <time> { http="<[http://192.168.18.115:8005{Authorization=Basic}:340000:REGEX(.*.Positionsupdate:.........([0-9]+.[0-9]+.[0-9]+.[0-9]+ [0-9]+:[0-9]+).*.)]" }

Switch ZOE_ac_start "Klimatisierung starten []" <klima>

Switch ZOE_Home "Standort [MAP(zoe.map):%s]" <location>

Location ZOE_coordinates "Koordinaten" <location>

Now I have to migrate this to the OH 3 http binding and I don’t know how!? The RegEx Transformation service is installed.
I created a thing but here is the first question. What HTTP method do I need? And how do I create the channels to match the previous items from OH 2.5? What is needed in State Transformation?

As far as I understand you created a webpage that contains a collection of values you would like to get into OH.

as you host your own page you should know it.
The default I would assume is the GET method.
Download the page content without parsing it. Create a debug log statement so that you in a first step can see if the page is downloaded. In a second step use RegEx stuff.

OK, I can access and download the page. I get the HTML code, now I need some help with Regex.
This is what I get for example:

<TR><TD>Kilometerstand:</TD><TD>4848 km</TD></TR>

So I need the value (4848 in this case). Can someone help me with Regex please?

OK, I got it! The syntax was the problem. Now it works with the following Regex syntax in state transformation:

REGEX:.*.Kilometerstand:.........([0-9]+) km.*.
2 Likes

Seems not to work for me if I change the REGEX this way as stated.
All values are empty in my sitemap.

Any other ideas what I propably missed to change from OH2.5 to OH3 using the same config files?
curl and php-curl installed for sure.

does the raw data look the same as in shown in the example in the other post ?

How can I find that out? I think yes, as it worked with OH2.5
It’s the latest version of db-EV/Zoe-PHP from github.

Here is a working example for that php script, you should be able to do the other channels based on this:

Base URL from http thing:

https://zoe.yxyxyxyxyx.net //adapt to your base url

State Transformation for “actual_km” from channel (if set to German language):

REGEX:.*.Kilometerstand:.........([0-9]+) km.*.

Item:

Number ZOE_actual_km "Kilometer [%s km]" { channel="http:url:zoe:actual_km" }

Sitemap:


Text item=ZOE_actual_km

zoe_km

Hi, thanks for your answer.

Now I’m getting confused.

In OH2.5 there was no thing file from you.

Here is what I currently have in OH3:

Number ZOE_actual_km "Kilometer [%s km]" <km>  { http="<[http://10.0.1.46/zoe/index.php:240000:REGEX(.*.Kilometerstand:.........([0-9]+) km.*.)]" } //240000=240000 Millisekunden Abfrageintervall
String ZOE_plug_connected "An Ladesäule? [%s]" <wallbox>  { http="<[http://10.0.1.46/zoe/index.php:250000:REGEX:.*.Angeschlossen:.........([a-zA-Z]+).*.]" }
String ZOE_charge_end "Ladungsende [%s h]" <finish> { http="<[http://10.0.1.46/zoe/index.php:260000:REGEX:.*.Fertig:.........([0-9]+:[0-9]+).*.]" }
String ZOE_charging "Wird geladen? [%s]" <strom>  { http="<[http://10.0.1.46/zoe/index.php:270000:REGEX:.*.Wird geladen:.........([a-zA-Z]+).*.]" }
Number ZOE_current_battery "Akkustand [%s %%]" <battery>  { http="<[http://10.0.1.46/zoe/index.php:280000:REGEX:.*.Akkustand:.........([0-9]+).*.]" }
Number ZOE_energy "Energie [%s kWh]" <energy>  { http="<[http://10.0.1.46/zoe/index.php:290000:REGEX:.*.Verf&uuml;gbare Energie:.........([0-9]+).*.]" }
Number ZOE_distance "Reichweite [%s km]" <entfernung>  { http="<[http://10.0.1.46/zoe/index.php:300000:REGEX:.*.Reichweite:.........([0-9]+).*.]" }
String ZOE_status_update "Status vom [%s]" <time>  { http="<[http://10.0.1.46/zoe/index.php:310000:REGEX:.*.Statusupdate:.........([0-9]+.[0-9]+.[0-9]+.[0-9]+ [0-9]+:[0-9]+).*.]" }
Number ZOE_position_north "Position Nord [%s]"  { http="<[http://10.0.1.46/zoe/index.php:320000:REGEX:.*.Fahrzeugposition:.........<......=......:..www.google.com.maps.place.([0-9]+.[0-9]+),.*.]" }
Number ZOE_position_east "Position Ost [%s]"  { http="<[http://10.0.1.46/zoe/index.php:330000:REGEX:.*.Fahrzeugposition:.........<......=......:..www.google.com.maps.place.[0-9]+.[0-9]+,([0-9]+.[0-9]+).*.]" }
String ZOE_position_update "Position vom [%s]" <time>  { http="<[http://10.0.1.46/zoe/index.php:340000:REGEX:.*.Positionsupdate:.........([0-9]+.[0-9]+.[0-9]+.[0-9]+ [0-9]+:[0-9]+).*.]" }
Switch ZOE_charge_start "Laden starten []"
Switch ZOE_ac_start "Klimatisierung starten []"
Switch ZOE_ac_start_calendar
Switch ZOE_Home "Standort [MAP(zoe.map):%s]" <location>
Switch Zoe_Alexa_Routine "ZOE Routine" { alexa="PowerController.powerState" }
Switch ZOE_charge100 "Batterie 100% laden[]"
Location ZOE_coordinates "Koordinaten" <location>

sitemap zoe label="Zoe" {
Text label="ZOE" icon="zoe" {
 Text item=ZOE_Home
 Switch item=ZOE_ac_start mappings=[ON="Start"]
 Text item=ZOE_actual_km
 Text item=ZOE_plug_connected
 Switch item=ZOE_charge_start mappings=[ON="Start"] visibility=[ZOE_plug_connected=="Ja"]
 Text item=ZOE_charging
 Text item=ZOE_charge_end visibility=[ZOE_plug_connected=="Ja"]
 Text item=ZOE_current_battery
 Text item=ZOE_energy
 Text item=ZOE_distance
 Text item=ZOE_status_update
 Text item=ZOE_position_update
 Mapview item=ZOE_coordinates height=10
}
}

and your rules file from OH2.5

That is a configuration syntax for openHAB 2.x.
In openHAB 3.x you need to use channel definitions, so the syntax is completly different:

ok, will try, thanks

should I create a separate file for these REGEX’s in the transform folder, or where should I put this?

In the HTTP binding is the following example.

Thing http:url:foo "Foo" [
	baseURL="https://example.com/api/v1/metadata-api/web/metadata",
	headers="key1=value1", "key2=value2", "key3=value3",
	refresh=15] {
		Channels:
			Type string : text "Text" [ stateTransformation="JSONPATH:$.metadata.data" ]
}

but how should I put it the right way?

Thing http:url:zoe:actual_km "ZOE_actual_km" [
	baseURL="http://10.0.1.46/zoe/index.php",
	headers="key1=value1", "key2=value2", "key3=value3",
	refresh=15] {
		Channels:
			Type string : text "Text" [ stateTransformation="REGEX:.*.Kilometerstand:.........([0-9]+) km.*." ]
}

In the channel definition:

Edit: I don’t use text files for Things, so cannot help in your case. My http Things are configured through MainUI.

Where have you entered the remaining ones from the former items file

Switch ZOE_charge_start "Laden starten []"
Switch ZOE_ac_start "Klimatisierung starten []"
Switch ZOE_ac_start_calendar
Switch ZOE_Home "Standort [MAP(zoe.map):%s]" <location>
Switch Zoe_Alexa_Routine "ZOE Routine" { alexa="PowerController.powerState" }
Switch ZOE_charge100 "Batterie 100% laden[]"
Location ZOE_coordinates "Koordinaten" <location>

in the http binding as channel as well or in the new items file like this one:

Number ZOE_actual_km "Kilometer [%s km]" <km>  { channel="http:url:zoe:actual_km" }
String ZOE_plug_connected "An Ladesäule? [%s]" <wallbox>  { channel="http:url:zoe:plug_connected" }
String ZOE_charge_end "Ladungsende [%s h]" <finish>     { channel="http:url:zoe:charge_end" }
String ZOE_charging "Wird geladen? [%s]" <strom>        { channel="http:url:zoe:charging" }
Number ZOE_current_battery "Akkustand [%s %%]" <battery>        { channel="http:url:zoe:current_battery" }
Number ZOE_energy "Energie [%s kWh]" <energy>   { channel="http:url:zoe:energy" }
Number ZOE_distance "Reichweite [%s km]" <entfernung>   { channel="http:url:zoe:distance" }
String ZOE_status_update "Status vom [%s]" <time>       { channel="http:url:zoe:status_update" }
Number ZOE_position_north "Position Nord [%s]"  { channel="http:url:zoe:position_north" }
Number ZOE_position_east "Position Ost [%s]"  { channel="http:url:zoe:position_east" }
String ZOE_position_update "Position vom [%s]" <time> { channel="http:url:zoe:position_update" }
Switch ZOE_charge_start "Laden starten []"
Switch ZOE_ac_start "Klimatisierung starten []"
Switch ZOE_ac_start_calendar
Switch ZOE_Home "Standort [MAP(zoe.map):%s]" <location>
Switch Zoe_Alexa_Routine "ZOE Routine" { alexa="PowerController.powerState" }
Switch ZOE_charge100 "Batterie 100% laden[]"
Location ZOE_coordinates "Koordinaten" <location>

as I’m getting the following errors in the log:

2021-09-16 09:39:50.866 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'zoe.items'
2021-09-16 09:39:51.111 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zoe-5' failed: The name 'ZOE_current_battery' cannot be resolved to an item or type; line 54, column 7, length 19 in zoe
2021-09-16 09:39:51.266 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'switchoffwallboxzoe-1' failed: The name 'ZOE_charge100' cannot be resolved to an item or type; line 5, column 7, length 13 in switchoffwallboxzoe
2021-09-16 09:39:51.269 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zoe-3' failed: The name 'ZOE_position_north' cannot be resolved to an item or type; line 28, column 65, length 18 in zoe
2021-09-16 09:39:51.275 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zoe-3' failed: The name 'ZOE_position_north' cannot be resolved to an item or type; line 28, column 65, length 18 in zoe
2021-09-16 09:39:52.116 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'zoe.items'
2021-09-16 09:39:52.220 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zoe-5' failed: The name 'ZOE_current_battery' cannot be resolved to an item or type; line 54, column 7, length 19 in zoe
2021-09-16 09:40:00.199 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zoe-4' failed: The name 'ZOE_distance' cannot be resolved to an item or type; line 42, column 8, length 12 in zoe
2021-09-16 09:40:24.026 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'http://10.0.1.46/zoe/index.php' (method='GET', content='null') failed: Total timeout 3000 ms elapsed
2021-09-16 09:42:03.710 [INFO ] [nding.http.internal.HttpThingHandler] - Using the secure client for thing 'http:url:zoe'.

Items without channels stay the same as before.
Your errors indicate that your items cannot be found.
If you want to use my definitions, you need to name your thing in a proper way:

If you are sure your definitions are correct, restart openHAB. Sometimes this solves similar problems.

follwing error:

2021-09-16 13:07:41.622 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zoe-1' failed: An error occurred during the script execution: array element type mismatch in zoe

code for rule:

// Triggers:
// - When ZOE_ac_start received command ON

// context: zoe-1
var String URL = 'http://myhome/zoe/index.php?acnow'
val String curlcommand = "curl@@-d@@" + "@@POST@@" + URL +"@@-H@@Content-Type:application/json@@-H@@accept"
var String jsonacnow = executeCommandLine(curlcommand, 1000)

Is the Syntax still right for OH3?

//Authorization Header for Basic Authentication: https://www.base64encode.org/
var Boolean MessageB = false

rule "Klimatisierung starten"
when
        Item ZOE_ac_start received command ON
then
    var String URL = 'http://10.0.1.46/zoe/index.php?acnow'
    val String curlcommand = "curl@@-d@@" + "@@POST@@" + URL +"@@-H@@Content-Type:application/json@@-H@@accept"
    var String jsonacnow = executeCommandLine(curlcommand, 1000) //executes the curl-string
end

rule "Laden starten"
when
        Item ZOE_charge_start received command ON
then
    var String URL = 'http://10.0.1.46/zoe/index.php?chargenow'
    val String curlcommand = "curl@@-d@@" + "@@POST@@" + URL +"@@-H@@Content-Type:application/json@@-H@@accept"
    var String jsoncharge = executeCommandLine(curlcommand, 1000) //executes the curl-string
end

rule "Zoe Home"
when
    Item ZOE_position_north changed  or
    Item ZOE_position_east changed
then
    val PointType home_location  = new PointType(new DecimalType(47.215), new DecimalType(9.703)) //hier die Koordinaten deines Standortes eintragen
    val PointType Zoe_location  = new PointType(new DecimalType(ZOE_position_north.state.toString), new DecimalType(ZOE_position_east.state.toString))
    val int distance = Zoe_location.distanceFrom(home_location).intValue()
    ZOE_coordinates.postUpdate(Zoe_location) //Update für Mapview
    if ( distance < 50) { //Abstand in Metern vom Standort
        ZOE_Home.postUpdate(ON)
    } else {
        ZOE_Home.postUpdate(OFF)
    }
end

no.
E.g. syntax of executeCommandLine has changed see Actions | openHAB

Ok, thanks

Not sure if I get this done by myself.

executeCommandLine(Duration.ofSeconds(5), "curl","-d","POST","https://zoe.yxyxyxyxyx.net/?acnow","-H","Content-Type:application/json","-s","-H","authorization:Basic abababababaabababa")

Of course you need to adapt the url and the authorization code (base64)

As you can see, it is all easier now with openHAB3 :slight_smile: