Add Import/Export value
Push Import/Export to the database and to mqtt.
This commit is contained in:
parent
48a7021940
commit
ff33024f80
17
README.md
17
README.md
|
@ -1,3 +1,20 @@
|
|||
# smartbridge
|
||||
|
||||
Software to readout and send data from a SBWF3102 smartbridge by net2grid, as sed by Pure Energie as Smart Home meter. The application pulls data from the webinterface and can push it to mqtt or InfluxDB.
|
||||
|
||||
## SBWF3102
|
||||
|
||||
The SBWF3102 by net2grid offers the following endpoints for data retrieval via http (port 80)
|
||||
|
||||
* `/meter/now` - Get current readings
|
||||
* `/meter/elec/power/hour`
|
||||
* `/meter/elec/power/day`
|
||||
* `/meter/elec/consumption/year`
|
||||
* `/meter/elec/consumption/month`
|
||||
* `/meter/elec/consumption/day`
|
||||
* `/meter/gas/consumption/year`
|
||||
* `/meter/gas/consumption/month`
|
||||
* `/meter/gas/consumption/day`
|
||||
|
||||
|
||||
Resources: See [MeterApiService.java](https://github.com/net2grid/net2grid_android/blob/master/app/src/main/java/nl/wittig/net2grid/api/MeterApiService.java)
|
||||
|
|
|
@ -71,17 +71,24 @@ func main() {
|
|||
if reading.Status != "ok" {
|
||||
fmt.Fprintf(os.Stderr, "status: %s\n", reading.Status)
|
||||
} else {
|
||||
data := fmt.Sprintf("{\"power\":%d,\"unit\":\"W\",\"min\":%d,\"max\":%d,\"timestamp\":%d}", reading.Electricity.Power.Current.Value, reading.Electricity.Power.Minimun.Value, reading.Electricity.Power.Maximum.Value, time.Now().Unix())
|
||||
data := fmt.Sprintf("{\"current\":%d,\"unit\":\"W\",\"min\":%d,\"max\":%d,\"import\":%d,\"export\":%d,\"importexportunit\":\"Wh\",\"timestamp\":%d}", reading.Electricity.Power.Current.Value, reading.Electricity.Power.Minimun.Value, reading.Electricity.Power.Maximum.Value, reading.Electricity.Import.Current.Value, reading.Electricity.Export.Current.Value, time.Now().Unix())
|
||||
if cf.Verbose {
|
||||
fmt.Print(cf.Mqtt.topic)
|
||||
fmt.Print(" ")
|
||||
fmt.Println(data)
|
||||
}
|
||||
mqtt_c.Publish("home/power", data)
|
||||
mqtt_c.Publish(cf.Mqtt.topic, data)
|
||||
|
||||
if cf.Influx.URL != "" {
|
||||
// Write current values
|
||||
tags := map[string]string{"unit": "W"}
|
||||
fields := map[string]interface{}{"value": reading.Electricity.Power.Current.Value, "min": reading.Electricity.Power.Minimun.Value, "max": reading.Electricity.Power.Maximum.Value}
|
||||
fields := map[string]interface{}{"value": reading.Electricity.Power.Current.Value}
|
||||
if err := influx.Write(cf.Influx.Organization, cf.Influx.Bucket, cf.Influx.Measurement, tags, fields); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "influxdb error: %s\n", err)
|
||||
}
|
||||
// Import and Export values
|
||||
tags = map[string]string{"unit": "Wh"}
|
||||
fields = map[string]interface{}{"import": reading.Electricity.Import.Current, "export": reading.Electricity.Export.Current}
|
||||
if err := influx.Write(cf.Influx.Organization, cf.Influx.Bucket, cf.Influx.Measurement, tags, fields); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "influxdb error: %s\n", err)
|
||||
}
|
||||
|
|
|
@ -48,5 +48,7 @@ func ReadSmartbridge(remote string) (Reading, error) {
|
|||
err = json.Unmarshal(buf, &reading)
|
||||
// Invert power so that negative = usage, positive = production
|
||||
reading.Electricity.Power.Current.Value = -reading.Electricity.Power.Current.Value
|
||||
reading.Electricity.Power.Minimun.Value = -reading.Electricity.Power.Minimun.Value
|
||||
reading.Electricity.Power.Maximum.Value = -reading.Electricity.Power.Maximum.Value
|
||||
return reading, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue