esphome 2024.8.2__py3-none-any.whl → 2024.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. esphome/__main__.py +6 -2
  2. esphome/components/api/api_connection.cpp +53 -0
  3. esphome/components/api/api_connection.h +4 -0
  4. esphome/components/api/api_pb2.cpp +280 -0
  5. esphome/components/api/api_pb2.h +91 -0
  6. esphome/components/api/api_pb2_service.cpp +85 -0
  7. esphome/components/api/api_pb2_service.h +28 -0
  8. esphome/components/async_tcp/__init__.py +3 -3
  9. esphome/components/atm90e26/sensor.py +10 -10
  10. esphome/components/atm90e32/sensor.py +1 -1
  11. esphome/components/bl0906/__init__.py +1 -0
  12. esphome/components/bl0906/bl0906.cpp +238 -0
  13. esphome/components/bl0906/bl0906.h +96 -0
  14. esphome/components/bl0906/const.py +4 -0
  15. esphome/components/bl0906/constants.h +122 -0
  16. esphome/components/bl0906/sensor.py +184 -0
  17. esphome/components/bl0942/__init__.py +1 -1
  18. esphome/components/bl0942/bl0942.cpp +127 -34
  19. esphome/components/bl0942/bl0942.h +87 -3
  20. esphome/components/bl0942/sensor.py +46 -8
  21. esphome/components/ble_client/__init__.py +1 -3
  22. esphome/components/ble_presence/binary_sensor.py +2 -2
  23. esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +5 -0
  24. esphome/components/bmp280/sensor.py +2 -93
  25. esphome/components/bmp280_base/__init__.py +88 -0
  26. esphome/components/{bmp280/bmp280.cpp → bmp280_base/bmp280_base.cpp} +11 -4
  27. esphome/components/{bmp280/bmp280.h → bmp280_base/bmp280_base.h} +9 -5
  28. esphome/components/bmp280_i2c/__init__.py +0 -0
  29. esphome/components/bmp280_i2c/bmp280_i2c.cpp +27 -0
  30. esphome/components/bmp280_i2c/bmp280_i2c.h +22 -0
  31. esphome/components/bmp280_i2c/sensor.py +22 -0
  32. esphome/components/bmp280_spi/__init__.py +0 -0
  33. esphome/components/bmp280_spi/bmp280_spi.cpp +65 -0
  34. esphome/components/bmp280_spi/bmp280_spi.h +20 -0
  35. esphome/components/bmp280_spi/sensor.py +22 -0
  36. esphome/components/captive_portal/captive_portal.cpp +2 -0
  37. esphome/components/captive_portal/captive_portal.h +3 -1
  38. esphome/components/ch422g/__init__.py +67 -0
  39. esphome/components/ch422g/ch422g.cpp +122 -0
  40. esphome/components/ch422g/ch422g.h +70 -0
  41. esphome/components/debug/debug_esp32.cpp +3 -1
  42. esphome/components/display/__init__.py +5 -4
  43. esphome/components/dsmr/dsmr.cpp +6 -0
  44. esphome/components/dsmr/dsmr.h +6 -0
  45. esphome/components/dsmr/text_sensor.py +7 -2
  46. esphome/components/e131/e131.cpp +2 -0
  47. esphome/components/e131/e131.h +3 -1
  48. esphome/components/e131/e131_addressable_light_effect.cpp +2 -0
  49. esphome/components/e131/e131_addressable_light_effect.h +2 -1
  50. esphome/components/e131/e131_packet.cpp +2 -0
  51. esphome/components/esp32_ble/ble_uuid.cpp +7 -0
  52. esphome/components/esp32_ble/ble_uuid.h +1 -0
  53. esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +11 -9
  54. esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +3 -3
  55. esphome/components/esp32_camera/__init__.py +4 -0
  56. esphome/components/esp32_camera/esp32_camera.cpp +9 -1
  57. esphome/components/esp32_camera/esp32_camera.h +3 -0
  58. esphome/components/esp32_can/canbus.py +18 -7
  59. esphome/components/esp32_can/esp32_can.cpp +8 -0
  60. esphome/components/esp32_can/esp32_can.h +4 -0
  61. esphome/components/esp32_rmt_led_strip/led_strip.cpp +14 -2
  62. esphome/components/esp32_rmt_led_strip/led_strip.h +3 -2
  63. esphome/components/esp32_rmt_led_strip/light.py +21 -4
  64. esphome/components/esphome/ota/ota_esphome.cpp +2 -1
  65. esphome/components/esphome/ota/ota_esphome.h +2 -0
  66. esphome/components/font/__init__.py +11 -22
  67. esphome/components/font/font.cpp +3 -2
  68. esphome/components/font/font.h +12 -3
  69. esphome/components/gree/climate.py +2 -1
  70. esphome/components/gree/gree.cpp +54 -3
  71. esphome/components/gree/gree.h +10 -2
  72. esphome/components/gt911/touchscreen/__init__.py +6 -4
  73. esphome/components/gt911/touchscreen/gt911_touchscreen.cpp +17 -0
  74. esphome/components/gt911/touchscreen/gt911_touchscreen.h +2 -0
  75. esphome/components/hmac_md5/__init__.py +2 -0
  76. esphome/components/hmac_md5/hmac_md5.cpp +56 -0
  77. esphome/components/hmac_md5/hmac_md5.h +48 -0
  78. esphome/components/homeassistant/__init__.py +13 -0
  79. esphome/components/homeassistant/switch/__init__.py +15 -2
  80. esphome/components/homeassistant/switch/homeassistant_switch.cpp +2 -2
  81. esphome/components/i2s_audio/__init__.py +88 -9
  82. esphome/components/i2s_audio/i2s_audio.h +20 -2
  83. esphome/components/i2s_audio/media_player/__init__.py +8 -4
  84. esphome/components/i2s_audio/media_player/i2s_audio_media_player.h +1 -1
  85. esphome/components/i2s_audio/microphone/__init__.py +19 -51
  86. esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +18 -15
  87. esphome/components/i2s_audio/microphone/i2s_audio_microphone.h +0 -12
  88. esphome/components/i2s_audio/speaker/__init__.py +39 -27
  89. esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +49 -37
  90. esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +3 -4
  91. esphome/components/ili9xxx/display.py +16 -17
  92. esphome/components/ili9xxx/ili9xxx_display.cpp +1 -1
  93. esphome/components/ili9xxx/ili9xxx_display.h +18 -18
  94. esphome/components/ili9xxx/ili9xxx_init.h +0 -3
  95. esphome/components/improv_serial/improv_serial_component.cpp +2 -1
  96. esphome/components/improv_serial/improv_serial_component.h +2 -1
  97. esphome/components/ledc/ledc_output.cpp +11 -7
  98. esphome/components/libretiny/__init__.py +8 -13
  99. esphome/components/ltr501/__init__.py +1 -0
  100. esphome/components/ltr501/ltr501.cpp +542 -0
  101. esphome/components/ltr501/ltr501.h +184 -0
  102. esphome/components/ltr501/ltr_definitions_501.h +260 -0
  103. esphome/components/ltr501/sensor.py +274 -0
  104. esphome/components/ltr_als_ps/sensor.py +2 -2
  105. esphome/components/lvgl/__init__.py +19 -16
  106. esphome/components/lvgl/automation.py +90 -9
  107. esphome/components/lvgl/defines.py +29 -2
  108. esphome/components/lvgl/gradient.py +61 -0
  109. esphome/components/lvgl/lv_validation.py +45 -27
  110. esphome/components/lvgl/lvcode.py +8 -3
  111. esphome/components/lvgl/lvgl_esphome.cpp +54 -0
  112. esphome/components/lvgl/lvgl_esphome.h +9 -3
  113. esphome/components/lvgl/number/__init__.py +1 -0
  114. esphome/components/lvgl/number/lvgl_number.h +3 -1
  115. esphome/components/lvgl/schemas.py +16 -11
  116. esphome/components/lvgl/select/__init__.py +1 -0
  117. esphome/components/lvgl/select/lvgl_select.h +3 -1
  118. esphome/components/lvgl/switch/__init__.py +2 -1
  119. esphome/components/lvgl/switch/lvgl_switch.h +3 -1
  120. esphome/components/lvgl/text/__init__.py +1 -0
  121. esphome/components/lvgl/text/lvgl_text.h +3 -1
  122. esphome/components/lvgl/trigger.py +3 -2
  123. esphome/components/lvgl/types.py +2 -1
  124. esphome/components/lvgl/widgets/__init__.py +23 -8
  125. esphome/components/lvgl/widgets/arc.py +5 -1
  126. esphome/components/lvgl/widgets/buttonmatrix.py +5 -1
  127. esphome/components/lvgl/widgets/checkbox.py +8 -3
  128. esphome/components/lvgl/widgets/meter.py +8 -1
  129. esphome/components/lvgl/widgets/msgbox.py +26 -15
  130. esphome/components/lvgl/widgets/page.py +51 -7
  131. esphome/components/lvgl/widgets/tileview.py +2 -8
  132. esphome/components/max31856/max31856.cpp +12 -1
  133. esphome/components/max31856/max31856.h +5 -2
  134. esphome/components/max31856/sensor.py +20 -0
  135. esphome/components/mcp9600/sensor.py +2 -2
  136. esphome/components/mdns/__init__.py +6 -6
  137. esphome/components/media_player/media_player.h +16 -0
  138. esphome/components/micro_wake_word/__init__.py +2 -25
  139. esphome/components/microphone/microphone.h +1 -1
  140. esphome/components/mics_4514/mics_4514.cpp +26 -36
  141. esphome/components/modbus_controller/__init__.py +6 -0
  142. esphome/components/modbus_controller/const.py +2 -0
  143. esphome/components/modbus_controller/modbus_controller.cpp +30 -27
  144. esphome/components/modbus_controller/modbus_controller.h +22 -4
  145. esphome/components/network/__init__.py +11 -8
  146. esphome/components/pipsolar/pipsolar.cpp +3 -0
  147. esphome/components/pipsolar/pipsolar.h +1 -0
  148. esphome/components/pipsolar/switch/__init__.py +2 -0
  149. esphome/components/prometheus/prometheus_handler.cpp +2 -0
  150. esphome/components/prometheus/prometheus_handler.h +3 -1
  151. esphome/components/rp2040/__init__.py +7 -8
  152. esphome/components/rpi_dpi_rgb/display.py +20 -17
  153. esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp +36 -6
  154. esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h +4 -0
  155. esphome/components/socket/socket.cpp +2 -0
  156. esphome/components/socket/socket.h +2 -0
  157. esphome/components/speaker/speaker.h +1 -1
  158. esphome/components/st7701s/display.py +35 -37
  159. esphome/components/st7701s/st7701s.cpp +11 -6
  160. esphome/components/st7701s/st7701s.h +1 -0
  161. esphome/components/statsd/__init__.py +65 -0
  162. esphome/components/statsd/statsd.cpp +156 -0
  163. esphome/components/statsd/statsd.h +86 -0
  164. esphome/components/tuya/__init__.py +1 -0
  165. esphome/components/tuya/number/__init__.py +39 -2
  166. esphome/components/tuya/number/tuya_number.cpp +58 -2
  167. esphome/components/tuya/number/tuya_number.h +12 -3
  168. esphome/components/udp/__init__.py +158 -0
  169. esphome/components/udp/binary_sensor.py +27 -0
  170. esphome/components/udp/sensor.py +27 -0
  171. esphome/components/udp/udp_component.cpp +616 -0
  172. esphome/components/udp/udp_component.h +158 -0
  173. esphome/components/uponor_smatrix/uponor_smatrix.cpp +4 -6
  174. esphome/components/uponor_smatrix/uponor_smatrix.h +0 -1
  175. esphome/components/veml7700/sensor.py +2 -2
  176. esphome/components/voice_assistant/__init__.py +6 -0
  177. esphome/components/voice_assistant/voice_assistant.cpp +24 -2
  178. esphome/components/voice_assistant/voice_assistant.h +20 -0
  179. esphome/components/web_server/__init__.py +11 -11
  180. esphome/components/web_server/list_entities.cpp +2 -0
  181. esphome/components/web_server/list_entities.h +3 -1
  182. esphome/components/web_server/web_server.cpp +2 -1
  183. esphome/components/web_server/web_server.h +2 -0
  184. esphome/components/web_server_base/web_server_base.cpp +2 -0
  185. esphome/components/web_server_base/web_server_base.h +3 -1
  186. esphome/components/wifi/wifi_component_libretiny.cpp +15 -1
  187. esphome/components/wireguard/__init__.py +9 -6
  188. esphome/components/wireguard/wireguard.cpp +2 -1
  189. esphome/components/wireguard/wireguard.h +3 -1
  190. esphome/config_validation.py +8 -0
  191. esphome/const.py +8 -1
  192. esphome/core/bytebuffer.cpp +117 -84
  193. esphome/core/bytebuffer.h +69 -21
  194. esphome/core/config.py +0 -3
  195. esphome/core/defines.h +2 -0
  196. esphome/core/ring_buffer.cpp +13 -2
  197. esphome/core/ring_buffer.h +56 -0
  198. esphome/external_files.py +5 -3
  199. {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/METADATA +1 -1
  200. {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/RECORD +204 -169
  201. {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/LICENSE +0 -0
  202. {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/WHEEL +0 -0
  203. {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/entry_points.txt +0 -0
  204. {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,184 @@
1
+ from esphome import automation
2
+ from esphome.automation import maybe_simple_id
3
+ import esphome.codegen as cg
4
+ from esphome.components import sensor, uart
5
+ import esphome.config_validation as cv
6
+ from esphome.const import (
7
+ CONF_CHANNEL,
8
+ CONF_CURRENT,
9
+ CONF_ENERGY,
10
+ CONF_FREQUENCY,
11
+ CONF_ID,
12
+ CONF_NAME,
13
+ CONF_POWER,
14
+ CONF_TEMPERATURE,
15
+ CONF_TOTAL_POWER,
16
+ CONF_VOLTAGE,
17
+ DEVICE_CLASS_CURRENT,
18
+ DEVICE_CLASS_ENERGY,
19
+ DEVICE_CLASS_FREQUENCY,
20
+ DEVICE_CLASS_POWER,
21
+ DEVICE_CLASS_TEMPERATURE,
22
+ DEVICE_CLASS_VOLTAGE,
23
+ ICON_CURRENT_AC,
24
+ ICON_POWER,
25
+ ICON_THERMOMETER,
26
+ STATE_CLASS_MEASUREMENT,
27
+ STATE_CLASS_TOTAL_INCREASING,
28
+ UNIT_AMPERE,
29
+ UNIT_CELSIUS,
30
+ UNIT_HERTZ,
31
+ UNIT_KILOWATT_HOURS,
32
+ UNIT_VOLT,
33
+ UNIT_WATT,
34
+ )
35
+
36
+ # Import ICONS not included in esphome's const.py, from the local components const.py
37
+ from .const import ICON_ENERGY, ICON_FREQUENCY, ICON_VOLTAGE
38
+
39
+ DEPENDENCIES = ["uart"]
40
+ AUTO_LOAD = ["bl0906"]
41
+ CONF_TOTAL_ENERGY = "total_energy"
42
+
43
+ bl0906_ns = cg.esphome_ns.namespace("bl0906")
44
+ BL0906 = bl0906_ns.class_("BL0906", cg.PollingComponent, uart.UARTDevice)
45
+ ResetEnergyAction = bl0906_ns.class_("ResetEnergyAction", automation.Action)
46
+
47
+ CONFIG_SCHEMA = (
48
+ cv.Schema(
49
+ {
50
+ cv.GenerateID(): cv.declare_id(BL0906),
51
+ cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(
52
+ icon=ICON_FREQUENCY,
53
+ accuracy_decimals=0,
54
+ device_class=DEVICE_CLASS_FREQUENCY,
55
+ unit_of_measurement=UNIT_HERTZ,
56
+ state_class=STATE_CLASS_MEASUREMENT,
57
+ ),
58
+ cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
59
+ icon=ICON_THERMOMETER,
60
+ accuracy_decimals=0,
61
+ device_class=DEVICE_CLASS_TEMPERATURE,
62
+ unit_of_measurement=UNIT_CELSIUS,
63
+ state_class=STATE_CLASS_MEASUREMENT,
64
+ ),
65
+ cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
66
+ icon=ICON_VOLTAGE,
67
+ accuracy_decimals=1,
68
+ device_class=DEVICE_CLASS_VOLTAGE,
69
+ unit_of_measurement=UNIT_VOLT,
70
+ state_class=STATE_CLASS_MEASUREMENT,
71
+ ),
72
+ cv.Optional(CONF_TOTAL_POWER): sensor.sensor_schema(
73
+ icon=ICON_POWER,
74
+ accuracy_decimals=3,
75
+ device_class=DEVICE_CLASS_POWER,
76
+ unit_of_measurement=UNIT_WATT,
77
+ state_class=STATE_CLASS_MEASUREMENT,
78
+ ),
79
+ cv.Optional(CONF_TOTAL_ENERGY): sensor.sensor_schema(
80
+ icon=ICON_ENERGY,
81
+ accuracy_decimals=3,
82
+ device_class=DEVICE_CLASS_ENERGY,
83
+ state_class=STATE_CLASS_TOTAL_INCREASING,
84
+ unit_of_measurement=UNIT_KILOWATT_HOURS,
85
+ ),
86
+ }
87
+ )
88
+ .extend(
89
+ cv.Schema(
90
+ {
91
+ cv.Optional(f"{CONF_CHANNEL}_{i + 1}"): cv.Schema(
92
+ {
93
+ cv.Optional(CONF_CURRENT): cv.maybe_simple_value(
94
+ sensor.sensor_schema(
95
+ icon=ICON_CURRENT_AC,
96
+ accuracy_decimals=3,
97
+ device_class=DEVICE_CLASS_CURRENT,
98
+ unit_of_measurement=UNIT_AMPERE,
99
+ state_class=STATE_CLASS_MEASUREMENT,
100
+ ),
101
+ key=CONF_NAME,
102
+ ),
103
+ cv.Optional(CONF_POWER): cv.maybe_simple_value(
104
+ sensor.sensor_schema(
105
+ icon=ICON_POWER,
106
+ accuracy_decimals=0,
107
+ device_class=DEVICE_CLASS_POWER,
108
+ unit_of_measurement=UNIT_WATT,
109
+ state_class=STATE_CLASS_MEASUREMENT,
110
+ ),
111
+ key=CONF_NAME,
112
+ ),
113
+ cv.Optional(CONF_ENERGY): cv.maybe_simple_value(
114
+ sensor.sensor_schema(
115
+ icon=ICON_ENERGY,
116
+ accuracy_decimals=3,
117
+ device_class=DEVICE_CLASS_ENERGY,
118
+ unit_of_measurement=UNIT_KILOWATT_HOURS,
119
+ state_class=STATE_CLASS_TOTAL_INCREASING,
120
+ ),
121
+ key=CONF_NAME,
122
+ ),
123
+ }
124
+ )
125
+ for i in range(6)
126
+ }
127
+ )
128
+ )
129
+ .extend(uart.UART_DEVICE_SCHEMA)
130
+ .extend(cv.polling_component_schema("60s"))
131
+ )
132
+
133
+ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
134
+ "bl0906", baud_rate=19200, require_tx=True, require_rx=True
135
+ )
136
+
137
+
138
+ @automation.register_action(
139
+ "bl0906.reset_energy",
140
+ ResetEnergyAction,
141
+ maybe_simple_id(
142
+ {
143
+ cv.Required(CONF_ID): cv.use_id(BL0906),
144
+ }
145
+ ),
146
+ )
147
+ async def reset_energy_to_code(config, action_id, template_arg, args):
148
+ paren = await cg.get_variable(config[CONF_ID])
149
+ return cg.new_Pvariable(action_id, template_arg, paren)
150
+
151
+
152
+ async def to_code(config):
153
+ var = cg.new_Pvariable(config[CONF_ID])
154
+ await cg.register_component(var, config)
155
+ await uart.register_uart_device(var, config)
156
+ if frequency_config := config.get(CONF_FREQUENCY):
157
+ sens = await sensor.new_sensor(frequency_config)
158
+ cg.add(var.set_frequency_sensor(sens))
159
+ if temperature_config := config.get(CONF_TEMPERATURE):
160
+ sens = await sensor.new_sensor(temperature_config)
161
+ cg.add(var.set_temperature_sensor(sens))
162
+ if voltage_config := config.get(CONF_VOLTAGE):
163
+ sens = await sensor.new_sensor(voltage_config)
164
+ cg.add(var.set_voltage_sensor(sens))
165
+
166
+ for i in range(6):
167
+ if channel_config := config.get(f"{CONF_CHANNEL}_{i + 1}"):
168
+ if current_config := channel_config.get(CONF_CURRENT):
169
+ sens = await sensor.new_sensor(current_config)
170
+ cg.add(getattr(var, f"set_current_{i + 1}_sensor")(sens))
171
+ if power_config := channel_config.get(CONF_POWER):
172
+ sens = await sensor.new_sensor(power_config)
173
+ cg.add(getattr(var, f"set_power_{i + 1}_sensor")(sens))
174
+ if energy_config := channel_config.get(CONF_ENERGY):
175
+ sens = await sensor.new_sensor(energy_config)
176
+ cg.add(getattr(var, f"set_energy_{i + 1}_sensor")(sens))
177
+
178
+ if total_power_config := config.get(CONF_TOTAL_POWER):
179
+ sens = await sensor.new_sensor(total_power_config)
180
+ cg.add(var.set_total_power_sensor(sens))
181
+
182
+ if total_energy_config := config.get(CONF_TOTAL_ENERGY):
183
+ sens = await sensor.new_sensor(total_energy_config)
184
+ cg.add(var.set_total_energy_sensor(sens))
@@ -1 +1 @@
1
- CODEOWNERS = ["@dbuezas"]
1
+ CODEOWNERS = ["@dbuezas", "@dwmw2"]
@@ -2,6 +2,8 @@
2
2
  #include "esphome/core/log.h"
3
3
  #include <cinttypes>
4
4
 
5
+ // Datasheet: https://www.belling.com.cn/media/file_object/bel_product/BL0942/datasheet/BL0942_V1.06_en.pdf
6
+
5
7
  namespace esphome {
6
8
  namespace bl0942 {
7
9
 
@@ -12,43 +14,64 @@ static const uint8_t BL0942_FULL_PACKET = 0xAA;
12
14
  static const uint8_t BL0942_PACKET_HEADER = 0x55;
13
15
 
14
16
  static const uint8_t BL0942_WRITE_COMMAND = 0xA8;
15
- static const uint8_t BL0942_REG_I_FAST_RMS_CTRL = 0x10;
16
- static const uint8_t BL0942_REG_MODE = 0x18;
17
- static const uint8_t BL0942_REG_SOFT_RESET = 0x19;
18
- static const uint8_t BL0942_REG_USR_WRPROT = 0x1A;
17
+
18
+ static const uint8_t BL0942_REG_I_RMSOS = 0x12;
19
+ static const uint8_t BL0942_REG_WA_CREEP = 0x14;
20
+ static const uint8_t BL0942_REG_I_FAST_RMS_TH = 0x15;
21
+ static const uint8_t BL0942_REG_I_FAST_RMS_CYC = 0x16;
22
+ static const uint8_t BL0942_REG_FREQ_CYC = 0x17;
23
+ static const uint8_t BL0942_REG_OT_FUNX = 0x18;
24
+ static const uint8_t BL0942_REG_MODE = 0x19;
25
+ static const uint8_t BL0942_REG_SOFT_RESET = 0x1C;
26
+ static const uint8_t BL0942_REG_USR_WRPROT = 0x1D;
19
27
  static const uint8_t BL0942_REG_TPS_CTRL = 0x1B;
20
28
 
21
- // TODO: Confirm insialisation works as intended
22
- const uint8_t BL0942_INIT[5][6] = {
23
- // Reset to default
24
- {BL0942_WRITE_COMMAND, BL0942_REG_SOFT_RESET, 0x5A, 0x5A, 0x5A, 0x38},
25
- // Enable User Operation Write
26
- {BL0942_WRITE_COMMAND, BL0942_REG_USR_WRPROT, 0x55, 0x00, 0x00, 0xF0},
27
- // 0x0100 = CF_UNABLE energy pulse, AC_FREQ_SEL 50Hz, RMS_UPDATE_SEL 800mS
28
- {BL0942_WRITE_COMMAND, BL0942_REG_MODE, 0x00, 0x10, 0x00, 0x37},
29
- // 0x47FF = Over-current and leakage alarm on, Automatic temperature measurement, Interval 100mS
30
- {BL0942_WRITE_COMMAND, BL0942_REG_TPS_CTRL, 0xFF, 0x47, 0x00, 0xFE},
31
- // 0x181C = Half cycle, Fast RMS threshold 6172
32
- {BL0942_WRITE_COMMAND, BL0942_REG_I_FAST_RMS_CTRL, 0x1C, 0x18, 0x00, 0x1B}};
29
+ static const uint32_t BL0942_REG_MODE_RESV = 0x03;
30
+ static const uint32_t BL0942_REG_MODE_CF_EN = 0x04;
31
+ static const uint32_t BL0942_REG_MODE_RMS_UPDATE_SEL = 0x08;
32
+ static const uint32_t BL0942_REG_MODE_FAST_RMS_SEL = 0x10;
33
+ static const uint32_t BL0942_REG_MODE_AC_FREQ_SEL = 0x20;
34
+ static const uint32_t BL0942_REG_MODE_CF_CNT_CLR_SEL = 0x40;
35
+ static const uint32_t BL0942_REG_MODE_CF_CNT_ADD_SEL = 0x80;
36
+ static const uint32_t BL0942_REG_MODE_UART_RATE_19200 = 0x200;
37
+ static const uint32_t BL0942_REG_MODE_UART_RATE_38400 = 0x300;
38
+ static const uint32_t BL0942_REG_MODE_DEFAULT =
39
+ BL0942_REG_MODE_RESV | BL0942_REG_MODE_CF_EN | BL0942_REG_MODE_CF_CNT_ADD_SEL;
40
+
41
+ static const uint32_t BL0942_REG_SOFT_RESET_MAGIC = 0x5a5a5a;
42
+ static const uint32_t BL0942_REG_USR_WRPROT_MAGIC = 0x55;
43
+
44
+ // 23-byte packet, 11 bits per byte, 2400 baud: about 105ms
45
+ static const uint32_t PKT_TIMEOUT_MS = 200;
33
46
 
34
47
  void BL0942::loop() {
35
48
  DataPacket buffer;
36
- if (!this->available()) {
49
+ int avail = this->available();
50
+
51
+ if (!avail) {
52
+ return;
53
+ }
54
+ if (avail < sizeof(buffer)) {
55
+ if (!this->rx_start_) {
56
+ this->rx_start_ = millis();
57
+ } else if (millis() > this->rx_start_ + PKT_TIMEOUT_MS) {
58
+ ESP_LOGW(TAG, "Junk on wire. Throwing away partial message (%d bytes)", avail);
59
+ this->read_array((uint8_t *) &buffer, avail);
60
+ this->rx_start_ = 0;
61
+ }
37
62
  return;
38
63
  }
39
- if (read_array((uint8_t *) &buffer, sizeof(buffer))) {
40
- if (validate_checksum(&buffer)) {
41
- received_package_(&buffer);
64
+
65
+ if (this->read_array((uint8_t *) &buffer, sizeof(buffer))) {
66
+ if (this->validate_checksum_(&buffer)) {
67
+ this->received_package_(&buffer);
42
68
  }
43
- } else {
44
- ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");
45
- while (read() >= 0)
46
- ;
47
69
  }
70
+ this->rx_start_ = 0;
48
71
  }
49
72
 
50
- bool BL0942::validate_checksum(DataPacket *data) {
51
- uint8_t checksum = BL0942_READ_COMMAND;
73
+ bool BL0942::validate_checksum_(DataPacket *data) {
74
+ uint8_t checksum = BL0942_READ_COMMAND | this->address_;
52
75
  // Whole package but checksum
53
76
  uint8_t *raw = (uint8_t *) data;
54
77
  for (uint32_t i = 0; i < sizeof(*data) - 1; i++) {
@@ -61,17 +84,73 @@ bool BL0942::validate_checksum(DataPacket *data) {
61
84
  return checksum == data->checksum;
62
85
  }
63
86
 
64
- void BL0942::update() {
87
+ void BL0942::write_reg_(uint8_t reg, uint32_t val) {
88
+ uint8_t pkt[6];
89
+
90
+ this->flush();
91
+ pkt[0] = BL0942_WRITE_COMMAND | this->address_;
92
+ pkt[1] = reg;
93
+ pkt[2] = (val & 0xff);
94
+ pkt[3] = (val >> 8) & 0xff;
95
+ pkt[4] = (val >> 16) & 0xff;
96
+ pkt[5] = (pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4]) ^ 0xff;
97
+ this->write_array(pkt, 6);
98
+ delay(1);
99
+ }
100
+
101
+ int BL0942::read_reg_(uint8_t reg) {
102
+ union {
103
+ uint8_t b[4];
104
+ uint32_le_t le32;
105
+ } resp;
106
+
107
+ this->write_byte(BL0942_READ_COMMAND | this->address_);
108
+ this->write_byte(reg);
65
109
  this->flush();
66
- this->write_byte(BL0942_READ_COMMAND);
110
+ if (this->read_array(resp.b, 4) &&
111
+ resp.b[3] ==
112
+ (uint8_t) ((BL0942_READ_COMMAND + this->address_ + reg + resp.b[0] + resp.b[1] + resp.b[2]) ^ 0xff)) {
113
+ resp.b[3] = 0;
114
+ return resp.le32;
115
+ }
116
+ return -1;
117
+ }
118
+
119
+ void BL0942::update() {
120
+ this->write_byte(BL0942_READ_COMMAND | this->address_);
67
121
  this->write_byte(BL0942_FULL_PACKET);
68
122
  }
69
123
 
70
124
  void BL0942::setup() {
71
- for (auto *i : BL0942_INIT) {
72
- this->write_array(i, 6);
73
- delay(1);
125
+ // If either current or voltage references are set explicitly by the user,
126
+ // calculate the power reference from it unless that is also explicitly set.
127
+ if ((this->current_reference_set_ || this->voltage_reference_set_) && !this->power_reference_set_) {
128
+ this->power_reference_ = (this->voltage_reference_ * this->current_reference_ * 3537.0 / 305978.0) / 73989.0;
129
+ this->power_reference_set_ = true;
130
+ }
131
+
132
+ // Similarly for energy reference, if the power reference was set by the user
133
+ // either implicitly or explicitly.
134
+ if (this->power_reference_set_ && !this->energy_reference_set_) {
135
+ this->energy_reference_ = this->power_reference_ * 3600000 / 419430.4;
136
+ this->energy_reference_set_ = true;
74
137
  }
138
+
139
+ this->write_reg_(BL0942_REG_USR_WRPROT, BL0942_REG_USR_WRPROT_MAGIC);
140
+ if (this->reset_)
141
+ this->write_reg_(BL0942_REG_SOFT_RESET, BL0942_REG_SOFT_RESET_MAGIC);
142
+
143
+ uint32_t mode = BL0942_REG_MODE_DEFAULT;
144
+ mode |= BL0942_REG_MODE_RMS_UPDATE_SEL; /* 800ms refresh time */
145
+ if (this->line_freq_ == LINE_FREQUENCY_60HZ)
146
+ mode |= BL0942_REG_MODE_AC_FREQ_SEL;
147
+ this->write_reg_(BL0942_REG_MODE, mode);
148
+
149
+ this->write_reg_(BL0942_REG_USR_WRPROT, 0);
150
+
151
+ if (this->read_reg_(BL0942_REG_MODE) != mode)
152
+ this->status_set_warning("BL0942 setup failed!");
153
+
75
154
  this->flush();
76
155
  }
77
156
 
@@ -82,10 +161,17 @@ void BL0942::received_package_(DataPacket *data) {
82
161
  return;
83
162
  }
84
163
 
164
+ // cf_cnt is only 24 bits, so track overflows
165
+ uint32_t cf_cnt = (uint24_t) data->cf_cnt;
166
+ cf_cnt |= this->prev_cf_cnt_ & 0xff000000;
167
+ if (cf_cnt < this->prev_cf_cnt_) {
168
+ cf_cnt += 0x1000000;
169
+ }
170
+ this->prev_cf_cnt_ = cf_cnt;
171
+
85
172
  float v_rms = (uint24_t) data->v_rms / voltage_reference_;
86
173
  float i_rms = (uint24_t) data->i_rms / current_reference_;
87
174
  float watt = (int24_t) data->watt / power_reference_;
88
- uint32_t cf_cnt = (uint24_t) data->cf_cnt;
89
175
  float total_energy_consumption = cf_cnt / energy_reference_;
90
176
  float frequency = 1000000.0f / data->frequency;
91
177
 
@@ -104,18 +190,25 @@ void BL0942::received_package_(DataPacket *data) {
104
190
  if (frequency_sensor_ != nullptr) {
105
191
  frequency_sensor_->publish_state(frequency);
106
192
  }
107
-
193
+ this->status_clear_warning();
108
194
  ESP_LOGV(TAG, "BL0942: U %fV, I %fA, P %fW, Cnt %" PRId32 ", ∫P %fkWh, frequency %fHz, status 0x%08X", v_rms, i_rms,
109
195
  watt, cf_cnt, total_energy_consumption, frequency, data->status);
110
196
  }
111
197
 
112
198
  void BL0942::dump_config() { // NOLINT(readability-function-cognitive-complexity)
113
199
  ESP_LOGCONFIG(TAG, "BL0942:");
200
+ ESP_LOGCONFIG(TAG, " Reset: %s", TRUEFALSE(this->reset_));
201
+ ESP_LOGCONFIG(TAG, " Address: %d", this->address_);
202
+ ESP_LOGCONFIG(TAG, " Nominal line frequency: %d Hz", this->line_freq_);
203
+ ESP_LOGCONFIG(TAG, " Current reference: %f", this->current_reference_);
204
+ ESP_LOGCONFIG(TAG, " Energy reference: %f", this->energy_reference_);
205
+ ESP_LOGCONFIG(TAG, " Power reference: %f", this->power_reference_);
206
+ ESP_LOGCONFIG(TAG, " Voltage reference: %f", this->voltage_reference_);
114
207
  LOG_SENSOR("", "Voltage", this->voltage_sensor_);
115
208
  LOG_SENSOR("", "Current", this->current_sensor_);
116
209
  LOG_SENSOR("", "Power", this->power_sensor_);
117
210
  LOG_SENSOR("", "Energy", this->energy_sensor_);
118
- LOG_SENSOR("", "frequency", this->frequency_sensor_);
211
+ LOG_SENSOR("", "Frequency", this->frequency_sensor_);
119
212
  }
120
213
 
121
214
  } // namespace bl0942
@@ -8,6 +8,57 @@
8
8
  namespace esphome {
9
9
  namespace bl0942 {
10
10
 
11
+ // The BL0942 IC is "calibration-free", which means that it doesn't care
12
+ // at all about calibration, and that's left to software. It measures a
13
+ // voltage differential on its IP/IN pins which linearly proportional to
14
+ // the current flow, and another on its VP pin which is proportional to
15
+ // the line voltage. It never knows the actual calibration; the values
16
+ // it reports are solely in terms of those inputs.
17
+ //
18
+ // The datasheet refers to the input voltages as I(A) and V(V), both
19
+ // in millivolts. It measures them against a reference voltage Vref,
20
+ // which is typically 1.218V (but that absolute value is meaningless
21
+ // without the actual calibration anyway).
22
+ //
23
+ // The reported I_RMS value is 305978 I(A)/Vref, and the reported V_RMS
24
+ // value is 73989 V(V)/Vref. So we can calibrate those by applying a
25
+ // simple meter with a resistive load.
26
+ //
27
+ // The chip also measures the phase difference between voltage and
28
+ // current, and uses it to calculate the power factor (cos φ). It
29
+ // reports the WATT value of 3537 * I_RMS * V_RMS * cos φ).
30
+ //
31
+ // It also integrates total energy based on the WATT value. The time for
32
+ // one CF_CNT pulse is 1638.4*256 / WATT.
33
+ //
34
+ // So... how do we calibrate that?
35
+ //
36
+ // Using a simple resistive load and an external meter, we can measure
37
+ // the true voltage and current for a given V_RMS and I_RMS reading,
38
+ // to calculate BL0942_UREF and BL0942_IREF. Those are in units of
39
+ // "305978 counts per amp" or "73989 counts per volt" respectively.
40
+ //
41
+ // We can derive BL0942_PREF from those. Let's eliminate the weird
42
+ // factors and express the calibration in plain counts per volt/amp:
43
+ // UREF1 = UREF/73989, IREF1 = IREF/305978.
44
+ //
45
+ // Next... the true power in Watts is V * I * cos φ, so that's equal
46
+ // to WATT/3537 * IREF1 * UREF1. Which means
47
+ // BL0942_PREF = BL0942_UREF * BL0942_IREF * 3537 / 305978 / 73989.
48
+ //
49
+ // Finally the accumulated energy. The period of a CF_CNT count is
50
+ // 1638.4*256 / WATT seconds, or 419230.4 / WATT seconds. Which means
51
+ // the energy represented by a CN_CNT pulse is 419230.4 WATT-seconds.
52
+ // Factoring in the calibration, that's 419230.4 / BL0942_PREF actual
53
+ // Watt-seconds (or Joules, as the physicists like to call them).
54
+ //
55
+ // But we're not being physicists today; we we're being engineers, so
56
+ // we want to convert to kWh instead. Which we do by dividing by 1000
57
+ // and then by 3600, so the energy in kWh is
58
+ // CF_CNT * 419230.4 / BL0942_PREF / 3600000
59
+ //
60
+ // Which makes BL0952_EREF = BL0942_PREF * 3600000 / 419430.4
61
+
11
62
  static const float BL0942_PREF = 596; // taken from tasmota
12
63
  static const float BL0942_UREF = 15873.35944299; // should be 73989/1.218
13
64
  static const float BL0942_IREF = 251213.46469622; // 305978/1.218
@@ -28,6 +79,11 @@ struct DataPacket {
28
79
  uint8_t checksum;
29
80
  } __attribute__((packed));
30
81
 
82
+ enum LineFrequency : uint8_t {
83
+ LINE_FREQUENCY_50HZ = 50,
84
+ LINE_FREQUENCY_60HZ = 60,
85
+ };
86
+
31
87
  class BL0942 : public PollingComponent, public uart::UARTDevice {
32
88
  public:
33
89
  void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
@@ -35,9 +91,27 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
35
91
  void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
36
92
  void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
37
93
  void set_frequency_sensor(sensor::Sensor *frequency_sensor) { frequency_sensor_ = frequency_sensor; }
94
+ void set_line_freq(LineFrequency freq) { this->line_freq_ = freq; }
95
+ void set_address(uint8_t address) { this->address_ = address; }
96
+ void set_reset(bool reset) { this->reset_ = reset; }
97
+ void set_current_reference(float current_ref) {
98
+ this->current_reference_ = current_ref;
99
+ this->current_reference_set_ = true;
100
+ }
101
+ void set_energy_reference(float energy_ref) {
102
+ this->energy_reference_ = energy_ref;
103
+ this->energy_reference_set_ = true;
104
+ }
105
+ void set_power_reference(float power_ref) {
106
+ this->power_reference_ = power_ref;
107
+ this->power_reference_set_ = true;
108
+ }
109
+ void set_voltage_reference(float voltage_ref) {
110
+ this->voltage_reference_ = voltage_ref;
111
+ this->voltage_reference_set_ = true;
112
+ }
38
113
 
39
114
  void loop() override;
40
-
41
115
  void update() override;
42
116
  void setup() override;
43
117
  void dump_config() override;
@@ -53,15 +127,25 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
53
127
 
54
128
  // Divide by this to turn into Watt
55
129
  float power_reference_ = BL0942_PREF;
130
+ bool power_reference_set_ = false;
56
131
  // Divide by this to turn into Volt
57
132
  float voltage_reference_ = BL0942_UREF;
133
+ bool voltage_reference_set_ = false;
58
134
  // Divide by this to turn into Ampere
59
135
  float current_reference_ = BL0942_IREF;
136
+ bool current_reference_set_ = false;
60
137
  // Divide by this to turn into kWh
61
138
  float energy_reference_ = BL0942_EREF;
139
+ bool energy_reference_set_ = false;
140
+ uint8_t address_ = 0;
141
+ bool reset_ = false;
142
+ LineFrequency line_freq_ = LINE_FREQUENCY_50HZ;
143
+ uint32_t rx_start_ = 0;
144
+ uint32_t prev_cf_cnt_ = 0;
62
145
 
63
- static bool validate_checksum(DataPacket *data);
64
-
146
+ bool validate_checksum_(DataPacket *data);
147
+ int read_reg_(uint8_t reg);
148
+ void write_reg_(uint8_t reg, uint32_t val);
65
149
  void received_package_(DataPacket *data);
66
150
  };
67
151
  } // namespace bl0942
@@ -1,32 +1,46 @@
1
1
  import esphome.codegen as cg
2
- import esphome.config_validation as cv
3
2
  from esphome.components import sensor, uart
3
+ import esphome.config_validation as cv
4
4
  from esphome.const import (
5
+ CONF_ADDRESS,
5
6
  CONF_CURRENT,
6
7
  CONF_ENERGY,
8
+ CONF_FREQUENCY,
7
9
  CONF_ID,
10
+ CONF_LINE_FREQUENCY,
8
11
  CONF_POWER,
9
12
  CONF_VOLTAGE,
10
- CONF_FREQUENCY,
11
13
  DEVICE_CLASS_CURRENT,
12
14
  DEVICE_CLASS_ENERGY,
15
+ DEVICE_CLASS_FREQUENCY,
13
16
  DEVICE_CLASS_POWER,
14
17
  DEVICE_CLASS_VOLTAGE,
15
- DEVICE_CLASS_FREQUENCY,
16
18
  STATE_CLASS_MEASUREMENT,
19
+ STATE_CLASS_TOTAL_INCREASING,
17
20
  UNIT_AMPERE,
21
+ UNIT_HERTZ,
18
22
  UNIT_KILOWATT_HOURS,
19
23
  UNIT_VOLT,
20
24
  UNIT_WATT,
21
- UNIT_HERTZ,
22
- STATE_CLASS_TOTAL_INCREASING,
23
25
  )
24
26
 
27
+ CONF_CURRENT_REFERENCE = "current_reference"
28
+ CONF_ENERGY_REFERENCE = "energy_reference"
29
+ CONF_POWER_REFERENCE = "power_reference"
30
+ CONF_RESET = "reset"
31
+ CONF_VOLTAGE_REFERENCE = "voltage_reference"
32
+
25
33
  DEPENDENCIES = ["uart"]
26
34
 
27
35
  bl0942_ns = cg.esphome_ns.namespace("bl0942")
28
36
  BL0942 = bl0942_ns.class_("BL0942", cg.PollingComponent, uart.UARTDevice)
29
37
 
38
+ LineFrequency = bl0942_ns.enum("LineFrequency")
39
+ LINE_FREQS = {
40
+ 50: LineFrequency.LINE_FREQUENCY_50HZ,
41
+ 60: LineFrequency.LINE_FREQUENCY_60HZ,
42
+ }
43
+
30
44
  CONFIG_SCHEMA = (
31
45
  cv.Schema(
32
46
  {
@@ -45,22 +59,35 @@ CONFIG_SCHEMA = (
45
59
  ),
46
60
  cv.Optional(CONF_POWER): sensor.sensor_schema(
47
61
  unit_of_measurement=UNIT_WATT,
48
- accuracy_decimals=0,
62
+ accuracy_decimals=1,
49
63
  device_class=DEVICE_CLASS_POWER,
50
64
  state_class=STATE_CLASS_MEASUREMENT,
51
65
  ),
52
66
  cv.Optional(CONF_ENERGY): sensor.sensor_schema(
53
67
  unit_of_measurement=UNIT_KILOWATT_HOURS,
54
- accuracy_decimals=0,
68
+ accuracy_decimals=3,
55
69
  device_class=DEVICE_CLASS_ENERGY,
56
70
  state_class=STATE_CLASS_TOTAL_INCREASING,
57
71
  ),
58
72
  cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(
59
73
  unit_of_measurement=UNIT_HERTZ,
60
- accuracy_decimals=0,
74
+ accuracy_decimals=2,
61
75
  device_class=DEVICE_CLASS_FREQUENCY,
62
76
  state_class=STATE_CLASS_MEASUREMENT,
63
77
  ),
78
+ cv.Optional(CONF_LINE_FREQUENCY, default="50HZ"): cv.All(
79
+ cv.frequency,
80
+ cv.enum(
81
+ LINE_FREQS,
82
+ int=True,
83
+ ),
84
+ ),
85
+ cv.Optional(CONF_ADDRESS, default=0): cv.int_range(min=0, max=3),
86
+ cv.Optional(CONF_RESET, default=True): cv.boolean,
87
+ cv.Optional(CONF_CURRENT_REFERENCE): cv.float_,
88
+ cv.Optional(CONF_ENERGY_REFERENCE): cv.float_,
89
+ cv.Optional(CONF_POWER_REFERENCE): cv.float_,
90
+ cv.Optional(CONF_VOLTAGE_REFERENCE): cv.float_,
64
91
  }
65
92
  )
66
93
  .extend(cv.polling_component_schema("60s"))
@@ -88,3 +115,14 @@ async def to_code(config):
88
115
  if frequency_config := config.get(CONF_FREQUENCY):
89
116
  sens = await sensor.new_sensor(frequency_config)
90
117
  cg.add(var.set_frequency_sensor(sens))
118
+ cg.add(var.set_line_freq(config[CONF_LINE_FREQUENCY]))
119
+ cg.add(var.set_address(config[CONF_ADDRESS]))
120
+ cg.add(var.set_reset(config[CONF_RESET]))
121
+ if (current_reference := config.get(CONF_CURRENT_REFERENCE, None)) is not None:
122
+ cg.add(var.set_current_reference(current_reference))
123
+ if (voltage_reference := config.get(CONF_VOLTAGE_REFERENCE, None)) is not None:
124
+ cg.add(var.set_voltage_reference(voltage_reference))
125
+ if (power_reference := config.get(CONF_POWER_REFERENCE, None)) is not None:
126
+ cg.add(var.set_power_reference(power_reference))
127
+ if (energy_reference := config.get(CONF_ENERGY_REFERENCE, None)) is not None:
128
+ cg.add(var.set_energy_reference(energy_reference))
@@ -65,9 +65,7 @@ CONF_ON_PASSKEY_NOTIFICATION = "on_passkey_notification"
65
65
  CONF_ON_NUMERIC_COMPARISON_REQUEST = "on_numeric_comparison_request"
66
66
  CONF_AUTO_CONNECT = "auto_connect"
67
67
 
68
- # Espressif platformio framework is built with MAX_BLE_CONN to 3, so
69
- # enforce this in yaml checks.
70
- MULTI_CONF = 3
68
+ MULTI_CONF = True
71
69
 
72
70
  CONFIG_SCHEMA = (
73
71
  cv.Schema(
@@ -41,7 +41,7 @@ CONFIG_SCHEMA = cv.All(
41
41
  cv.Optional(CONF_SERVICE_UUID): esp32_ble_tracker.bt_uuid,
42
42
  cv.Optional(CONF_IBEACON_MAJOR): cv.uint16_t,
43
43
  cv.Optional(CONF_IBEACON_MINOR): cv.uint16_t,
44
- cv.Optional(CONF_IBEACON_UUID): cv.uuid,
44
+ cv.Optional(CONF_IBEACON_UUID): esp32_ble_tracker.bt_uuid,
45
45
  cv.Optional(CONF_TIMEOUT, default="5min"): cv.positive_time_period,
46
46
  cv.Optional(CONF_MIN_RSSI): cv.All(
47
47
  cv.decibel, cv.int_range(min=-100, max=-30)
@@ -83,7 +83,7 @@ async def to_code(config):
83
83
  cg.add(var.set_service_uuid128(uuid128))
84
84
 
85
85
  if ibeacon_uuid := config.get(CONF_IBEACON_UUID):
86
- ibeacon_uuid = esp32_ble_tracker.as_hex_array(str(ibeacon_uuid))
86
+ ibeacon_uuid = esp32_ble_tracker.as_reversed_hex_array(ibeacon_uuid)
87
87
  cg.add(var.set_ibeacon_uuid(ibeacon_uuid))
88
88
 
89
89
  if (ibeacon_major := config.get(CONF_IBEACON_MAJOR)) is not None: