mirror of
https://github.com/MickMake/GoSungrow.git
synced 2025-04-11 21:29:19 +02:00
v3.0.4-beta - Energy dashboard fixes.
This commit is contained in:
parent
fbbaf2f695
commit
5acee08eb0
26
.idea/workspace.xml
generated
26
.idea/workspace.xml
generated
@ -4,7 +4,15 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="76adadc9-ae71-42a6-82a1-66dbc8ecb14c" name="Changes" comment="" />
|
||||
<list default="true" id="76adadc9-ae71-42a6-82a1-66dbc8ecb14c" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/cmd/cmd_mqtt.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_mqtt.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsDetail/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsDetail/data.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/struct_point.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/struct_point.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/mmHa/sensors.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/sensors.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/mmHa/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/struct.go" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@ -564,16 +572,6 @@
|
||||
<line>139</line>
|
||||
<option name="timeStamp" value="8165" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_point.go</url>
|
||||
<line>52</line>
|
||||
<option name="timeStamp" value="8236" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_point.go</url>
|
||||
<line>47</line>
|
||||
<option name="timeStamp" value="8237" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
|
||||
<line>71</line>
|
||||
@ -720,9 +718,9 @@
|
||||
<option name="timeStamp" value="8769" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/mmHa/struct.go</url>
|
||||
<line>554</line>
|
||||
<option name="timeStamp" value="8793" />
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_point.go</url>
|
||||
<line>82</line>
|
||||
<option name="timeStamp" value="8828" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
<default-breakpoints>
|
||||
|
@ -46,6 +46,7 @@ type CmdMqtt struct {
|
||||
Client *mmHa.Mqtt
|
||||
endpoints MqttEndPoints
|
||||
points getDevicePointAttrs.PointsMap
|
||||
previous map[string]*api.DataEntries
|
||||
|
||||
optionLogLevel int
|
||||
optionSleepDelay time.Duration
|
||||
@ -67,6 +68,7 @@ func NewCmdMqtt() *CmdMqtt {
|
||||
optionLogLevel: LogLevelInfo,
|
||||
optionSleepDelay: time.Second * 40, // Takes up to 40 seconds for data to come in.
|
||||
optionFetchSchedule: time.Minute * 5,
|
||||
previous: make(map[string]*api.DataEntries, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,8 +86,8 @@ func (c *CmdMqtt) AttachCommand(cmd *cobra.Command) *cobra.Command {
|
||||
var cmdMqtt = &cobra.Command{
|
||||
Use: "mqtt",
|
||||
Aliases: []string{""},
|
||||
Short: fmt.Sprintf("Connect to a HASSIO broker."),
|
||||
Long: fmt.Sprintf("Connect to a HASSIO broker."),
|
||||
Short: "Connect to a HASSIO broker.",
|
||||
Long: "Connect to a HASSIO broker.",
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: nil,
|
||||
@ -99,8 +101,8 @@ func (c *CmdMqtt) AttachCommand(cmd *cobra.Command) *cobra.Command {
|
||||
var cmdMqttRun = &cobra.Command{
|
||||
Use: "run",
|
||||
Aliases: []string{""},
|
||||
Short: fmt.Sprintf("One-off sync to a HASSIO broker."),
|
||||
Long: fmt.Sprintf("One-off sync to a HASSIO broker."),
|
||||
Short: "One-off sync to a HASSIO broker.",
|
||||
Long: "One-off sync to a HASSIO broker.",
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
@ -124,8 +126,8 @@ func (c *CmdMqtt) AttachCommand(cmd *cobra.Command) *cobra.Command {
|
||||
var cmdMqttSync = &cobra.Command{
|
||||
Use: "sync",
|
||||
Aliases: []string{""},
|
||||
Short: fmt.Sprintf("Sync to a HASSIO MQTT broker."),
|
||||
Long: fmt.Sprintf("Sync to a HASSIO MQTT broker."),
|
||||
Short: "Sync to a HASSIO MQTT broker.",
|
||||
Long: "Sync to a HASSIO MQTT broker.",
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
@ -150,13 +152,13 @@ func (c *CmdMqtt) AttachCommand(cmd *cobra.Command) *cobra.Command {
|
||||
|
||||
func (c *CmdMqtt) AttachFlags(cmd *cobra.Command, viper *viper.Viper) {
|
||||
for range Only.Once {
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttUsername, flagMqttUsername, "", "", fmt.Sprintf("HASSIO: mqtt username."))
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttUsername, flagMqttUsername, "", "", "HASSIO: mqtt username.")
|
||||
viper.SetDefault(flagMqttUsername, "")
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttPassword, flagMqttPassword, "", "", fmt.Sprintf("HASSIO: mqtt password."))
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttPassword, flagMqttPassword, "", "", "HASSIO: mqtt password.")
|
||||
viper.SetDefault(flagMqttPassword, "")
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttHost, flagMqttHost, "", "", fmt.Sprintf("HASSIO: mqtt host."))
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttHost, flagMqttHost, "", "", "HASSIO: mqtt host.")
|
||||
viper.SetDefault(flagMqttHost, "")
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttPort, flagMqttPort, "", "", fmt.Sprintf("HASSIO: mqtt port."))
|
||||
cmd.PersistentFlags().StringVarP(&c.MqttPort, flagMqttPort, "", "", "HASSIO: mqtt port.")
|
||||
viper.SetDefault(flagMqttPort, "")
|
||||
}
|
||||
}
|
||||
@ -392,9 +394,22 @@ func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
|
||||
c.LogInfo("Syncing %d entries with HASSIO from %s.\n", len(data.Map), endpoint)
|
||||
|
||||
for o := range data.Map {
|
||||
refreshConfig := newDay
|
||||
|
||||
entries := data.Map[o]
|
||||
r := entries.GetEntry(api.LastEntry) // Gets the last entry
|
||||
|
||||
if strings.Contains(r.EndPoint, "pv_to_grid_energy") {
|
||||
fmt.Printf("EMPTY[%s] -> %s\n", r.EndPoint, r.Value.String())
|
||||
}
|
||||
if _, ok := c.previous[o]; ok {
|
||||
previous := c.previous[o].GetEntry(api.LastEntry)
|
||||
if r.Value.String() != previous.Value.String() {
|
||||
refreshConfig = true
|
||||
}
|
||||
}
|
||||
c.previous[o] = entries
|
||||
|
||||
if !r.Point.Valid {
|
||||
// Any point that shouldn't be passed through to MQTT is ignored
|
||||
// - includes child points of an aggregate of several points.
|
||||
@ -425,15 +440,15 @@ func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
|
||||
name = mmHa.JoinStringsForName(" - ", r.Parent.Key, r.Point.Id, r.Point.GroupName, r.Point.Description)
|
||||
}
|
||||
|
||||
if r.Point.Unit == "" {
|
||||
r.Point.Unit = r.Point.ValueType
|
||||
}
|
||||
if r.Point.Unit == "Bool" {
|
||||
r.Point.Unit = mmHa.LabelBinarySensor
|
||||
}
|
||||
if r.Point.ValueType == "Bool" {
|
||||
r.Point.Unit = mmHa.LabelBinarySensor
|
||||
}
|
||||
// if r.Point.Unit == "" {
|
||||
// r.Point.Unit = r.Point.ValueType
|
||||
// }
|
||||
// if r.Point.Unit == "Bool" {
|
||||
// r.Point.Unit = mmHa.LabelBinarySensor
|
||||
// }
|
||||
// if r.Point.ValueType == "Bool" {
|
||||
// r.Point.Unit = mmHa.LabelBinarySensor
|
||||
// }
|
||||
|
||||
re := mmHa.EntityConfig {
|
||||
Name: name, // mmHa.JoinStringsForName(" - ", id), // r.Point.Name, // PointName,
|
||||
@ -454,28 +469,21 @@ func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
|
||||
Icon: r.Current.PointIcon(),
|
||||
UpdateFreq: r.Current.DataStructure.PointUpdateFreq,
|
||||
|
||||
LastReset: r.Point.WhenReset(),
|
||||
// LastReset: "",
|
||||
// LastResetValueTemplate: "",
|
||||
}
|
||||
|
||||
// if strings.Contains(r.EndPoint, "grid_to_load_energy") {
|
||||
// fmt.Printf("EMPTY[%s] -> %s\n", r.EndPoint, r.Value.String())
|
||||
// }
|
||||
// if r.Current.DataStructure.PointUpdateFreq != "" {
|
||||
// fmt.Printf("EMPTY[%s] -> %s\n", r.EndPoint, r.Value.String())
|
||||
// }
|
||||
re.FixConfig()
|
||||
|
||||
switch {
|
||||
case r.Point.IsTotal():
|
||||
re.StateClass = "total"
|
||||
default:
|
||||
re.StateClass = "measurement"
|
||||
if re.LastResetValueTemplate != "" {
|
||||
re.LastReset = r.Point.WhenReset(r.Date)
|
||||
}
|
||||
|
||||
// if strings.Contains(r.EndPoint, "pv_to_grid_energy") {
|
||||
// fmt.Printf("EMPTY[%s] -> %s\n", r.EndPoint, r.Value.String())
|
||||
// }
|
||||
// fmt.Printf("UNIT[%s] -> %s / %s / %s / %s /\n", id, r.Point.GroupName, r.Point.Unit, r.Point.ValueType, r.Point.Description)
|
||||
|
||||
if newDay {
|
||||
if refreshConfig {
|
||||
c.LogPlainInfo("C")
|
||||
c.LogDebug("Config: [%s]\n", r.EndPoint)
|
||||
c.Error = c.Client.BinarySensorPublishConfig(re)
|
||||
@ -584,6 +592,15 @@ func (c *CmdMqtt) UpdatePoint(entry *api.DataEntry) error {
|
||||
entry.Point.Unit = p.Unit.String()
|
||||
// fmt.Printf("[%s] -> %s\n", entry.EndPoint, entry.Value.String())
|
||||
}
|
||||
if entry.Point.Unit == "" {
|
||||
entry.Point.Unit = entry.Point.ValueType
|
||||
}
|
||||
if entry.Point.Unit == "Bool" {
|
||||
entry.Point.Unit = mmHa.LabelBinarySensor
|
||||
}
|
||||
if entry.Point.ValueType == "Bool" {
|
||||
entry.Point.Unit = mmHa.LabelBinarySensor
|
||||
}
|
||||
|
||||
// Parent
|
||||
if len(entry.Point.Parents.Map) == 0 {
|
||||
|
@ -237,25 +237,25 @@ type ResultData struct {
|
||||
UUID valueTypes.Integer `json:"uuid"`
|
||||
EnergyFlow []valueTypes.Integer `json:"energy_flow" PointName:"Energy Flow" PointIgnoreZero:"false" PointArrayFlatten:"true"`
|
||||
|
||||
P13003Map valueTypes.UnitValue `json:"p13003_map" PointId:"p13003" PointName:"PV Power To Load" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13003Map valueTypes.UnitValue `json:"p13003_map" PointId:"p13003" PointName:"PV Power To Load" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13003MapVirgin valueTypes.UnitValue `json:"p13003_map_virgin" PointIgnore:"true"`
|
||||
P13011Map valueTypes.UnitValue `json:"p13011_map" PointId:"p13011" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13011Map valueTypes.UnitValue `json:"p13011_map" PointId:"p13011" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13011MapVirgin valueTypes.UnitValue `json:"p13011_map_virgin" PointIgnore:"true"`
|
||||
P13115Map valueTypes.UnitValue `json:"p13115_map" PointId:"p13115" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13115Map valueTypes.UnitValue `json:"p13115_map" PointId:"p13115" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13115MapVirgin valueTypes.UnitValue `json:"p13115_map_virgin" PointIgnore:"true"`
|
||||
P13119Map valueTypes.UnitValue `json:"p13119_map" PointId:"p13119" PointName:"Load Power" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13119Map valueTypes.UnitValue `json:"p13119_map" PointId:"p13119" PointName:"Load Power" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13119MapVirgin valueTypes.UnitValue `json:"p13119_map_virgin" PointIgnore:"true"`
|
||||
P13121Map valueTypes.UnitValue `json:"p13121_map" PointId:"p13121" PointName:"PV Power To Grid" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13121Map valueTypes.UnitValue `json:"p13121_map" PointId:"p13121" PointName:"PV Power To Grid" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13121MapVirgin valueTypes.UnitValue `json:"p13121_map_virgin" PointIgnore:"true"`
|
||||
P13126Map valueTypes.UnitValue `json:"p13126_map" PointId:"p13126" PointName:"PV Power To Battery" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13126Map valueTypes.UnitValue `json:"p13126_map" PointId:"p13126" PointName:"PV Power To Battery" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13126MapVirgin valueTypes.UnitValue `json:"p13126_map_virgin" PointIgnore:"true"`
|
||||
P13141 valueTypes.Float `json:"p13141" PointName:"Battery Charge Percent" PointUnit:"%" PointIcon:"mdi:battery" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13142 valueTypes.Float `json:"p13142" PointName:"Battery Health" PointUnit:"%" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13149Map valueTypes.UnitValue `json:"p13149_map" PointId:"p13149" PointName:"Grid Power To Load" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13142 valueTypes.Float `json:"p13142" PointName:"Battery Health" PointUnit:"%" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13149Map valueTypes.UnitValue `json:"p13149_map" PointId:"p13149" PointName:"Grid Power To Load" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13149MapVirgin valueTypes.UnitValue `json:"p13149_map_virgin" PointIgnore:"true"`
|
||||
P13150Map valueTypes.UnitValue `json:"p13150_map" PointId:"p13150" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13150Map valueTypes.UnitValue `json:"p13150_map" PointId:"p13150" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13150MapVirgin valueTypes.UnitValue `json:"p13150_map_virgin" PointIgnore:"true"`
|
||||
P13155 valueTypes.Float `json:"p13155" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreqInstant" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
P13155 valueTypes.Float `json:"p13155" PointDeviceFrom:"PsKey" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true" PointVirtualShift:"3"`
|
||||
} `json:"storage_inverter_data" DataTable:"false"`
|
||||
}
|
||||
|
||||
|
@ -402,28 +402,34 @@ func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
_ = entries.MakeState(pvToLoadPowerActive)
|
||||
|
||||
pvDailyEnergy := entries.CopyPointFromName(epp.AddString("p13112"), epp, "pv_daily_energy", "Pv Daily Energy (p13112)")
|
||||
pvDailyEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
|
||||
pvToGridEnergy := entries.CopyPointFromName(epp.AddString("p13173"), epp, "pv_to_grid_energy", "Pv To Grid Energy (p13173)")
|
||||
pvToGridEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
|
||||
pvToGridEnergyPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_grid_energy_percent", "Pv To Grid Energy Percent (Calc)")
|
||||
pvToGridEnergyPercent.SetValue(entries.GetPercent(pvToGridEnergy, pvDailyEnergy, 1))
|
||||
pvToGridEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
pvToGridEnergyPercent.SetValue(entries.GetPercent(pvToGridEnergy, pvDailyEnergy, 1))
|
||||
pvToGridEnergyPercent.Value.SetUnit("%")
|
||||
|
||||
pvToBatteryEnergy := entries.CopyPointFromName(epp.AddString("p13174"), epp, "pv_to_battery_energy", "Pv To Battery Energy (p13174)")
|
||||
pvToBatteryEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
|
||||
totalDailyEnergy := entries.CopyPointFromName(epp.AddString("p13199"), epp, "total_daily_energy", "Total Daily Energy (p13199)")
|
||||
totalDailyEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
|
||||
// dailyPvEnergy(p13112) - pvToGridEnergy(p13173) - pvToBatteryEnergy(p13174)
|
||||
// WRONG!!! - p13112 (Pv Daily Energy) - p13122 (Daily Feed-in Energy) - p13174 (Daily Battery Charging Energy from PV)
|
||||
dailyFeedInEnergy := entries.GetReflect(epp.AddString("p13173"))
|
||||
batteryChargeEnergy := entries.GetReflect(epp.AddString("p13174"))
|
||||
selfConsumptionOfPv := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_consumption_energy", "Pv Consumption Energy (Calc)")
|
||||
selfConsumptionOfPv.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
tmp1 := pvDailyEnergy.GetValueFloat() - dailyFeedInEnergy.GetValueFloat() - batteryChargeEnergy.GetValueFloat()
|
||||
selfConsumptionOfPv.SetValue(tmp1)
|
||||
selfConsumptionOfPv.SetValuePrecision(3)
|
||||
|
||||
selfConsumptionOfPvPercent := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_consumption_energy_percent", "Pv Consumption Energy Percent (Calc)")
|
||||
selfConsumptionOfPvPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
selfConsumptionOfPvPercent.SetValue(entries.GetPercent(selfConsumptionOfPv, pvDailyEnergy, 1))
|
||||
selfConsumptionOfPvPercent.Value.SetUnit("%")
|
||||
|
||||
@ -431,16 +437,19 @@ func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
// WRONG!!! - pvToLoadEnergy := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_to_load_energy", "Pv To Load Energy (p13116)")
|
||||
gridToLoadEnergy := entries.GetReflect(epp.AddString("p13147"))
|
||||
pvToLoadEnergy := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_to_load_energy", "Pv To Load Energy (Calc)")
|
||||
pvToLoadEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
tmp2 := totalDailyEnergy.GetValueFloat() - gridToLoadEnergy.GetValueFloat()
|
||||
pvToLoadEnergy.SetValue(tmp2)
|
||||
pvToLoadEnergy.SetValuePrecision(3)
|
||||
|
||||
pvToLoadEnergyPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_load_energy_percent", "Pv To Load Energy Percent (Calc)")
|
||||
pvToLoadEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
pvToLoadEnergyPercent.SetValue(entries.GetPercent(pvToLoadEnergy, totalDailyEnergy, 1))
|
||||
pvToLoadEnergyPercent.Value.SetUnit("%")
|
||||
|
||||
gridToLoadDailyEnergy := entries.GetReflect(epp.AddString("p13147"))
|
||||
pvDailyEnergyPercent := entries.CopyPoint(totalDailyEnergy, epp, "pv_daily_energy_percent", "Pv Daily Energy Percent (Calc)")
|
||||
pvDailyEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
dpe := totalDailyEnergy.GetValueFloat() - gridToLoadDailyEnergy.GetValueFloat()
|
||||
pvDailyEnergyPercent.SetValue(api.GetPercent(dpe, totalDailyEnergy.GetValueFloat(), 1))
|
||||
pvDailyEnergyPercent.Value.SetUnit("%")
|
||||
@ -454,7 +463,8 @@ func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
// _ = entries.CopyPointFromName(epp.AddString("p13122"), epp, "pv_to_grid2", "")
|
||||
|
||||
// TotalPvYield
|
||||
_ = entries.CopyPointFromName(epp.AddString("p13134"), epp, "pv_total_energy", "Pv Total Energy (p13134)")
|
||||
pcTotalEnergy := entries.CopyPointFromName(epp.AddString("p13134"), epp, "pv_total_energy", "Pv Total Energy (p13134)")
|
||||
pcTotalEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,8 +480,8 @@ func (e *EndPoint) SetGridPoints(epp GoStruct.EndPointPath, entries api.DataMap)
|
||||
|
||||
totalLoadEnergy := entries.CopyPointFromName(epp.AddString("p13199"), epp, "total_load_energy", "Total Load Energy (Calc)")
|
||||
gridToLoadEnergyPercent := entries.CopyPoint(totalLoadEnergy, epp, "grid_to_load_energy_percent", "")
|
||||
gridToLoadEnergyPercent.SetValue(entries.GetPercent(gridToLoadEnergy, totalLoadEnergy, 1))
|
||||
gridToLoadEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
gridToLoadEnergyPercent.SetValue(entries.GetPercent(gridToLoadEnergy, totalLoadEnergy, 1))
|
||||
gridToLoadEnergyPercent.Value.SetUnit("%")
|
||||
|
||||
pvToGridPower := entries.CopyPointFromName(epp.AddString("p13121"), epp, "pv_to_grid_power", "Pv To Grid Power (p13121)")
|
||||
@ -489,6 +499,7 @@ func (e *EndPoint) SetGridPoints(epp GoStruct.EndPointPath, entries api.DataMap)
|
||||
pvToGridEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
|
||||
gridEnergy := entries.CopyPoint(pvToGridEnergy, epp, "grid_energy", "Grid Energy (Calc)")
|
||||
gridEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
gridEnergy.SetValue(entries.LowerUpper(pvToGridEnergy, gridToLoadEnergy))
|
||||
}
|
||||
}
|
||||
@ -496,7 +507,8 @@ func (e *EndPoint) SetGridPoints(epp GoStruct.EndPointPath, entries api.DataMap)
|
||||
func (e *EndPoint) SetLoadPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
for range Only.Once {
|
||||
// Daily Load Energy Consumption
|
||||
_ = entries.CopyPointFromName(epp.AddString("p13199"), epp, "daily_total_energy", "Daily Total Energy (p13199)")
|
||||
dailyTotalEnergy := entries.CopyPointFromName(epp.AddString("p13199"), epp, "daily_total_energy", "Daily Total Energy (p13199)")
|
||||
dailyTotalEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
|
||||
|
||||
// Total Load Energy Consumption
|
||||
// _ = entries.CopyPointFromName(epp.AddString("p13130"), epp, "total_energy_consumption", "")
|
||||
|
@ -31,60 +31,63 @@ func (p *Point) FixUnitType() Point {
|
||||
return *p
|
||||
}
|
||||
|
||||
func (p *Point) WhenReset() string {
|
||||
func (p *Point) WhenReset(date valueTypes.DateTime) string {
|
||||
var ret string
|
||||
|
||||
for range Only.Once {
|
||||
var err error
|
||||
now := time.Now()
|
||||
var now time.Time
|
||||
// now := time.Now()
|
||||
now = date.Time
|
||||
|
||||
switch {
|
||||
case p.Is5Minute():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 5).Format("2006-01-02T15:04:05"))
|
||||
// now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 5).Format("2006-01-02T15:04:05"))
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Truncate(time.Minute * 5).Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
case p.Is15Minute():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 15).Format("2006-01-02T15:04:05"))
|
||||
// now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 15).Format("2006-01-02T15:04:05"))
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Truncate(time.Minute * 15).Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
case p.Is30Minute():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 30).Format("2006-01-02T15:04:05"))
|
||||
// now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 30).Format("2006-01-02T15:04:05"))
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Truncate(time.Minute * 30).Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
|
||||
case p.IsInstant():
|
||||
// ret = ""
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
// valueTypes.DateTimeFullLayout
|
||||
ret = now.Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
case p.IsBoot():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Format("2006-01-02") + "T00:00:00")
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
case p.IsDaily():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Format("2006-01-02") + "T00:00:00")
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
case p.IsMonthly():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Format("2006-01") + "-01T00:00:00")
|
||||
ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
case p.IsYearly():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Format("2006") + "-01-01T00:00:00")
|
||||
ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Format(valueTypes.DateTimeFullLayout)
|
||||
|
||||
case p.IsTotal():
|
||||
ret = "1970-01-01T00:00:00"
|
||||
|
||||
default:
|
||||
// ret = "1970-01-01T00:00:00"
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
ret = now.Format(valueTypes.DateTimeFullLayout)
|
||||
}
|
||||
if err != nil {
|
||||
// now := time.Now()
|
||||
|
@ -80,7 +80,7 @@ func (m *Mqtt) SensorPublishValue(config EntityConfig) error {
|
||||
LastReset: config.LastReset, // m.GetLastReset(config.FullId),
|
||||
Value: value,
|
||||
}
|
||||
if config.UpdateFreq == "" {
|
||||
if config.StateClass != "total" {
|
||||
payload = MqttState {
|
||||
Value: value,
|
||||
}
|
||||
|
@ -687,34 +687,51 @@ func (config *EntityConfig) FixConfig() {
|
||||
config.Icon = SetDefault(config.Icon, "")
|
||||
}
|
||||
|
||||
if config.LastReset != "" {
|
||||
break
|
||||
switch {
|
||||
case config.Point.IsBoot():
|
||||
config.StateClass = "measurement"
|
||||
config.LastReset = ""
|
||||
config.LastResetValueTemplate = ""
|
||||
|
||||
case config.Point.IsDaily():
|
||||
fallthrough
|
||||
case config.Point.IsMonthly():
|
||||
fallthrough
|
||||
case config.Point.IsYearly():
|
||||
fallthrough
|
||||
case config.Point.IsTotal():
|
||||
config.StateClass = "total"
|
||||
config.LastResetValueTemplate = SetDefault(config.LastResetValueTemplate, "{{ value_json.last_reset | as_datetime }}")
|
||||
// config.LastReset = config.Point.WhenReset(config.Date)
|
||||
|
||||
case config.Point.Is5Minute():
|
||||
fallthrough
|
||||
case config.Point.Is15Minute():
|
||||
fallthrough
|
||||
case config.Point.Is30Minute():
|
||||
fallthrough
|
||||
case config.Point.IsInstant():
|
||||
fallthrough
|
||||
default:
|
||||
config.StateClass = "measurement"
|
||||
config.LastReset = ""
|
||||
config.LastResetValueTemplate = ""
|
||||
}
|
||||
|
||||
// if config.LastReset == "" {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// pt := api.GetDevicePoint(config.FullId)
|
||||
// if !pt.Valid {
|
||||
// break
|
||||
// }
|
||||
|
||||
if config.StateClass == "instant" {
|
||||
config.StateClass = "measurement"
|
||||
break
|
||||
}
|
||||
|
||||
if config.StateClass == "" {
|
||||
config.StateClass = "measurement"
|
||||
break
|
||||
}
|
||||
|
||||
//
|
||||
// config.LastReset = pt.WhenReset()
|
||||
config.LastResetValueTemplate = SetDefault(config.LastResetValueTemplate, "{{ value_json.last_reset | as_datetime() }}")
|
||||
// config.LastResetValueTemplate = SetDefault(config.LastResetValueTemplate, "{{ value_json.last_reset | as_datetime }}")
|
||||
// config.LastResetValueTemplate = SetDefault(config.LastResetValueTemplate, "{{ value_json.last_reset | int | timestamp_local | as_datetime }}")
|
||||
|
||||
if config.LastReset == "" {
|
||||
config.StateClass = "measurement"
|
||||
break
|
||||
}
|
||||
config.StateClass = "total"
|
||||
// config.StateClass = "total"
|
||||
// config.StateClass = "measurement"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user