1
0
Fork 0

Publish to different topic if state hasn't changed

main
Jordan Hotmann 2023-11-20 15:24:44 -07:00
parent a7130653c6
commit 3d835cf5d5
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
1 changed files with 5 additions and 1 deletions

View File

@ -134,7 +134,11 @@ func handleMessages() {
if marshallErr != nil { if marshallErr != nil {
logger.Error("Error marshalling event data", "error", marshallErr) logger.Error("Error marshalling event data", "error", marshallErr)
} }
if message.Event.Data.NewState.State == message.Event.Data.OldState.State {
nats.Publish(fmt.Sprintf("homeassistant.attributues.%s.%s", message.Event.Data.EntityId, message.Event.Data.NewState.State), data)
} else {
nats.Publish(fmt.Sprintf("homeassistant.states.%s.%s", message.Event.Data.EntityId, message.Event.Data.NewState.State), data) nats.Publish(fmt.Sprintf("homeassistant.states.%s.%s", message.Event.Data.EntityId, message.Event.Data.NewState.State), data)
}
nats.SetKeyValueString(fmt.Sprintf("homeassistant.states.%s", message.Event.Data.EntityId), message.Event.Data.NewState.State) nats.SetKeyValueString(fmt.Sprintf("homeassistant.states.%s", message.Event.Data.EntityId), message.Event.Data.NewState.State)
case zhaEventId: case zhaEventId:
data, _ := json.Marshal(message.Event.Data) data, _ := json.Marshal(message.Event.Data)