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:
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.
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
}
}
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:
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)
//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