Documentation ¶
Overview ¶
zhub4 - Система домашней автоматизации на Go Copyright (c) 2022-2023 GSB, Georgii Batanov gbatanov@yandex.ru MIT License
zhub4 - Система домашней автоматизации на Go Copyright (c) 2022-2023 GSB, Georgii Batanov gbatanov@yandex.ru MIT License
Index ¶
- Constants
- Variables
- func Command_to_string(c CommandId) string
- func GetDevicesByType(tp uint8) []uint64
- type BatteryParams
- type Command
- type CommandId
- type DeviceInfo
- type ElectricParams
- type EndDevice
- func (ed *EndDevice) Bytes_to_float64(src []byte) (float64, error)
- func (ed EndDevice) GetCurrentState(channel uint8) string
- func (ed EndDevice) GetDeviceType() uint8
- func (ed EndDevice) GetHumanName() string
- func (ed *EndDevice) GetMainsVoltage() float64
- func (ed EndDevice) GetMotionState() int8
- func (ed EndDevice) GetPowerSource() uint8
- func (ed *EndDevice) GetPromDoorString() string
- func (ed EndDevice) GetPromMotionString() string
- func (ed *EndDevice) GetPromPressure() string
- func (ed EndDevice) GetPromRelayString() string
- func (ed *EndDevice) Get_battery_level() uint8
- func (ed *EndDevice) Get_battery_voltage() float64
- func (ed *EndDevice) Get_current() float64
- func (ed *EndDevice) Get_energy() float64
- func (ed *EndDevice) Get_humidity() int8
- func (ed *EndDevice) Get_last_action() time.Time
- func (ed *EndDevice) Get_last_seen() time.Time
- func (ed *EndDevice) Get_linkquality() uint8
- func (ed *EndDevice) Get_luminocity() int8
- func (ed EndDevice) Get_mac_address() uint64
- func (ed *EndDevice) Get_power() float64
- func (ed *EndDevice) Get_pressure() float64
- func (ed *EndDevice) Get_temperature() int8
- func (ed *EndDevice) SetBatteryParams(value1 uint8, value2 float64)
- func (ed *EndDevice) SetCurrent(value float64)
- func (ed *EndDevice) SetCurrentState(state string, channel uint8)
- func (ed *EndDevice) SetLastAction(tm time.Time)
- func (ed *EndDevice) SetMainsVoltage(value float64)
- func (ed *EndDevice) SetMotionState(state uint8)
- func (ed *EndDevice) SetPowerSource(value uint8)
- func (ed *EndDevice) Set_energy(value float64)
- func (ed *EndDevice) Set_humidity(value int8)
- func (ed *EndDevice) Set_last_seen(tm time.Time)
- func (ed *EndDevice) Set_linkquality(quality uint8)
- func (ed *EndDevice) Set_luminocity(value int8)
- func (ed *EndDevice) Set_manufacturer(value string)
- func (ed *EndDevice) Set_model_identifier(value string)
- func (ed *EndDevice) Set_power(value float64)
- func (ed *EndDevice) Set_pressure(value float64)
- func (ed *EndDevice) Set_product_code(value string)
- func (ed *EndDevice) Set_temperature(value int8)
- type Event
- type EventHandler
- type Message
- type RF_Channels
- type Simple_descriptor
- type Zdo
- func (zdo *Zdo) ActiveEndpoints(address uint16) error
- func (zdo *Zdo) Bind(shortAddress uint16, macAddress uint64, endpoint uint8, cluster zcl.Cluster) error
- func (zdo *Zdo) FinishConfiguration() error
- func (zdo *Zdo) Generate_transaction_number() uint8
- func (zdo *Zdo) Generate_transaction_sequence_number() uint8
- func (zdo *Zdo) InputCommand()
- func (zdo *Zdo) ParseZclData(data []byte) zcl.Frame
- func (zdo *Zdo) PermitJoin(duration time.Duration) error
- func (zdo *Zdo) ReadRfChannels() RF_Channels
- func (zdo *Zdo) RegisterEndpointDescriptor(endpoint_descriptor Simple_descriptor) error
- func (zdo *Zdo) Reset() error
- func (zdo *Zdo) SendMessage(ep zcl.Endpoint, cl zcl.Cluster, frame zcl.Frame) error
- func (zdo *Zdo) Simple_descriptor(address uint16, endpointNumber uint8) error
- func (zdo *Zdo) Startup(delay time.Duration) error
- func (zdo *Zdo) Stop()
- func (zdo *Zdo) WriteRfChannels(new RF_Channels) error
Constants ¶
const BUTTON_IKEA = uint64(0x8cf681fffe0656ef)
const BUTTON_SONOFF_1 = uint64(0x00124b0028928e8a)
const BUTTON_SONOFF_2 = uint64(0x00124b00253ba75f)
const CLIMAT_BALCON = uint64(0x00124b000b1bb401)
const DOOR_1_TOILET = uint64(0x00124b0025485ee6)
const DOOR_2_CAB = uint64(0x00124b002512a60b)
const DOOR_3_BOX = uint64(0x00124b00250bba63)
const MOTION_1_CORIDOR = uint64(0x00124b0025137475)
const MOTION_2_ROOM = uint64(0x00124b0024455048)
const MOTION_3_CORIDOR = uint64(0x00124b002444d159)
const MOTION_4_NURSERY = uint64(0x00124b002a535b66)
const MOTION_5_KITCHEN = uint64(0x00124b002a507fe2)
const MOTION_IKEA = uint64(0x0c4314fffe17d8a8)
const MOTION_LIGHT_CORIDOR = uint64(0x00124b0014db2724)
const MOTION_LIGHT_NURSERY = uint64(0x00124b0007246963)
const PLUG_1 = uint64(0x70b3d52b6001b4a4)
const PLUG_2_CHARGER = uint64(0x70b3d52b6001b5d9)
const PLUG_3_NURSERY_LIGHT = uint64(0x70b3d52b60022ac9)
const PLUG_4_SOLDER = uint64(0x70b3d52b60022cfd)
const PRESENCE_1_KITCHEN = uint64(0x00124b0009451438)
const RELAY_1 = uint64(0x54ef44100019335b)
const RELAY_2_WASH = uint64(0x54ef441000193352)
const RELAY_3_CAB_LIGHT = uint64(0x54ef44100018b523)
const RELAY_4_CORIDOR_LIGHT = uint64(0x54ef4410001933d3)
const RELAY_5_TOILET = uint64(0x54ef4410005b2639)
const RELAY_6_ROOM_LIGHT = uint64(0x54ef441000609dcc)
const RELAY_7_KITCHEN = uint64(0x00158d0009414d7e)
const VALVE_COLD_WATER = uint64(0xa4c138373e89d731)
const VALVE_HOT_WATER = uint64(0xa4c138d9758e1dcd)
const WATER_LEAK_1 = uint64(0x00158d0006e469a4)
const WATER_LEAK_2 = uint64(0x00158d0006f8fc61)
const WATER_LEAK_3 = uint64(0x00158d0006b86b79)
const WATER_LEAK_4 = uint64(0x00158d0006ea99db)
Variables ¶
var DEVICE_TYPES map[uint8]string = map[uint8]string{ 1: "SonoffButton", 2: "SonoffMotionSensor", 3: "SonoffDoorSensor", 4: "Custom", 5: "WaterSensor", 6: "WaterValve", 7: "IkeaButton", 8: "IkeaMotionSensor", 9: "RelayAqara", 10: "SmartPlug", 11: "RelayAqaraDouble", } // 2 -?
Input clusters can have commands sent to them to perform actions, where as output clusters instead send these commands to a bound device.
var KNOWN_DEVICES map[uint64]DeviceInfo = map[uint64]DeviceInfo{ WATER_LEAK_1: {5, "Aqara", "SJCGQ11LM", "Протечка1", "Датчик протечки 1 (туалет)", zcl.PowerSource_BATTERY, 1, 0}, WATER_LEAK_2: {5, "Aqara", "SJCGQ11LM", "Протечка2", "Датчик протечки 2 (кухня)", zcl.PowerSource_BATTERY, 1, 0}, WATER_LEAK_3: {5, "Aqara", "SJCGQ11LM", "Протечка3", "Датчик протечки 3 (ванна)", zcl.PowerSource_BATTERY, 1, 0}, WATER_LEAK_4: {5, "Aqara", "SJCGQ11LM", "Протечка4", "Датчик протечки 4 (кухня)", zcl.PowerSource_BATTERY, 1, 0}, RELAY_2_WASH: {9, "Aqara", "SSM-U01", "Стиралка", "Реле2(Стиральная машина)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, RELAY_4_CORIDOR_LIGHT: {9, "Aqara", "SSM-U01", "КоридорСвет", "Реле4(Свет в коридоре)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, RELAY_5_TOILET: {9, "Aqara", "SSM-U01", "ТулетЗанят", "Реле5(Туалет занят)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, RELAY_6_ROOM_LIGHT: {9, "Aqara", "SSM-U01", "Реле6", "Реле6 (Свет комната)", zcl.PowerSource_SINGLE_PHASE, 1, 1}, RELAY_7_KITCHEN: {11, "Aqara", "Double", "КухняСвет/КухняВент", "Реле 7(Свет/Вентилятор кухня)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, PLUG_2_CHARGER: {10, "Girier", "TS011F", "Розетка2", "Розетка 2(Зарядники)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, PLUG_3_NURSERY_LIGHT: {10, "Girier", "TS011F", "Розетка3", "Розетка 3(Лампы в детской)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, VALVE_HOT_WATER: {6, "TUYA", "Valve", "КранГВ", "Кран1 ГВ", zcl.PowerSource_SINGLE_PHASE, 1, 0}, VALVE_COLD_WATER: {6, "TUYA", "Valve", "КранХВ", "Кран2 ХВ", zcl.PowerSource_SINGLE_PHASE, 1, 0}, MOTION_1_CORIDOR: {2, "Sonoff", "SNZB-03", "КоридорДвижение", "Датчик движения 1 (коридор)", zcl.PowerSource_BATTERY, 1, 0}, MOTION_2_ROOM: {2, "Sonoff", "SNZB-03", "КомнатаДвижение", "Датчик движения 2 (комната)", zcl.PowerSource_BATTERY, 1, 0}, MOTION_3_CORIDOR: {2, "Sonoff", "SNZB-03", "Движение3", "Датчик движения 3(коридор) ", zcl.PowerSource_BATTERY, 1, 0}, MOTION_4_NURSERY: {2, "Sonoff", "SNZB-03", "ДетскаяДвижение4", "Датчик движения 4 (детская)", zcl.PowerSource_BATTERY, 1, 0}, PRESENCE_1_KITCHEN: {4, "Custom", "CC2530", "КухняПрисутствие", "Датчик присутствия 1 (кухня)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, MOTION_LIGHT_NURSERY: {4, "Custom", "CC2530", "ДетскаяДвижение", "Датчик движение + освещение (детская)", zcl.PowerSource_SINGLE_PHASE, 1, 0}, DOOR_1_TOILET: {3, "Sonoff", "SNZB-04", "ТуалетДатчик", "Датчик открытия 1 (туалет)", zcl.PowerSource_BATTERY, 1, 0}, BUTTON_SONOFF_2: {1, "Sonoff", "SNZB-01", "Кнопка2", "Кнопка Sonoff 2", zcl.PowerSource_BATTERY, 1, 0}, CLIMAT_BALCON: {4, "GSB", "CC2530", "КлиматБалкон", "Датчик климата (балкон)", zcl.PowerSource_BATTERY, 1, 0}, }
MAC Address,Type, Vendor,Model, GrafanaName, Human name, Power source,available,test
var OFF_LIST []uint64 = []uint64{ RELAY_4_CORIDOR_LIGHT, RELAY_7_KITCHEN, RELAY_3_CAB_LIGHT, RELAY_5_TOILET, PLUG_1, PLUG_3_NURSERY_LIGHT, PLUG_4_SOLDER, RELAY_6_ROOM_LIGHT, }
List of devices that are turned off by long pressing the Sonoff1 button I use the same list for forced shutdown in the mode "No one is at home"
var PROM_DOOR_LIST []uint64 = []uint64{ DOOR_1_TOILET, }
var PROM_MOTION_LIST []uint64 = []uint64{ MOTION_1_CORIDOR, MOTION_LIGHT_CORIDOR, PRESENCE_1_KITCHEN, MOTION_5_KITCHEN, MOTION_2_ROOM, MOTION_3_CORIDOR, MOTION_4_NURSERY, MOTION_LIGHT_NURSERY, MOTION_IKEA, }
var PROM_RELAY_LIST []uint64 = []uint64{ RELAY_7_KITCHEN, RELAY_4_CORIDOR_LIGHT, RELAY_5_TOILET} // toilet is busy
Functions ¶
func Command_to_string ¶
func GetDevicesByType ¶
Types ¶
type BatteryParams ¶
type BatteryParams struct {
// contains filtered or unexported fields
}
type Command ¶
func (Command) Payload_size ¶
get payload size (size of field "Payload")
type CommandId ¶
type CommandId uint16
commands
const ( //System SYS_RESET_REQ CommandId = 0x4100 SYS_RESET_IND CommandId = 0x4180 SYS_PING CommandId = 0x2101 SYS_PING_SRSP CommandId = 0x6101 SYS_OSAL_NV_READ CommandId = 0x2108 SYS_OSAL_NV_READ_SRSP CommandId = 0x6108 SYS_OSAL_NV_WRITE CommandId = 0x2109 SYS_OSAL_NV_WRITE_SRSP CommandId = 0x6109 SYS_OSAL_NV_ITEM_INIT CommandId = 0x2107 SYS_OSAL_NV_ITEM_INIT_SRSP CommandId = 0x6107 SYS_OSAL_NV_LENGTH CommandId = 0x2113 SYS_OSAL_NV_LENGTH_SRSP CommandId = 0x6113 SYS_OSAL_NV_DELETE CommandId = 0x2112 SYS_OSAL_NV_DELETE_SRSP CommandId = 0x6112 SYS_SET_TX_POWER CommandId = 0x2114 SYS_SET_TX_POWER_SRSP CommandId = 0x6114 SYS_VERSION CommandId = 0x2102 SYS_VERSION_SRSP CommandId = 0x6102 // ZDO ZDO_STARTUP_FROM_APP_SRSP CommandId = 0x6540 ZDO_STATE_CHANGE_IND CommandId = 0x45c0 ZDO_BIND_REQ CommandId = 0x2521 ZDO_BIND_RSP CommandId = 0x45a1 ZDO_BIND_SRSP CommandId = 0x6521 ZDO_UNBIND_REQ CommandId = 0x2522 ZDO_UNBIND_RSP CommandId = 0x45a2 ZDO_MGMT_LQI_REQ CommandId = 0x2531 ZDO_MGMT_LQI_SRSP CommandId = 0x6531 ZDO_MGMT_LQI_RSP CommandId = 0x45b1 ZDO_SRC_RTG_IND CommandId = 0x45C4 ZDO_MGMT_PERMIT_JOIN_REQ CommandId = 0x2536 ZDO_MGMT_PERMIT_JOIN_SRSP CommandId = 0x6536 ZDO_MGMT_PERMIT_JOIN_RSP CommandId = 0x45b6 ZDO_PERMIT_JOIN_IND CommandId = 0x45cb ZDO_TC_DEV_IND CommandId = 0x45ca ZDO_LEAVE_IND CommandId = 0x45c9 ZDO_END_DEVICE_ANNCE_IND CommandId = 0x45c1 ZDO_ACTIVE_EP_REQ CommandId = 0x2505 ZDO_ACTIVE_EP_SRSP CommandId = 0x6505 ZDO_ACTIVE_EP_RSP CommandId = 0x4585 ZDO_SIMPLE_DESC_REQ CommandId = 0x2504 ZDO_SIMPLE_DESC_SRSP CommandId = 0x6504 ZDO_SIMPLE_DESC_RSP CommandId = 0x4584 ZDO_POWER_DESC_REQ CommandId = 0x2503 ZDO_POWER_DESC_SRSP CommandId = 0x6503 ZDO_POWER_DESC_RSP CommandId = 0x4583 ZDO_IEEE_ADDR_REQ CommandId = 0x2501 ZDO_IEEE_ADDR_REQ_SRSP CommandId = 0x6501 ZDO_IEEE_ADDR_RSP CommandId = 0x4581 ZDO_STARTUP_FROM_APP CommandId = 0x2540 // AF AF_REGISTER CommandId = 0x2400 AF_REGISTER_SRSP CommandId = 0x6400 AF_INCOMING_MSG CommandId = 0x4481 AF_DATA_REQUEST CommandId = 0x2401 AF_DATA_REQUEST_SRSP CommandId = 0x6401 AF_DATA_CONFIRM CommandId = 0x4480 // UTIL UTIL_GET_DEVICE_INFO CommandId = 0x2700 UTIL_GET_DEVICE_INFO_SRSP CommandId = 0x6700 // ZB ZB_GET_DEVICE_INFO CommandId = 0x2606 ZB_GET_DEVICE_INFO_SRSP CommandId = 0x6606 )
type DeviceInfo ¶
type DeviceInfo struct { PowerSource zcl.PowerSource Available uint8 // include in prod configuration Test uint8 //include in test configuration // contains filtered or unexported fields }
type ElectricParams ¶
type ElectricParams struct {
// contains filtered or unexported fields
}
type EndDevice ¶
type EndDevice struct { MacAddress uint64 ShortAddress uint16 Di DeviceInfo ChargerOn bool // contains filtered or unexported fields }
func EndDeviceCreate ¶
func (*EndDevice) Bytes_to_float64 ¶
func (EndDevice) GetCurrentState ¶
func (EndDevice) GetDeviceType ¶
func (EndDevice) GetHumanName ¶
func (*EndDevice) GetMainsVoltage ¶
func (EndDevice) GetMotionState ¶
func (EndDevice) GetPowerSource ¶
func (*EndDevice) GetPromDoorString ¶
/ @brief Возвращает строку для Prometheus / @return
func (EndDevice) GetPromMotionString ¶
func (*EndDevice) GetPromPressure ¶
func (EndDevice) GetPromRelayString ¶
/ @brief Возвращает строку для Prometheus / Чтобы линия реле не сливалась с линией датчика, / искуственно отступаю на 0,1 / @return
func (*EndDevice) Get_battery_level ¶
func (*EndDevice) Get_battery_voltage ¶
func (*EndDevice) Get_current ¶
func (*EndDevice) Get_energy ¶
func (*EndDevice) Get_humidity ¶
func (*EndDevice) Get_last_action ¶
func (*EndDevice) Get_last_seen ¶
func (*EndDevice) Get_linkquality ¶
func (*EndDevice) Get_luminocity ¶
func (EndDevice) Get_mac_address ¶
func (*EndDevice) Get_pressure ¶
func (*EndDevice) Get_temperature ¶
func (*EndDevice) SetBatteryParams ¶
charge level, battery voltage
func (*EndDevice) SetCurrent ¶
func (*EndDevice) SetCurrentState ¶
func (*EndDevice) SetLastAction ¶
func (*EndDevice) SetMainsVoltage ¶
func (*EndDevice) SetMotionState ¶
func (*EndDevice) SetPowerSource ¶
func (*EndDevice) Set_energy ¶
func (*EndDevice) Set_humidity ¶
func (*EndDevice) Set_last_seen ¶
func (*EndDevice) Set_linkquality ¶
func (*EndDevice) Set_luminocity ¶
func (*EndDevice) Set_manufacturer ¶
func (*EndDevice) Set_model_identifier ¶
func (*EndDevice) Set_pressure ¶
func (*EndDevice) Set_product_code ¶
func (*EndDevice) Set_temperature ¶
type EventHandler ¶
func Create_event_handler ¶
func Create_event_handler() *EventHandler
func (*EventHandler) AddEvent ¶
func (eh *EventHandler) AddEvent(id CommandId)
func (*EventHandler) GetEvent ¶
func (eh *EventHandler) GetEvent(id CommandId) *Event
type RF_Channels ¶
type RF_Channels struct {
Channels []uint8
}
var DefaultRFChannels RF_Channels = RF_Channels{[]uint8{11}}
var TestRFChannels RF_Channels = RF_Channels{[]uint8{15}}
func (RF_Channels) Compare ¶
func (current RF_Channels) Compare(new RF_Channels) bool
type Simple_descriptor ¶
type Simple_descriptor struct {
// contains filtered or unexported fields
}
var Default_endpoint Simple_descriptor = Simple_descriptor{1, 0x0104, 0x05, 0, []uint16{}, []uint16{}} // Output clusters list.
type Zdo ¶
type Zdo struct { Flag bool Uart *serial3.Uart Cmdinput chan []byte ShortAddress uint16 // contains filtered or unexported fields }
func (*Zdo) ActiveEndpoints ¶
get endpoint list from device
func (*Zdo) Bind ¶
func (zdo *Zdo) Bind(shortAddress uint16, macAddress uint64, endpoint uint8, cluster zcl.Cluster) error
bind device with zhub
func (*Zdo) FinishConfiguration ¶
func (*Zdo) Generate_transaction_number ¶
in payload
func (*Zdo) Generate_transaction_sequence_number ¶
in zcl.Frame
func (*Zdo) InputCommand ¶
func (zdo *Zdo) InputCommand()
receive command from UART and call command handler
func (*Zdo) PermitJoin ¶
Enable pairing mode for duration seconds
func (*Zdo) ReadRfChannels ¶
func (zdo *Zdo) ReadRfChannels() RF_Channels
read channels list from coordinator
func (*Zdo) RegisterEndpointDescriptor ¶
func (zdo *Zdo) RegisterEndpointDescriptor(endpoint_descriptor Simple_descriptor) error
func (*Zdo) SendMessage ¶
send a message to a specific device
func (*Zdo) Simple_descriptor ¶
get endpoint descriptor from device
func (*Zdo) WriteRfChannels ¶
func (zdo *Zdo) WriteRfChannels(new RF_Channels) error
write channels list into coordinator