Code by Scott שאול בן ישוע
Verified Commit 0ca90e71 authored by Sha'ul ben Yeshua's avatar Sha'ul ben Yeshua 🎗
Browse files

added hubitat driver

parent 78358781
/**
* Tesla Powerwall II Status for Hubitat
*
* Copyright 2020 Scott Grayban
*
* Notes:
* Power is load from house
* Energy is Solar power
* Grid is power sent or taken from public power grid
* energy_imported is power you needed from the grid
* energy_exported is power you sent to the grid
*
* API calls casn be found at https://github.com/vloschiavo/powerwall2
* V 1.0 - Initial code
*
*/
metadata {
definition (name: "Tesla Powerwall II Status", namespace: "sgrayban", author: "Scott Grayban") {
capability "Battery"
capability "EnergyMeter"
capability "PowerMeter"
capability "Sensor"
capability "VoltageMeasurement"
attribute "energy_imported", "number"
attribute "energy_exported", "number"
attribute "powerwall", "number"
attribute "grid", "number"
attribute "load", "number"
attribute "solar", "number"
attribute "GridFreqSetting", "number"
attribute "GridPhaseSetting", "string"
attribute "GridVoltageSetting", "number"
attribute "Distributor", "string"
attribute "SiteName", "string"
attribute "Region", "string"
attribute "Timezone", "string"
attribute "ConnectedToTesla", "string"
attribute "SystemRunning", "string"
}
preferences {
input name: "notes", type: "text", title: "<b>Device Notes</b>:",
description: "<ul><li><b>Grid</b> is +/- load from public grid</li><li><b>Power</b> is load from house</li><li><b>Energy</b> is Solar power</li><li><b>Energy_imported</b> is total power you needed from the grid</li><li><b>Energy_exported</b> is total power you sent to the grid</li><li><b>Powerwall data refreshes every minute</b></li></ul>"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def uninstalled() {
log.debug "Uninstalled"
unschedule()
}
def updated() {
log.debug "Updated"
initialize()
}
def initialize() {
updateCharge()
runEvery1Minute(updateCharge)
}
// parse events into attributes
def parse(String description) {
}
def updateCharge() {
def name
def params = [
uri: 'https://192.168.0.19',
ignoreSSLIssues: true,
path: '/api/system_status/soe',
contentType: 'application/json'
]
try {
httpGet(params) {resp ->
sendEvent(name: "battery", value: Math.round(resp.data.percentage).toDouble().round(2))
}
} catch (e) {
log.error "error: $e"
}
/// Get the meter values
params = [
uri: 'https://192.168.0.19',
ignoreSSLIssues: true,
path: '/api/meters/aggregates',
contentType: 'application/json'
]
try {
httpGet(params) {resp ->
sendEvent(name: "solar", value: "${Math.round(resp.data.solar.instant_power/100)/10}")
sendEvent(name: "energy", value: "${Math.round(resp.data.solar.instant_power/100)/10}")
sendEvent(name: "load", value: "${Math.round(resp.data.load.instant_power/100)/10}")
sendEvent(name: "power", value: "${Math.round(resp.data.load.instant_power/100)/10}")
sendEvent(name: "grid", value: "${Math.round(resp.data.site.instant_power/100)/10}")
sendEvent(name: "powerwall", value: "${Math.round(resp.data.battery.instant_power/100)/10}")
sendEvent(name: "energy_exported", value: resp.data.site.energy_exported)
sendEvent(name: "energy_imported", value: resp.data.site.energy_imported)
sendEvent(name: "voltage", value: Math.round(resp.data.site.instant_average_voltage).toDouble().round(2)
)
}
} catch (e) {
log.error "error: $e"
}
/// Get the site info values
params = [
uri: 'https://192.168.0.19',
ignoreSSLIssues: true,
path: '/api/site_info',
contentType: 'application/json'
]
try {
httpGet(params) {resp ->
sendEvent(name: "SiteName", value: resp.data.site_name)
sendEvent(name: "Timezone", value: resp.data.timezone)
sendEvent(name: "Region", value: resp.data.region)
sendEvent(name: "GridVoltageSetting", value: resp.data.grid_voltage_setting)
sendEvent(name: "GridFreqSetting", value: resp.data.grid_freq_setting)
sendEvent(name: "GridPhaseSetting", value: resp.data.grid_phase_setting)
sendEvent(name: "Distributor", value: resp.data.distributor)
}
} catch (e) {
log.error "error: $e"
}
/// Get the sitemaster info values
params = [
uri: 'https://192.168.0.19',
ignoreSSLIssues: true,
path: '/api/sitemaster',
contentType: 'application/json'
]
try {
httpGet(params) {resp ->
sendEvent(name: "SystemRunning", value: resp.data.running)
sendEvent(name: "ConnectedToTesla", value: resp.data.connected_to_tesla)
}
} catch (e) {
log.error "error: $e"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment