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 {
logger.Error("Error marshalling event data", "error", marshallErr)
}
nats.Publish(fmt.Sprintf("homeassistant.states.%s.%s", message.Event.Data.EntityId, message.Event.Data.NewState.State), data)
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.SetKeyValueString(fmt.Sprintf("homeassistant.states.%s", message.Event.Data.EntityId), message.Event.Data.NewState.State)
case zhaEventId:
data, _ := json.Marshal(message.Event.Data)