Skip to content

Commit

Permalink
v1.4.0 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MickMake committed Mar 2, 2022
1 parent 0dac734 commit a15e5cd
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 81 deletions.
19 changes: 2 additions & 17 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ Note:

I'm currently using it in my [HomeAssistant](https://www.home-assistant.io/) instance.

![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/SunGrowOnHASSIO.png?raw=true)
![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/SunGrowOnHASSIO1.png?raw=true)

![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/SunGrowOnHASSIO2.png?raw=true)

![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/SunGrowOnHASSIO3.png?raw=true)

![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/SunGrowOnHASSIO4.png?raw=true)

![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/SunGrowOnHASSIO5.png?raw=true)


## What state is it in?
Expand Down
83 changes: 22 additions & 61 deletions cmd/cmd_mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"github.com/spf13/cobra"
"math/rand"
"strings"
"time"
)

Expand Down Expand Up @@ -111,62 +110,20 @@ func cmdMqttFunc(cmd *cobra.Command, args []string) error {

data := ep.GetData()
for i, r := range data.Entries {
point_id := strings.ReplaceAll(r.PointId, ".", "-")
id := "sungrow_" + point_id
fmt.Println(id)

err = foo.SensorPublishConfig(id, r.PointName, r.Unit, i)
// time.Sleep(time.Second)
err = foo.SensorPublishState(id, r.Value)
fmt.Printf("%s ", r.PointId)
err = foo.SensorPublishConfig(r.PointId, r.PointName, r.Unit, i)
if err != nil {
break
}
err = foo.SensorPublishState(r.PointId, r.Value)
if err != nil {
break
}
}
fmt.Println()
if err != nil {
break
}

// sensor1 := mmMqtt.Sensor {
// Device: mmMqtt.Device {
// Connections: [][]string{{"sungrow_address", "1"}},
// Identifiers: []string{"sungrow_battery_Level", "sungrow_address_1"},
// Manufacturer: "MickMake",
// Model: "SunGrow inverter",
// Name: "SunGrow battery level",
// SwVersion: "GoSunGrow https://github.com/MickMake/GoSungrow",
// ViaDevice: "GoSunGrow",
// },
// Name: "SunGrow battery level",
// StateTopic: "homeassistant/sensor/SunGrow/sungrow_battery_Level/state",
// UniqueID: "sungrow_battery_Level",
// UnitOfMeasurement: "%",
// }

// err = foo.SensorPublishConfig("sungrow_battery_Level", "SunGrow battery level", "%", "1")
// if err != nil {
// break
// }
// err = foo.SensorPublishState("sungrow_battery_Level", randoPercent())
// if err != nil {
// break
// }

// sensor2 := mmMqtt.Sensor {
// Device: mmMqtt.Device {
// Connections: [][]string{{"sungrow_address", "2"}},
// Identifiers: []string{"sungrow_pv_energy", "sungrow_address_2"},
// Manufacturer: "MickMake",
// Model: "SunGrow inverter",
// Name: "SunGrow PV Energy",
// SwVersion: "GoSunGrow https://github.com/MickMake/GoSungrow",
// ViaDevice: "GoSunGrow",
// },
// Name: "SunGrow PV Energy",
// StateTopic: "homeassistant/sensor/SunGrow/sungrow_pv_energy/state",
// UniqueID: "sungrow_pv_energy",
// UnitOfMeasurement: "kWh",
// }

// err = foo.SensorPublishConfig("sungrow_pv_energy", "SunGrow PV Energy", "kWh", "2")
// if err != nil {
// break
// }
// err = foo.SensorPublishState("sungrow_pv_energy", randoKWh())


updateCounter := 0
timer := time.NewTicker(10 * time.Second)
Expand All @@ -187,12 +144,16 @@ func cmdMqttFunc(cmd *cobra.Command, args []string) error {

data = ep.GetData()
for _, r := range data.Entries {
point_id := strings.ReplaceAll(r.PointId, ".", "-")
id := "sungrow_" + point_id
fmt.Println(id)
err = foo.SensorPublishState(id, r.Value)
fmt.Printf("%s ", r.PointId)
err = foo.SensorPublishState(r.PointId, r.Value)
if err != nil {
break
}
}

fmt.Println()
}
if err != nil {
break
}


Expand Down
Binary file removed docs/SunGrowOnHASSIO.png
Binary file not shown.
Binary file added docs/SunGrowOnHASSIO1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/SunGrowOnHASSIO2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/SunGrowOnHASSIO3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/SunGrowOnHASSIO4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/SunGrowOnHASSIO5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions mmMqtt/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
mqtt "github.com/eclipse/paho.mqtt.golang"
"net/url"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -199,6 +200,8 @@ func (m *Mqtt) SensorPublish(subtopic string, payload interface{}) error {
func (m *Mqtt) SensorPublishConfig(id string, name string, units string, address int) error {
for range Only.Once {
a := strconv.Itoa(address)
id = strings.ReplaceAll("sungrow_" + id, ".", "-")

class := ""
switch units {
case "MW":
Expand Down Expand Up @@ -263,9 +266,10 @@ func (m *Mqtt) SensorPublishConfig(id string, name string, units string, address
return m.err
}

func (m *Mqtt) SensorPublishState(sensor string, payload interface{}) error {
func (m *Mqtt) SensorPublishState(id string, payload interface{}) error {
for range Only.Once {
m.client.Publish(SensorBaseTopic + "/" + sensor + "/state", 0, true, payload)
id = strings.ReplaceAll("sungrow_" + id, ".", "-")
m.client.Publish(SensorBaseTopic + "/" + id + "/state", 0, true, payload)
}
return m.err
}
Expand Down

0 comments on commit a15e5cd

Please sign in to comment.