Skip to content

Commit

Permalink
feat: Add Home Assistant state_class for long term statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
adriffaud authored and Scrin committed Dec 14, 2022
1 parent 01695ba commit afac08b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data_sinks/mqtt_homeassistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type homeassistantDiscovery struct {
UniqueID string `json:"unique_id"`
DeviceClass string `json:"device_class,omitempty"`
StateTopic string `json:"state_topic"`
StateClass string `json:"state_class"`
JsonAttributesTopic string `json:"json_attributes_topic"`
Name string `json:"name,omitempty"`
UnitOfMeasurement string `json:"unit_of_measurement"`
Expand Down Expand Up @@ -182,6 +183,7 @@ func publishHomeAssistantDiscovery(client mqtt.Client, conf config.MQTTPublisher
UniqueID: id,
DeviceClass: disco.DeviceClass,
StateTopic: conf.TopicPrefix + "/" + measurement.Mac,
StateClass: "measurement",
JsonAttributesTopic: confTopicPrefix + "/attributes",
Name: fmt.Sprintf("%s %s", name, disco.NamePostfix),
UnitOfMeasurement: disco.UnitOfMeasurement,
Expand Down

0 comments on commit afac08b

Please sign in to comment.