Hello,
I’ve got my Tesla powerwall 2 recently installed and tried to integrate it into openhab. I’d like to share my solution to integrated the PW2 into openhab by using the api documented here https://github.com/vloschiavo/powerwall2
It seems there is an issues regardings the ssl certifcates on the Powerwall, so i used the exec binding to issue CURL commands to the powerwall gateway with the -k option
-k, --insecure Allow connections to SSL sites without certs (H)
The openhab config looks as follow
.thing
Thing exec:command:pw_aggregates [command="curl https://192.168.X.XXX/api/meters/aggregates -k", interval=1, timeout=5]
Thing exec:command:pw_soe [command="curl https://192.168.X.XXX/api/system_status/soe -k", interval=15, timeout=5]
.items
String PWAggregates_JSON "[%s]" {channel="exec:command:pw_aggregates:output"} // liest JSON String, wird in Rule in folgende Items geschrieben
Number:Power PW_InstPower_Site "InstPower Site [%.1f W]" (gPowerwall, gInfluxDefault)
Number:Power PW_InstPower_Battery "InstPower Battery [%.1f W]" (gPowerwall, gInfluxDefault)
Number:Power PW_InstPower_Load "InstPower Load [%.1f W]" (gPowerwall, gInfluxDefault)
Number:Power PW_InstPower_Solar "InstPower Solar [%.1f W]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyExported_Site "EnergyExported Site [%.1f Wh]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyImported_Site "EnergyImported Site [%.1f Wh]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyExported_Battery "EnergyExported Battery [%.1f Wh]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyImported_Battery "EnergyImported Battery [%.1f Wh]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyExported_Load "EnergyExported Load [%.1f Wh]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyImported_Load "EnergyImported Load [%.1f Wh]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyExported_Solar "EnergyExported Solar [%.1f Wh]" (gPowerwall, gInfluxDefault)
Number:Energy PW_EnergyImported_Solar "EnergyImported Solar [%.1f Wh]" (gPowerwall, gInfluxDefault)
String PWSoe_JSON "[%s]" {channel="exec:command:pw_soe:output"} // liest JSON String, wird in Rule in folgende Items geschrieben
Number PW_StateofCharge "State of Charge [%.1f]" (gPowerwall, gInfluxDefault)
.rules
// Powerwall JSON Conversion Aggregates
rule "Convert JSON to Item Type Number"
when
Item PWAggregates_JSON changed
then
// use the transformation service to retrieve the value
//val newValue = transform("JSONPATH", "$.site.instant_power", PWAggregates_JSON.state.toString)
PW_InstPower_Site.postUpdate( transform("JSONPATH", "$.site.instant_power", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_InstPower_Battery.postUpdate( transform("JSONPATH", "$.battery.instant_power", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_InstPower_Load.postUpdate( transform("JSONPATH", "$.load.instant_power", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_InstPower_Solar.postUpdate( transform("JSONPATH", "$.solar.instant_power", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyExported_Site.postUpdate( transform("JSONPATH", "$.site.energy_exported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyImported_Site.postUpdate( transform("JSONPATH", "$.site.energy_imported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyExported_Battery.postUpdate( transform("JSONPATH", "$.battery.energy_exported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyImported_Battery .postUpdate( transform("JSONPATH", "$.battery.energy_imported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyExported_Load.postUpdate( transform("JSONPATH", "$.load.energy_exported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyImported_Load.postUpdate( transform("JSONPATH", "$.load.energy_imported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyExported_Solar.postUpdate( transform("JSONPATH", "$.solar.energy_exported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
PW_EnergyImported_Solar.postUpdate( transform("JSONPATH", "$.solar.energy_imported", PWAggregates_JSON.state.toString) ) // post the new value to the Number Item
end
// Powerwall JSON Conversion Soe
rule "Convert JSON to Item Type Number"
when
Item PWSoe_JSON changed
then
// use the transformation service to retrieve the value
PW_StateofCharge.postUpdate( transform("JSONPATH", "$.percentage", PWSoe_JSON.state.toString) ) // post the new value to the Number Item
end
any suggestions for improvements or a more efficient solution by using the http binding are highly welcome