1
0
Fork 0

zwave events

main v0.12.0
Jordan Hotmann 2023-11-27 15:59:35 -07:00
parent 8ceeed9278
commit fc1e13ad67
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
3 changed files with 54 additions and 22 deletions

View File

@ -17,6 +17,7 @@
- `homeassistant.states.{domain}.{entity}.{state}` - Home Assistant device state changes: [payload](https://www.home-assistant.io/docs/configuration/state_object/)
- `homeassistant.attributes.{domain}.{entity}.{state}` - When a device's attributes change but the state hasn't changed: [payload](https://www.home-assistant.io/docs/configuration/state_object/)
- `homeassistant.zha.{device IEEE}` - ZHA events: [payload](https://www.home-assistant.io/docs/configuration/state_object/)
- `homeassistant.zwave-scene.{device ID}` - ZwaveJS scene events: [payload](https://www.home-assistant.io/integrations/zwave_js/#scene-events-value-notification)
- `homeassistant.nfc.{tag ID}` - Home Assistant NFC tag scanned: [payload](https://www.home-assistant.io/docs/configuration/state_object/)
- `homeassistant.timer.{timer name}.finished` - Home Assistant timer finished: payload is simply `"finished"`
- `schedules.{schedule name}` - HATS schedule finished: payload is simply `"finished"`

View File

@ -25,6 +25,7 @@ const (
stateChangeEventId = 1001
zhaEventId = 1002
nfcEventId = 1003
zwaveEventId = 1004
timerFinishedEventId = 1005
)
@ -116,6 +117,10 @@ func handleMessages() {
Type: ha.MessageType.SubscribeEvents,
EventType: ha.MessageType.TagScanned,
Id: nfcEventId})
haWebsocketConn.WriteJSON(ha.SubscribeEventsMessage{
Type: ha.MessageType.SubscribeEvents,
EventType: ha.MessageType.ZwaveEvent,
Id: zwaveEventId})
haWebsocketConn.WriteJSON(ha.SubscribeEventsMessage{
Type: ha.MessageType.SubscribeEvents,
EventType: ha.MessageType.TimerFinished,
@ -147,6 +152,9 @@ func handleMessages() {
case nfcEventId:
data, _ := json.Marshal(message.Event.Data)
nats.Publish(fmt.Sprintf("homeassistant.nfc.%s", message.Event.Data.TagId), data)
case zwaveEventId:
data, _ := json.Marshal(message.Event.Data)
nats.Publish(fmt.Sprintf("homeassistant.zwave-scene.%s", message.Event.Data.DeviceId), data)
case timerFinishedEventId:
nats.PublishString(fmt.Sprintf("homeassistant.%s.finished", message.Event.Data.EntityId), "finished")
}

View File

@ -8,6 +8,7 @@ var MessageType = struct {
Result string
Event string
ZhaEvent string
ZwaveEvent string
SubscribeEvents string
StateChanged string
TagScanned string
@ -20,6 +21,7 @@ var MessageType = struct {
Result: "result",
Event: "event",
ZhaEvent: "zha_event",
ZwaveEvent: "zwave_js_value_notification",
SubscribeEvents: "subscribe_events",
StateChanged: "state_changed",
TagScanned: "tag_scanned",
@ -83,25 +85,27 @@ var Services = struct {
// Extra props that can be sent when calling a Home Assistant service
var ExtraProps = struct {
Transition string
Brightness string
BrightnessPercent string
HvacMode string
Temperature string
TargetTempHigh string
TargetTempLow string
Duration string
Value string
Transition string
Brightness string
BrightnessPercent string
BrightnessPercentStep string
HvacMode string
Temperature string
TargetTempHigh string
TargetTempLow string
Duration string
Value string
}{
Transition: "transition",
Brightness: "brightness",
BrightnessPercent: "brightness_pct",
HvacMode: "hvac_mode",
Temperature: "temperature",
TargetTempHigh: "target_temp_high",
TargetTempLow: "target_temp_low",
Duration: "duration",
Value: "value",
Transition: "transition",
Brightness: "brightness",
BrightnessPercent: "brightness_pct",
BrightnessPercentStep: "brightness_step_pct",
HvacMode: "hvac_mode",
Temperature: "temperature",
TargetTempHigh: "target_temp_high",
TargetTempLow: "target_temp_low",
Duration: "duration",
Value: "value",
}
type ResultContext struct {
@ -121,15 +125,34 @@ type StateData struct {
}
type EventData struct {
EntityId string `json:"entity_id,omitempty"`
NewState StateData `json:"new_state,omitempty"`
OldState StateData `json:"old_state,omitempty"`
EntityId string `json:"entity_id,omitempty"`
NewState StateData `json:"new_state,omitempty"`
OldState StateData `json:"old_state,omitempty"`
// ZHA
DeviceIeee string `json:"device_ieee,omitempty"`
DeviceId string `json:"device_id,omitempty"`
Command string `json:"command,omitempty"`
Args interface{} `json:"args,omitempty"`
Params interface{} `json:"params,omitempty"`
TagId string `json:"tag_id,omitempty"`
// NFC
TagId string `json:"tag_id,omitempty"`
// ZwaveJS Scene
Domain string `json:"domain,omitempty"`
NodeID int `json:"node_id,omitempty"`
HomeID string `json:"home_id,omitempty"`
Endpoint int `json:"endpoint,omitempty"`
CommandClass int `json:"command_class,omitempty"`
CommandClassName string `json:"command_class_name,omitempty"`
Label string `json:"label,omitempty"`
Property string `json:"property,omitempty"`
PropertyName string `json:"property_name,omitempty"`
PropertyKey string `json:"property_key,omitempty"`
PropertyKeyName string `json:"property_key_name,omitempty"`
Value string `json:"value,omitempty"`
ValueRaw int `json:"value_raw,omitempty"`
}
type Event struct {