1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-03 00:21:56 +00:00

Compare commits

..

331 Commits

Author SHA1 Message Date
Jesse Hills
ec3618ecb8 Merge pull request #3304 from esphome/bump-2022.3.0
2022.3.0
2022-03-16 23:38:01 +13:00
Jesse Hills
792a24f38d Bump version to 2022.3.0 2022-03-16 22:32:24 +13:00
Jesse Hills
652e8a015b Merge branch 'beta' into bump-2022.3.0 2022-03-16 22:32:24 +13:00
Jesse Hills
59e6e798dd Merge pull request #3302 from esphome/bump-2022.3.0b2
2022.3.0b2
2022-03-16 15:38:32 +13:00
Jesse Hills
e5c2dbc7ec Bump version to 2022.3.0b2 2022-03-16 14:06:00 +13:00
Jesse Hills
756f71c382 Allow custom register type for modbus number (#3202) 2022-03-16 14:06:00 +13:00
Jesse Hills
b7535693fa Add helper overloads for hex print 16-bit (#3297) 2022-03-16 14:06:00 +13:00
stegm
06a3505698 Add optimistic config flag to modbus select. (#3267) 2022-03-16 14:06:00 +13:00
Jesse Hills
efa8f0730d Merge pull request #3278 from esphome/bump-2022.3.0b1
2022.3.0b1
2022-03-09 20:57:07 +13:00
Jesse Hills
023d26f521 Bump version to 2022.3.0b1 2022-03-09 20:07:50 +13:00
Jesse Hills
5068619f1b Merge branch 'dev' into bump-2022.3.0b1 2022-03-09 20:07:49 +13:00
wilberforce
5b2457af0b Add visual step/min/max for webserver climate (#3275) 2022-03-09 10:28:16 +13:00
Jesse Hills
900b4f1af9 Bump esphome-dashboard to 20220309.0 (#3277) 2022-03-09 10:27:54 +13:00
JasperPlant
4c22a98b0b Add entity_category_diagnostics to SGP30 baseline sensors (#3272) 2022-03-08 15:21:13 +13:00
wilberforce
3b8ca80900 Webserver v2 (#2688)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2022-03-08 15:02:24 +13:00
Jesse Hills
1ef6fd8fb0 Merge pull request #3261 from esphome/bump-2022.2.6
2022.2.6
2022-03-02 22:54:51 +13:00
Jesse Hills
942b0de7fd Bump version to 2022.2.6 2022-03-02 17:07:08 +13:00
Jesse Hills
859cca49d1 Only get free memory size from internal (#3259) 2022-03-02 17:07:08 +13:00
Jesse Hills
dc6eff83ea Only get free memory size from internal (#3259) 2022-03-02 16:44:35 +13:00
Jesse Hills
38ff66debd Remove stray define (#3260) 2022-03-02 16:32:45 +13:00
Sean Brogan
1d2e0f74ea Add Mopeka BLE and Mopeka Pro Check BLE Sensor (#2618)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2022-03-01 11:30:33 +13:00
Jesse Hills
8f7ff25624 Merge pull request #3252 from esphome/bump-2022.2.5
2022.2.5
2022-02-24 07:28:56 +13:00
Jesse Hills
97aca8e54c Bump version to 2022.2.5 2022-02-23 11:20:48 +13:00
Nicholas Peters
95acf19067 Fix regression caused by TSL2591 auto gain (#3249) 2022-02-23 11:20:48 +13:00
Martin Weinelt
3d0899aa58 Respect ESPHOME_USE_SUBPROCESS in esp32 post_build script (#3246) 2022-02-23 11:20:48 +13:00
Jesse Hills
bf60e40d0b Add optional display page for touchscreen binary sensors (#3247) 2022-02-23 11:05:53 +13:00
RubyBailey
c9094ca537 Add sensor support: Honeywell ABP (SPI version) (#3164)
Co-authored-by: RubyBailey <ruby_bailey11@hotmail.com>
2022-02-22 11:22:30 +01:00
Jesse Hills
68b3fd6b8f Store platform as uppercase (#3251) 2022-02-22 13:54:23 +13:00
Nicholas Peters
9323b3a248 Fix regression caused by TSL2591 auto gain (#3249) 2022-02-22 13:53:24 +13:00
Jesse Hills
b55e9329d9 Fix template button after abstract press_action (#3250) 2022-02-22 13:47:16 +13:00
Micha Nordmann
a5b4105971 support for waveshare 7.50in-hd-b (#3239) 2022-02-22 07:35:04 +13:00
Arturo Casal
d1feaa935d Add device support: MCP4728 (#3174)
* Added MCP4728 output component.

* Added tests to test1.yaml

* Added codeowners

* Lint fixes

* Implemented code review changes

* Lint fixes

* Added i2c communication check on setup()

* Fixed tests

* Lint fix

* Update esphome/components/mcp4728/mcp4728_output.cpp

Changed log function

Co-authored-by: Otto Winter <otto@otto-winter.com>

Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-21 12:47:03 +01:00
Martin Weinelt
6919930aaa Respect ESPHOME_USE_SUBPROCESS in esp32 post_build script (#3246) 2022-02-21 14:05:13 +13:00
EdJoPaTo
69633826bb Implement send_first_at for exponential_moving_average (#3240) 2022-02-21 13:13:06 +13:00
Niorix
771162bfb1 light: add RESTORE_AND_OFF/RESTORE_AND_ON LightRestoreMode (#3238) 2022-02-21 12:52:14 +13:00
Fabian Affolter
ba785e29e9 Add support for MPU-6886 (#3183) 2022-02-21 12:23:26 +13:00
Jesse Hills
138d6e505b Merge pull request #3245 from esphome/bump-2022.2.4
2022.2.4
2022-02-21 10:54:54 +13:00
Jesse Hills
2748e6ba29 Bump version to 2022.2.4 2022-02-21 10:17:25 +13:00
Jesse Hills
dbd4e927d8 Fix fatal erroring in addon startup script (#3244) 2022-02-21 10:17:24 +13:00
Jesse Hills
e73d47918f Fix lilygo touchscreen rotation (#3221) 2022-02-21 10:17:24 +13:00
Tyler Bules
b881bc071e ESP32-C3 deep sleep fix (#3066) 2022-02-21 10:17:24 +13:00
Otto Winter
1d0395d1c7 Improve ESP8266 iram usage (#3223) 2022-02-21 10:17:24 +13:00
Otto Winter
616c787e37 Fix ESP8266 climate memaccess warning (#3226) 2022-02-21 10:17:24 +13:00
Otto Winter
0c4de2bc97 Publish NAN when dallas conversion failed (#3227) 2022-02-21 10:17:24 +13:00
Jesse Hills
2c7b104f4a Fix fatal erroring in addon startup script (#3244) 2022-02-21 10:01:00 +13:00
Jesse Hills
78951c197a Fix lilygo touchscreen rotation (#3221) 2022-02-21 09:58:53 +13:00
cstaahl
07c1cf7137 Pulse meter internal filter mode (#3082)
Co-authored-by: Paul Daumlechner <paul.daumlechner@live.de>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-21 09:32:35 +13:00
Otto Winter
d26141151a Button code cleanup (#3242) 2022-02-21 09:17:51 +13:00
Otto Winter
f59dbe4a88 Add copy integration (#3241) 2022-02-21 09:13:37 +13:00
Otto Winter
8dae7f8225 Bump esphome-dashboard from 20220209.0 to 20220219.0 (#3231) 2022-02-19 15:57:52 +01:00
Otto Winter
5811389891 BH1750 dynamically calculate options (#3214)
* BH1750 dynamically calculate options

* Fix tests

* Fix NAN

* Convert setup to new-style

* Add myself as codeowner
2022-02-19 15:49:20 +01:00
Otto Winter
debcaf6fb7 Add ESP32C3 and ESP32S2 support to dashboard (#3152)
* Add ESP32C3 and ESP32S2 support to dashboard

* Format

* Fix tests
2022-02-19 15:47:50 +01:00
Tyler Bules
b8d10a62c2 ESP32-C3 deep sleep fix (#3066) 2022-02-19 15:13:48 +01:00
Otto Winter
d2b209234f Improve ESP8266 iram usage (#3223) 2022-02-19 15:09:17 +01:00
Otto Winter
34c9d8be50 Lint trailing whitespace (#3230) 2022-02-19 14:46:27 +01:00
Otto Winter
ae57ad0c81 Fix warning in test1.yaml (#3228) 2022-02-19 14:42:54 +01:00
Otto Winter
0c1520dd9c Fix ESP8266 climate memaccess warning (#3226) 2022-02-19 14:11:45 +01:00
Otto Winter
d594f43ebd Publish NAN when dallas conversion failed (#3227) 2022-02-19 14:11:01 +01:00
Oxan van Leeuwen
125c693e3f Add ESP32 variant config validator function (#3088)
* Add esp32_variant config validator function

* Drop unused is_esp32c3 function

Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-19 11:41:34 +01:00
mknjc
ad2f857e15 [miscale] Add flag to clear last impedance reading if the newly received reading only contains weight (#3132) 2022-02-19 10:59:53 +01:00
Peter Valkov
e445d6aada Fix for api disconnect detection. (#2909)
Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-19 10:36:19 +01:00
Arturo Casal
88fbb0ffbb Add sensor support: MAX44009 (#3125)
Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-19 09:49:45 +01:00
Borys Pierov
231908fe9f Implement text_sensor based on ble_client (#3079)
Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-19 09:45:32 +01:00
ImSorryButWho
f137cc10f4 Remote magiquest protocol (#2963)
Co-authored-by: Aaron Hertz <aaron@rockforest.org>
Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-18 22:22:41 +01:00
Jesse Hills
c2f5ac9eba Merge pull request #3220 from esphome/bump-2022.2.3
2022.2.3
2022-02-18 12:06:19 +13:00
Jesse Hills
5764c988af Bump version to 2022.2.3 2022-02-18 11:51:56 +13:00
dependabot[bot]
ccc2fbfd67 Bump platformio from 5.2.4 to 5.2.5 (#3188)
* Bump platformio from 5.2.4 to 5.2.5

Bumps [platformio](https://github.com/platformio/platformio) from 5.2.4 to 5.2.5.
- [Release notes](https://github.com/platformio/platformio/releases)
- [Changelog](https://github.com/platformio/platformio-core/blob/develop/HISTORY.rst)
- [Commits](https://github.com/platformio/platformio/commits)

---
updated-dependencies:
- dependency-name: platformio
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update requirements.txt

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Otto Winter <otto@otto-winter.com>
2022-02-18 11:51:56 +13:00
Jesse Hills
10b4adb8e6 Merge pull request #3219 from esphome/bump-2022.2.2
2022.2.2
2022-02-18 10:36:33 +13:00
Jesse Hills
83b7181bcb Bump version to 2022.2.2 2022-02-18 10:16:11 +13:00
Jesse Hills
8886b7e141 Add LONG LONG flag for arduinojson (#3212) 2022-02-18 10:16:11 +13:00
Otto Winter
7dcc4d030b Fix platformio docker version mismstch (#3215) 2022-02-18 10:16:11 +13:00
Stewart
b9398897c1 Set entity-category to diagnostic for debug component (#3209)
Co-authored-by: Stewart Morgan <stewart@arnos-vale.net>
Co-authored-by: root <root@build.servers.arnos-vale.net>
2022-02-18 10:16:11 +13:00
Jesse Hills
657b1c60ae Merge pull request #3208 from esphome/bump-2022.2.1
2022.2.1
2022-02-17 08:00:12 +13:00
Jesse Hills
dc54b17778 Bump version to 2022.2.1 2022-02-17 07:36:14 +13:00
Stewart
1fb214165b Fix missed ARDUINO_VERSION_CODE to USE_ARDUINO_VERSION_CODE changes (#3206)
Co-authored-by: Stewart Morgan <stewart@arnos-vale.net>
2022-02-17 07:36:14 +13:00
Jesse Hills
81b2fd78f5 Merge pull request #3204 from esphome/bump-2022.2.0
2022.2.0
2022-02-16 21:12:45 +13:00
Jesse Hills
69002fb1e6 Bump version to 2022.2.0 2022-02-16 20:13:14 +13:00
Jesse Hills
75332a752d Merge branch 'beta' into bump-2022.2.0 2022-02-16 20:13:13 +13:00
Jesse Hills
b528f48417 Merge pull request #3201 from esphome/bump-2022.2.0b3
2022.2.0b3
2022-02-16 11:10:31 +13:00
Jesse Hills
ec7a79049a Bump version to 2022.2.0b3 2022-02-16 09:45:05 +13:00
Jesse Hills
6ddad6b299 Update HA addon token (#3200) 2022-02-16 09:45:05 +13:00
Maurice Makaay
16dc7762f9 Fix strlcpy() uses to make long SSIDs and passwords work (#3199)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
2022-02-16 09:45:05 +13:00
Jesse Hills
dc0ed8857f Merge pull request #3198 from esphome/bump-2022.2.0b2
2022.2.0b2
2022-02-15 12:48:34 +13:00
Jesse Hills
bb6b77bd98 Bump version to 2022.2.0b2 2022-02-15 12:00:12 +13:00
Jesse Hills
dcc80f9032 Allow framework version validator to be maximum version (#3197) 2022-02-15 12:00:12 +13:00
Otto Winter
dd554bcdf4 Make generating combined binary output verbose (#3127) 2022-02-15 12:00:12 +13:00
Jesse Hills
f376a39e55 Clamp rotary_encoder restored value to min and max (#3184) 2022-02-15 12:00:12 +13:00
dependabot[bot]
8dcc9d6b66 Bump aioesphomeapi from 10.8.1 to 10.8.2 (#3182) 2022-02-15 12:00:11 +13:00
Jesse Hills
a576c9f21f Merge pull request #3180 from esphome/bump-2022.2.0b1
2022.2.0b1
2022-02-10 00:20:46 +13:00
Jesse Hills
71a438e2cb Bump version to 2022.2.0b1 2022-02-09 23:47:36 +13:00
Jesse Hills
272d6f2a8b Merge branch 'dev' into bump-2022.2.0b1 2022-02-09 23:47:36 +13:00
Jesse Hills
09ed1aed93 Merge pull request #3177 from esphome/bump-2022.1.4
2022.1.4
2022-02-09 12:42:47 +13:00
Jesse Hills
53d3718028 Bump version to 2022.1.4 2022-02-09 11:54:41 +13:00
Jesse Hills
2b5dce5232 Try fix canbus config validation (#3173) 2022-02-09 11:54:40 +13:00
Otto Winter
9ad84150aa Enable mDNS during OTA safe mode (#3146) 2022-02-09 11:54:40 +13:00
Jesse Hills
c0523590b4 Merge pull request #3154 from esphome/bump-2022.1.3
2022.1.3
2022-02-03 07:17:52 +13:00
Jesse Hills
c7f091ab10 Bump version to 2022.1.3 2022-02-02 22:16:24 +13:00
Jesse Hills
7479e0aada Fix backwards string case helpers (#3126) 2022-02-02 22:16:16 +13:00
Jesse Hills
5bbee1a1fe Merge pull request #3111 from esphome/bump-2022.1.2
2022.1.2
2022-01-25 09:36:20 +13:00
Jesse Hills
bdb9546ca3 Bump version to 2022.1.2 2022-01-25 09:11:20 +13:00
Plácido Revilla
46af4cad6e Set the wrapped single light in light partition to internal (#3092) 2022-01-25 09:11:19 +13:00
Martin
76a238912b [modbus_controller] fix incorrect start address for number write (#3073) 2022-01-25 09:11:19 +13:00
Jesse Hills
909a526967 Merge pull request #3075 from esphome/bump-2022.1.1
2022.1.1
2022-01-20 09:08:57 +13:00
Jesse Hills
cd6f4fb93f Bump version to 2022.1.1 2022-01-20 08:34:18 +13:00
Jesse Hills
c19458696e Add *.py.script files to distributions (#3074) 2022-01-20 08:34:18 +13:00
Jesse Hills
318b930e9f Merge pull request #3070 from esphome/bump-2022.1.0
2022.1.0
2022-01-19 19:43:54 +13:00
Jesse Hills
9296a078a7 Bump version to 2022.1.0 2022-01-19 16:08:27 +13:00
Jesse Hills
5dc776e55f Merge pull request #3068 from esphome/bump-2022.1.0b4
2022.1.0b4
2022-01-19 07:40:37 +13:00
Jesse Hills
72d60f30f7 Bump version to 2022.1.0b4 2022-01-18 15:49:31 +13:00
Oxan van Leeuwen
869743a742 Fail hard if no random bytes available for encryption (#3067) 2022-01-18 15:49:31 +13:00
Martin
7b03e07908 [modbus_controller] add missing skip_updates (#3063) 2022-01-18 15:49:31 +13:00
Paulus Schoutsen
348f880e15 bump dashboard to 20220116.0 (#3061) 2022-01-18 15:49:31 +13:00
Jesse Hills
ead597d0fb Merge pull request #3060 from esphome/bump-2022.1.0b3
2022.1.0b3
2022-01-17 13:13:40 +13:00
Jesse Hills
afbf989715 Bump version to 2022.1.0b3 2022-01-17 12:40:07 +13:00
Jesse Hills
01b62a16c3 Add number setting to web_server/rest_api (#3055) 2022-01-17 12:40:07 +13:00
Oxan van Leeuwen
c5eba04517 Remove deprecated attribute from virtual entity methods (#3056) 2022-01-17 12:40:07 +13:00
Oxan van Leeuwen
282313ab52 Rename post_build scripts to fix codeowners script (#3057) 2022-01-17 12:40:07 +13:00
Ohad Lutzky
d274545e77 Disable caching for binary download (#3054) 2022-01-17 12:40:07 +13:00
Jesse Hills
d3fda37615 Merge pull request #3042 from esphome/bump-2022.1.0b2
2022.1.0b2
2022-01-13 22:21:45 +13:00
Jesse Hills
cbe3092404 Bump version to 2022.1.0b2 2022-01-13 21:28:45 +13:00
Paulus Schoutsen
6dfe3039d0 Bump dashboard to 20220113.2 (#3041) 2022-01-13 21:28:45 +13:00
Paulus Schoutsen
d6009453df Add factory to download name (#3040) 2022-01-13 21:28:45 +13:00
Jesse Hills
c81323ef91 Merge pull request #3039 from esphome/bump-2022.1.0b1
2022.1.0b1
2022-01-13 12:12:07 +13:00
Jesse Hills
961c27f1c2 Bump version to 2022.1.0b1 2022-01-13 11:02:07 +13:00
Jesse Hills
fe4a14e6cc Merge branch 'dev' into bump-2022.1.0b1 2022-01-13 11:02:07 +13:00
Jesse Hills
50848c2f4d Merge pull request #2966 from esphome/bump-2021.12.3
2021.12.3
2021-12-30 14:54:49 +13:00
Jesse Hills
d32633b3c7 Update curl package version in docker (#2939) 2021-12-30 14:32:29 +13:00
Jesse Hills
b37739eec2 Bump version to 2021.12.3 2021-12-30 13:58:47 +13:00
Jesse Hills
28f87dc804 Remove -e for hassio images (#2964) 2021-12-30 13:58:47 +13:00
Jesse Hills
41879e41e6 Workaround installing as editable package not working (#2936) 2021-12-30 13:58:47 +13:00
Jesse Hills
fc0a6546a2 Only allow internal pins for dht sensor (#2940) 2021-12-30 13:58:47 +13:00
Jesse Hills
ffd4280d6c Require arduino in webserver for better validation (#2941) 2021-12-30 13:58:46 +13:00
Jesse Hills
db3b955b0f Merge pull request #2932 from esphome/bump-2021.12.2
2021.12.2
2021-12-21 12:45:27 +13:00
Jesse Hills
5516f65971 Bump version to 2021.12.2 2021-12-21 08:24:08 +13:00
Oxan van Leeuwen
9471df0a1b Fix MQTT button press action (#2917) 2021-12-21 08:24:07 +13:00
Oxan van Leeuwen
6d39f64be7 Don't disable idle task WDT when it's not enabled (#2856) 2021-12-21 08:24:07 +13:00
Jesse Hills
b89d0a9a73 Merge pull request #2915 from esphome/bump-2021.12.1
2021.12.1
2021-12-15 16:36:39 +13:00
Jesse Hills
4bb779d9a5 Bump version to 2021.12.1 2021-12-15 14:57:32 +13:00
wilberforce
386a5b6362 Allow button POST on press from web server (#2913) 2021-12-15 14:57:32 +13:00
Oxan van Leeuwen
e32a999cd0 Set text sensor state property to filter output (#2893) 2021-12-15 14:57:32 +13:00
Jesse Hills
bfbc6a4bad Merge pull request #2907 from esphome/bump-2021.12.0
2021.12.0
2021-12-12 07:59:37 +13:00
Jesse Hills
8c9e0e552d Bump version to 2021.12.0 2021-12-12 07:10:51 +13:00
Jesse Hills
8aaf9fd83f Merge pull request #2905 from esphome/bump-2021.12.0b6
2021.12.0b6
2021-12-11 21:54:49 +13:00
Jesse Hills
08057720b8 Bump version to 2021.12.0b6 2021-12-11 21:07:07 +13:00
Jesse Hills
bfaa648837 Bump esphome-dashboard to 20211211.0 (#2904) 2021-12-11 21:07:07 +13:00
Keith Burzinski
d504daef91 Fix for two points setting when fan_only_cooling is disabled (#2903)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Keith Burzinski <kburzinski@kbx-mbp2021.ad.kbx81.net>
2021-12-11 21:07:07 +13:00
Jesse Hills
b8d3ef2f49 Merge pull request #2899 from esphome/bump-2021.12.0b5
2021.12.0b5
2021-12-10 10:55:55 +13:00
Jesse Hills
3bf6320030 Bump version to 2021.12.0b5 2021-12-10 09:55:48 +13:00
Guillermo Ruffino
708b928c73 Modbus number/output use write single (#2896)
Co-authored-by: Martin <25747549+martgras@users.noreply.github.com>
2021-12-10 09:55:48 +13:00
Jesse Hills
649366ff44 Fix published state for modbus number (#2894) 2021-12-10 09:55:47 +13:00
Jesse Hills
e5c9e87fad Merge pull request #2890 from esphome/bump-2021.12.0b4
2021.12.0b4
2021-12-10 09:50:29 +13:00
Jesse Hills
f3d9d707b6 Bump version to 2021.12.0b4 2021-12-08 12:58:14 +13:00
Jesse Hills
090e10730c Bump esphome-dashboard to 20211208.0 (#2887) 2021-12-08 12:58:14 +13:00
Jesse Hills
fbc84861c7 Use new platform component config blocks for wizard (#2885) 2021-12-08 12:58:14 +13:00
Carlos Garcia Saura
e763469af8 Feed watchdog while setting up OTA (#2876) 2021-12-08 12:58:14 +13:00
Jesse Hills
3c0c514e44 Merge pull request #2880 from esphome/bump-2021.12.0b3
2021.12.0b3
2021-12-07 15:27:08 +13:00
Jesse Hills
ed5e2dd332 Bump version to 2021.12.0b3 2021-12-07 07:47:48 +13:00
Jesse Hills
09b7c6f550 Bump esphome-dashboard to 20211207.0 (#2877) 2021-12-07 07:47:48 +13:00
Oxan van Leeuwen
df315a1f51 Feed watchdog when no component loops (#2857) 2021-12-07 07:47:48 +13:00
Jesse Hills
7ee4bb621c Allow wizard to specify secrets (#2875) 2021-12-07 07:47:48 +13:00
Jesse Hills
24874f4c3c Adopt using wifi secrets that should exist at this point (#2874) 2021-12-07 07:47:48 +13:00
Jesse Hills
c128880033 Add endpoint to fetch secrets keys (#2873) 2021-12-07 07:47:48 +13:00
Massimiliano Ravelli
a66e94a0b0 Ignore already stopped dhcp for ethernet (#2862)
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2021-12-07 07:47:48 +13:00
Oxan van Leeuwen
56870ed4a8 Fix MCP23x17 not disabling pullup after config change (#2855) 2021-12-07 07:47:48 +13:00
Martin
3ac720df47 SPS30 : fix i2c read size (#2866) 2021-12-07 07:47:48 +13:00
Carlos Garcia Saura
1bc757ad06 ADC: Turn verbose the debugging "got voltage" (#2863) 2021-12-07 07:47:48 +13:00
Martin
f72abc6f3d tlc59208f : fix compilation error (#2867) 2021-12-07 07:47:48 +13:00
Jesse Hills
5ac88de985 Bump esphome-dashboard to 20211206.0 (#2870) 2021-12-07 07:47:48 +13:00
Jesse Hills
0826b367d6 Merge pull request #2853 from esphome/bump-2021.12.0b2
2021.12.0b2
2021-12-03 08:07:30 +13:00
Jesse Hills
329bf861d6 Bump version to 2021.12.0b2 2021-12-03 07:54:34 +13:00
Oxan van Leeuwen
9dcd3d18a0 Update ota_component.cpp (#2852) 2021-12-03 07:54:34 +13:00
Jesse Hills
db66cd88b6 Merge pull request #2851 from esphome/bump-2021.12.0b1
2021.12.0b1
2021-12-02 21:32:43 +13:00
Jesse Hills
86c205fe43 Remove blank line 2021-12-02 21:08:11 +13:00
Jesse Hills
c6414138c7 Bump version to 2021.12.0b1 2021-12-02 19:38:49 +13:00
Jesse Hills
36b355eb82 Merge branch 'dev' into bump-2021.12.0b1 2021-12-02 19:38:44 +13:00
Jesse Hills
7be9291b13 Merge pull request #2821 from esphome/bump-2021.11.4
2021.11.4
2021-11-29 13:23:47 +13:00
Jesse Hills
ea9e75039b Bump version to 2021.11.4 2021-11-29 10:18:49 +13:00
Conclusio
a5fb036011 Add delay to improve stability (#2793) 2021-11-29 10:18:48 +13:00
Dave T
e55506f9db Correct bitmask for third color (blue) scaling. (#2817) 2021-11-29 10:18:48 +13:00
Carlos Garcia Saura
50ec1d0445 Fix compilation error for WPA enterprise in ESP-IDF (#2815) 2021-11-29 10:18:48 +13:00
Oxan van Leeuwen
3d5e1d8d91 Fix parsing of multiple values in EZO sensor (#2814)
Co-authored-by: Lydia Sevelt <LydiaSevelt@gmail.com>
2021-11-29 10:18:48 +13:00
Oxan van Leeuwen
db2128a344 Fix parsing numbers in Anova (#2816) 2021-11-29 10:18:48 +13:00
Jesse Hills
21db43db06 Merge pull request #2808 from esphome/bump-2021.11.3
2021.11.3
2021-11-28 00:01:16 +13:00
Jesse Hills
5009b3029f Bump version to 2021.11.3 2021-11-27 21:13:01 +13:00
Maurice Makaay
57a029189c Add missing nvs_flash_init() to ESP32 preferences code (#2805)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
2021-11-27 21:13:01 +13:00
Jesse Hills
0cb715bb76 Merge pull request #2799 from esphome/bump-2021.11.2
2021.11.2
2021-11-26 09:25:37 +13:00
Jesse Hills
7d03823afd Bump version to 2021.11.2 2021-11-26 09:02:54 +13:00
Oxan van Leeuwen
8e1c9f5042 Fix parsing numbers from null-terminated buffers (#2755) 2021-11-26 09:02:54 +13:00
Samuel Sieb
980b7cda8f Remove floating point ops from the ISR (#2751)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
2021-11-26 09:02:53 +13:00
Kamil Trzciński
3a72dd5cb6 esp32_camera_web_server: Improve support for MotionEye (#2777) 2021-11-26 09:02:53 +13:00
Dave T
3178243811 Fix frame scaling for animated gifs (#2750) 2021-11-26 09:02:53 +13:00
Maurice Makaay
d30e2f2a4f Allow UART debug configuration with no after: definition (#2753) 2021-11-26 09:02:53 +13:00
Jesse Hills
6226dae05c Merge pull request #2744 from esphome/bump-2021.11.1
2021.11.1
2021-11-17 23:45:43 +13:00
Jesse Hills
9c6a475a6e Bump version to 2021.11.1 2021-11-17 23:31:38 +13:00
Franck Nijhof
8294d10d5b Re-instate device class update for binary sensors (#2743) 2021-11-17 23:31:38 +13:00
Evgeny
67558bec47 Fix HM3301 AQI index calculator (#2739) 2021-11-17 23:31:38 +13:00
Jesse Hills
84873d4074 Merge pull request #2742 from esphome/bump-2021.11.0
2021.11.0
2021-11-17 22:18:29 +13:00
Jesse Hills
58a0b28a39 Bump version to 2021.11.0 2021-11-17 21:58:30 +13:00
Jesse Hills
b37d3a66cc Merge pull request #2738 from esphome/bump-2021.11.0b9
2021.11.0b9
2021-11-17 10:27:41 +13:00
Jesse Hills
7e495a5e27 Bump version to 2021.11.0b9 2021-11-17 08:00:26 +13:00
rotarykite
c41547fd4a Fix senseair component uart read timeout (#2658)
Co-authored-by: DAVe3283 <DAVe3283+GitHub@gmail.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Chua Jun Chieh <junchieh.chua@softspace.com.my>
2021-11-17 08:00:26 +13:00
Ryan Hoffman
0d47d41c85 Use as_reversed_hex_array in ble_sensor to fix UUID parsing (#2737)
#1627 renamed as_hex_array to as_reversed_hex_array but forgot to rename these users.
2021-11-17 08:00:26 +13:00
Jesse Hills
41a3a17456 Merge pull request #2734 from esphome/bump-2021.11.0b8
2021.11.0b8
2021-11-16 13:50:10 +13:00
Jesse Hills
cbbafbcca2 Bump version to 2021.11.0b8 2021-11-16 12:53:56 +13:00
Jesse Hills
c75566b374 Fix zeroconf time comparisons (#2733)
Co-authored-by: J. Nick Koston <nick@koston.org>
2021-11-16 12:53:56 +13:00
Jesse Hills
7279f1fcc1 Merge pull request #2732 from esphome/bump-2021.11.0b7
2021.11.0b7
2021-11-16 12:19:07 +13:00
Jesse Hills
d7432f7c10 Bump version to 2021.11.0b7 2021-11-16 11:05:51 +13:00
Jesse Hills
b0a0a153f3 Improv serial/checksum changes (#2731)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-11-16 11:05:51 +13:00
Jesse Hills
024632dbd0 Merge pull request #2730 from esphome/bump-2021.11.0b6
2021.11.0b6
2021-11-16 10:53:11 +13:00
Jesse Hills
0a545a28b9 Bump version to 2021.11.0b6 2021-11-16 09:59:00 +13:00
Jesse Hills
0f2df59998 Add zeroconf as a direct dependency and lock the version (#2729) 2021-11-16 09:58:59 +13:00
Jesse Hills
29a7d32f77 Merge pull request #2725 from esphome/bump-2021.11.0b5
2021.11.0b5
2021-11-15 13:42:59 +13:00
Jesse Hills
687a7e9b2f Bump version to 2021.11.0b5 2021-11-15 12:02:18 +13:00
Alexandre-Jacques St-Jacques
09e8782318 Remove unnecessary duplicate touch_pad_filter_start (#2724) 2021-11-15 12:02:18 +13:00
Jesse Hills
f2aea02210 Merge pull request #2723 from esphome/bump-2021.11.0b4
2021.11.0b4
2021-11-15 11:42:59 +13:00
Jesse Hills
194f922312 Bump version to 2021.11.0b4 2021-11-15 11:03:40 +13:00
Jesse Hills
fea3c48098 Fix indentation of write_lambda for modbus_controller number (#2722) 2021-11-15 11:03:39 +13:00
Sergey V. DUDANOV
c2f57baec2 RemoteTransmitter fix. Bug from version 2021.10. Some changes. (#2706) 2021-11-15 11:03:39 +13:00
Oxan van Leeuwen
f4a140e126 Feed WDT between doing ESP32 touchpad measurements (#2720) 2021-11-15 11:03:39 +13:00
Oxan van Leeuwen
ab506b09fe Restore InterruptLock on wifi-less ESP8266 (#2712) 2021-11-15 11:03:39 +13:00
Krzysztof Białek
87e1cdeedb Allow setting custom command_topic for Select and Number components (#2714) 2021-11-15 11:03:39 +13:00
Jesse Hills
81a36146ef Bump ESPAsyncWebServer to 2.1.0 (#2686) 2021-11-15 11:03:39 +13:00
Jesse Hills
7fa4a68a27 Merge pull request #2704 from esphome/bump-2021.11.0b3
2021.11.0b3
2021-11-12 17:21:58 +13:00
Jesse Hills
f1c5e2ef81 Bump version to 2021.11.0b3 2021-11-12 16:12:31 +13:00
lcavalli
b526155cce Update device classes for binary sensors (#2703) 2021-11-12 16:12:31 +13:00
Jesse Hills
62c3f301e7 Only allow prometheus when using arduino (#2697) 2021-11-12 16:12:31 +13:00
Jesse Hills
38cb988809 Remove my.ha links from improv (#2695) 2021-11-12 16:12:31 +13:00
Jesse Hills
b976ac54c8 Merge pull request #2693 from esphome/bump-2021.11.0b2
2021.11.0b2
2021-11-11 12:52:35 +13:00
Jesse Hills
78026e766f Bump version to 2021.11.0b2 2021-11-11 12:25:41 +13:00
Oxan van Leeuwen
b4cd8d21a5 Enable addressable light power supply based on raw values (#2690) 2021-11-11 12:25:41 +13:00
Maurice Makaay
7552893311 Uart debugging support (#2478)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
Co-authored-by: Maurice Makaay <account-github@makaay.nl>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2021-11-11 12:25:41 +13:00
Carlos Garcia Saura
21c896d8f8 [remote_transmitter] accurate pulse timing for ESP8266 (#2476) 2021-11-11 12:25:40 +13:00
Jesse Hills
4b7fe202ec Fix template number initial value being NaN (#2692) 2021-11-11 12:25:40 +13:00
Jesse Hills
9f4519210f Merge pull request #2691 from esphome/bump-2021.11.0b1
2021.11.0b1
2021-11-11 11:05:45 +13:00
Jesse Hills
b0506afa5b Merge branch 'beta' into bump-2021.11.0b1 2021-11-11 10:48:23 +13:00
Jesse Hills
8cbb379898 Remove import (not sure how it got there) 2021-11-11 10:35:18 +13:00
Jesse Hills
b226215593 Bump version to 2021.11.0b1 2021-11-11 10:10:05 +13:00
Jesse Hills
19970729a9 Merge branch 'dev' into bump-2021.11.0b1 2021-11-11 10:10:04 +13:00
Jesse Hills
d2ebfd2833 Merge pull request #2634 from esphome/bump-2021.10.3
2021.10.3
2021-10-27 11:21:08 +13:00
Jesse Hills
bd782fc828 Bump version to 2021.10.3 2021-10-27 10:49:11 +13:00
Jesse Hills
23560e608c Fix select.set using lambda (#2633) 2021-10-27 10:49:10 +13:00
Jan Čermák
f1377b560e Fix pin number validation for sn74hc595 (#2621) 2021-10-27 10:49:10 +13:00
Martin
72108684ea fix modbus output (#2630) 2021-10-27 10:49:10 +13:00
Jesse Hills
c6adaaea97 Remove power and energy from sensors that are not true power (#2628) 2021-10-27 10:49:10 +13:00
Otto Winter
91999a38ca Fix glue code missing micros() (#2623) 2021-10-27 10:49:10 +13:00
0hax
b34eed125d Teleinfo ptec (#2599)
* teleinfo: handle historical mode correctly.

In historical mode, tags like PTEC leads to an issue where we detect a
timestamp wheras this is not possible in historical mode.

PTEC teleinfo tag looks like:
    PTEC HP..
Instead of the usual format
    IINST1 001 I

This make our data parsing fails.

While at here, make sure we continue parsing other tags even if parsing
one of the tag fails.

Signed-off-by: 0hax <0hax@protonmail.com>

* teleinfo: fix compilation with loglevel set to debug.

Signed-off-by: 0hax <0hax@protonmail.com>
2021-10-27 10:49:10 +13:00
Stefan Agner
2abe09529a Autodetect flash size (#2615) 2021-10-27 10:49:10 +13:00
Otto Winter
9aaaf4dd4b Bump platform-espressif8266 from 2.6.2 to 2.6.3 (#2620) 2021-10-27 10:49:09 +13:00
Andreas Hergert
cbfbcf7f1b fixed dependency for pca9685 component (#2614)
Co-authored-by: Otto Winter <otto@otto-winter.com>
Co-authored-by: Andreas <andreas.hergert@otrs.com>
2021-10-27 10:49:09 +13:00
Otto Winter
c7651dc40d Merge pull request #2613 from esphome/bump-2021.10.2
2021.10.2
2021-10-22 18:35:28 +02:00
Otto winter
eda1c471ad Bump version to 2021.10.2 2021-10-22 18:26:24 +02:00
Andreas Hergert
c7ef18fbc4 Bugfix tca9548a and idf refactor anh (#2612)
Co-authored-by: Andreas Hergert <andreas.hergert@otrs.com>
2021-10-22 18:26:23 +02:00
Otto Winter
901ec918b1 Fix ESP8266 OTA compression only starting framework v2.7.0 (#2610) 2021-10-22 18:26:23 +02:00
Otto Winter
6bdae55ee1 Fix compiler warnings and update platformio line filter (#2607) 2021-10-22 18:26:23 +02:00
Otto Winter
dfb96e4b7f Add owner to all libraries used (#2604) 2021-10-22 18:26:22 +02:00
Otto Winter
ff2c316b18 Re-raise keyboardinterrupt (#2603) 2021-10-22 18:26:22 +02:00
Otto Winter
5be52f71f9 Add OTA upload compression for ESP8266 (#2601) 2021-10-22 18:26:22 +02:00
Otto Winter
42873dd37c Bump noise-c from 0.1.3 to 0.1.4 (#2602) 2021-10-22 18:26:21 +02:00
Otto Winter
f93e7d4e3a Fix socket connection closed not detected (#2587) 2021-10-22 18:26:21 +02:00
Oxan van Leeuwen
bbcd523967 Fix validation of addressable light IDs (#2588) 2021-10-22 18:26:21 +02:00
dependabot[bot]
68cbe58d00 Bump esphome-dashboard from 20211021.0 to 20211021.1 (#2594)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-22 18:26:12 +02:00
Oxan van Leeuwen
115bca98f1 Fix old-style arduino_version on ESP8266 and with magic values (#2591) 2021-10-22 18:24:48 +02:00
Oxan van Leeuwen
ed0b34b2fe Fix pin/component switchup in SX1509 pin configuration (#2593) 2021-10-22 18:24:48 +02:00
Oxan van Leeuwen
ab34401421 Fix PlatformIO version for latest Arduino framework (#2590) 2021-10-22 18:24:48 +02:00
Otto Winter
eed0c18d65 Fix HeatpumpIR pin (#2585) 2021-10-22 18:24:47 +02:00
Otto Winter
e5a38ce748 Merge pull request #2580 from esphome/bump-2021.10.1
2021.10.1
2021-10-21 15:31:26 +02:00
Otto Winter
7d9d9fcf36 Fix platformio_install_deps no longer installing all lib_deps (#2584) 2021-10-21 15:29:53 +02:00
Otto Winter
f0aba6ceb2 Fix platformio version in Dockerfile doesn't match requirements (#2582) 2021-10-21 14:53:22 +02:00
Otto Winter
ab07ee57c6 Fix ESP8266 dallas GPIO16 INPUT_PULLUP (#2581) 2021-10-21 14:39:55 +02:00
Otto winter
eae3d72a4d Bump version to 2021.10.1 2021-10-21 14:23:08 +02:00
Otto Winter
7b8d826704 Fix ESP8266 OTA adds unnecessary Update library (#2579) 2021-10-21 14:23:07 +02:00
Otto Winter
e7baa42e63 Arduino global delay/millis/... symbols workaround (#2575) 2021-10-21 14:23:07 +02:00
Otto Winter
2f32833a22 Fix wifi ble coexistence check (#2573) 2021-10-21 14:23:07 +02:00
Otto Winter
f6935a4b4b Fix ESP8266 GPIO0 Pullup Validation (#2572) 2021-10-21 14:23:06 +02:00
Maurice Makaay
332c9e891b Fix MDNS for ESP8266 devices (#2571)
Co-authored-by: Maurice Makaay <account-github@makaay.nl>
Co-authored-by: Otto winter <otto@otto-winter.com>
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
2021-10-21 14:23:06 +02:00
Jesse Hills
b91ee4847f Merge pull request #2570 from esphome/bump-2021.10.0
2021.10.0
2021-10-21 08:37:26 +13:00
Jesse Hills
625463d871 Bump version to 2021.10.0 2021-10-21 07:57:10 +13:00
Jesse Hills
6433a01e07 Merge pull request #2567 from esphome/bump-2021.10.0b11
2021.10.0b11
2021-10-21 07:47:22 +13:00
Jesse Hills
56cc31e8e7 Bump version to 2021.10.0b11 2021-10-21 07:32:27 +13:00
Otto Winter
3af297aa76 Revert nextion clang-tidy changes (#2566) 2021-10-21 07:32:27 +13:00
Otto Winter
996ec59d28 Move running process log line to debug level (#2565) 2021-10-21 07:32:26 +13:00
Jesse Hills
95593eeeab Bump esphome-dashboard to 20211021.0 (#2564) 2021-10-21 07:32:20 +13:00
Jesse Hills
dad244fb7a A few esp32_ble_server/improv fixes (#2562) 2021-10-21 07:31:55 +13:00
Jesse Hills
adb5d27d95 Merge pull request #2561 from esphome/bump-2021.10.0b10
2021.10.0b10
2021-10-20 17:28:37 +13:00
Jesse Hills
8456a8cecb Bump version to 2021.10.0b10 2021-10-20 16:39:24 +13:00
Jesse Hills
b9f66373c1 Bump esphome-dashboard to 20211020.1 (#2559) 2021-10-20 16:39:16 +13:00
Jesse Hills
9ac365feef Fix HA addon so it does not have logout button (#2558) 2021-10-20 16:38:46 +13:00
Jesse Hills
43bbd58a44 Merge pull request #2557 from esphome/bump-2021.10.0b9
2021.10.0b9
2021-10-20 11:18:40 +13:00
Jesse Hills
7feffa64f3 Bump version to 2021.10.0b9 2021-10-20 11:00:02 +13:00
Jesse Hills
ea0977abb4 Bump dashboard to 20211020.0 (#2556) 2021-10-20 10:59:53 +13:00
Jesse Hills
4c83dc7c28 Merge pull request #2555 from esphome/bump-2021.10.0b8
2021.10.0b8
2021-10-20 10:30:59 +13:00
Jesse Hills
e10ab1da78 Bump version to 2021.10.0b8 2021-10-20 10:14:30 +13:00
Martin
1b0e60374b ignore exception when not waiting for a response (#2552) 2021-10-20 10:14:30 +13:00
Oxan van Leeuwen
3a760fbb44 Fix ADC pin validation on ESP32-C3 (#2551) 2021-10-20 10:14:30 +13:00
Jesse Hills
6ef57a2973 Merge pull request #2550 from esphome/bump-2021.10.0b7
2021.10.0b7
2021-10-19 16:22:29 +13:00
Jesse Hills
3e9c7f2e9f Bump version to 2021.10.0b7 2021-10-19 15:47:31 +13:00
Jesse Hills
430598b7a1 Bump dashboard to 20211019.0 (#2549) 2021-10-19 15:47:26 +13:00
Jesse Hills
91611b09b4 Merge pull request #2545 from esphome/bump-2021.10.0b6
2021.10.0b6
2021-10-18 21:41:22 +13:00
Jesse Hills
ecd115851f Bump version to 2021.10.0b6 2021-10-18 21:26:36 +13:00
Maurice Makaay
4a1e50fed1 OTA firmware MD5 check + password support for esp-idf (#2507)
Co-authored-by: Maurice Makaay <account-github@makaay.nl>
2021-10-18 21:26:36 +13:00
Jesse Hills
d6d037047b Merge pull request #2544 from esphome/bump-2021.10.0b5
2021.10.0b5
2021-10-18 16:37:43 +13:00
Jesse Hills
b5734c2b20 Bump version to 2021.10.0b5 2021-10-18 15:31:01 +13:00
Oxan van Leeuwen
723fb7eaac Autodetect ESP32 variant (#2530)
Co-authored-by: Otto winter <otto@otto-winter.com>
2021-10-18 15:31:01 +13:00
Jesse Hills
63a9acaa19 Fix Bluetooth setup_priorities (#2458)
Co-authored-by: Otto Winter <otto@otto-winter.com>
2021-10-18 15:31:00 +13:00
Jesse Hills
0524f8c677 Fix const used for IDF recommended version (#2542) 2021-10-18 15:31:00 +13:00
Otto Winter
70b62f272e Only show timestamp for dashboard access logs (#2540) 2021-10-18 15:31:00 +13:00
Jesse Hills
f0089b7940 Merge pull request #2539 from esphome/bump-2021.10.0b4
2021.10.0b4
2021-10-17 21:17:54 +13:00
Jesse Hills
4b44280d53 Bump version to 2021.10.0b4 2021-10-17 20:34:07 +13:00
Paulus Schoutsen
f045382d20 Bump dashboard to 20211015.0 (#2525)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2021-10-17 20:34:03 +13:00
Jesse Hills
db3fa1ade7 Allow downloading all bin files from backend in dashboard (#2514)
Co-authored-by: Otto Winter <otto@otto-winter.com>
2021-10-17 20:28:43 +13:00
Oxan van Leeuwen
f83950fd75 Fix bitshift on read in ADE7953 (#2537) 2021-10-17 20:28:43 +13:00
Oxan van Leeuwen
4dd1bf920d Replace framework version_hint with source option (#2529) 2021-10-17 20:28:43 +13:00
Martin
98755f3621 Fix bug in register name definition (#2526) 2021-10-17 20:28:43 +13:00
Keith Burzinski
c3a8a044b9 Fix Nextion HTTPClient error for ESP32 (#2524) 2021-10-17 20:28:42 +13:00
Martin
15b5ea43a7 Add pressure compensation during runtime (#2493)
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
2021-10-17 20:28:42 +13:00
Jesse Hills
ec683fc227 Merge pull request #2523 from esphome/bump-2021.10.0b3
2021.10.0b3
2021-10-15 10:15:26 +13:00
Jesse Hills
d4e65eb82a Bump version to 2021.10.0b3 2021-10-15 09:42:44 +13:00
Paul Monigatti
10c6601b0a Revert "Added test for bme680_bsec" (#2518)
This reverts commit 7f6a50d291 due to BSEC library license restrictions.
2021-10-15 09:42:44 +13:00
Oxan van Leeuwen
73940bc1bd Don't define UART_SELECTION_UART2 when UART2 is unavailable (#2512) 2021-10-15 09:42:43 +13:00
Paul Monigatti
9b7fb829f9 Fix: Color modes not being correctly used in light partitions (#2513) 2021-10-15 09:42:43 +13:00
Dmitriy Lopatko
c51d8c9021 add missing include in sgp30 (#2517) 2021-10-15 09:42:43 +13:00
Paul Monigatti
d8a6dfe5ce Fix BME680_BSEC compilation issue with ESP32 (#2516) 2021-10-15 09:42:43 +13:00
Oxan van Leeuwen
5f7cef0b06 Disallow using UART2 for logger on ESP-32 variants that lack it (#2510) 2021-10-15 09:42:43 +13:00
Paul Monigatti
48ff2ffc68 Fix: Light flash not restoring previous LightState (#2383)
* Update light state when transformer has finished

* Revert writing direct to output

* Correct handling of zero-length light transformers

* Allow transformers to handle zero-length transitions, and check more boundary conditions when transitioning back to start state

* Removed log.h

* Fixed race condition between LightFlashTransformer.apply() and is_finished()

* clang-format

* Step progress from 0.0f to 1.0f at t=start_time for zero-length transforms to avoid divide-by-zero
2021-10-15 09:42:43 +13:00
Oxan van Leeuwen
b3b9ccd314 Fix light state remaining on after turn off with transition (#2509) 2021-10-15 09:42:43 +13:00
Jesse Hills
e63c7b483b Merge pull request #2505 from esphome/bump-2021.10.0b2
2021.10.0b2
2021-10-13 22:45:29 +13:00
Jesse Hills
f57980b069 Bump version to 2021.10.0b2 2021-10-13 22:30:29 +13:00
Jesse Hills
7006aa0d2a Merge branch 'dev' into beta 2021-10-13 22:11:53 +13:00
Jesse Hills
8051c1ca99 Merge pull request #2504 from esphome/bump-2021.10.0b1
2021.10.0b1
2021-10-13 21:38:41 +13:00
Jesse Hills
a779592414 Bump version to 2021.10.0b1 2021-10-13 16:40:46 +13:00
Jesse Hills
112215848d Merge branch 'dev' into bump-2021.10.0b1 2021-10-13 16:40:46 +13:00
136 changed files with 4878 additions and 414 deletions

View File

@@ -9,4 +9,3 @@ contact_links:
- name: Frequently Asked Question
url: https://esphome.io/guides/faq.html
about: Please view the FAQ for common questions and what to include in a bug report.

View File

@@ -1,4 +1,4 @@
# What does this implement/fix?
# What does this implement/fix?
Quick description and explanation of changes
@@ -35,6 +35,6 @@ Quick description and explanation of changes
## Checklist:
- [ ] The code change is tested and works locally.
- [ ] Tests have been added to verify that the new code works (under `tests/` folder).
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated in [esphome-docs](https://github.com/esphome/esphome-docs).

View File

@@ -28,6 +28,7 @@ esphome/components/atc_mithermometer/* @ahpohl
esphome/components/b_parasite/* @rbaron
esphome/components/ballu/* @bazuchan
esphome/components/bang_bang/* @OttoWinter
esphome/components/bh1750/* @OttoWinter
esphome/components/binary_sensor/* @esphome/core
esphome/components/bl0940/* @tobias-
esphome/components/ble_client/* @buxtronix
@@ -43,6 +44,7 @@ esphome/components/climate/* @esphome/core
esphome/components/climate_ir/* @glmnet
esphome/components/color_temperature/* @jesserockz
esphome/components/coolix/* @glmnet
esphome/components/copy/* @OttoWinter
esphome/components/cover/* @esphome/core
esphome/components/cs5460a/* @balrog-kun
esphome/components/cse7761/* @berfenger
@@ -78,6 +80,7 @@ esphome/components/hbridge/light/* @DotNetDann
esphome/components/heatpumpir/* @rob-deutsch
esphome/components/hitachi_ac424/* @sourabhjaiswal
esphome/components/homeassistant/* @OttoWinter
esphome/components/honeywellabp/* @RubyBailey
esphome/components/hrxl_maxsonar_wr/* @netmikey
esphome/components/i2c/* @esphome/core
esphome/components/improv_serial/* @esphome/core
@@ -94,6 +97,7 @@ esphome/components/lilygo_t5_47/touchscreen/* @jesserockz
esphome/components/lock/* @esphome/core
esphome/components/logger/* @esphome/core
esphome/components/ltr390/* @sjtrny
esphome/components/max44009/* @berfenger
esphome/components/max7219digit/* @rspaargaren
esphome/components/max9611/* @mckaymatthew
esphome/components/mcp23008/* @jesserockz
@@ -105,6 +109,7 @@ esphome/components/mcp23x17_base/* @jesserockz
esphome/components/mcp23xxx_base/* @jesserockz
esphome/components/mcp2515/* @danielschramm @mvturnho
esphome/components/mcp3204/* @rsumner
esphome/components/mcp4728/* @berfenger
esphome/components/mcp47a1/* @jesserockz
esphome/components/mcp9808/* @k7hpn
esphome/components/md5/* @esphome/core
@@ -121,6 +126,9 @@ esphome/components/modbus_controller/select/* @martgras @stegm
esphome/components/modbus_controller/sensor/* @martgras
esphome/components/modbus_controller/switch/* @martgras
esphome/components/modbus_controller/text_sensor/* @martgras
esphome/components/mopeka_ble/* @spbrogan
esphome/components/mopeka_pro_check/* @spbrogan
esphome/components/mpu6886/* @fabaff
esphome/components/network/* @esphome/core
esphome/components/nextion/* @senexcrenshaw
esphome/components/nextion/binary_sensor/* @senexcrenshaw
@@ -141,7 +149,7 @@ esphome/components/pn532_spi/* @OttoWinter @jesserockz
esphome/components/power_supply/* @esphome/core
esphome/components/preferences/* @esphome/core
esphome/components/psram/* @esphome/core
esphome/components/pulse_meter/* @stevebaxter
esphome/components/pulse_meter/* @cstaahl @stevebaxter
esphome/components/pvvx_mithermometer/* @pasiz
esphome/components/qr_code/* @wjtje
esphome/components/radon_eye_ble/* @jeffeb3

View File

@@ -5,7 +5,7 @@ For a detailed guide, please see https://esphome.io/guides/contributing.html#con
Things to note when contributing:
- Please test your changes :)
- If a new feature is added or an existing user-facing feature is changed, you should also
- If a new feature is added or an existing user-facing feature is changed, you should also
update the [docs](https://github.com/esphome/esphome-docs). See [contributing to esphome-docs](https://esphome.io/guides/contributing.html#contributing-to-esphomedocs)
for more information.
- Please also update the tests in the `tests/` folder. You can do so by just adding a line in one of the YAML files

View File

@@ -7,12 +7,12 @@
# Check SSL requirements, if enabled
if bashio::config.true 'ssl'; then
if ! bashio::config.has_value 'certfile'; then
bashio::fatal 'SSL is enabled, but no certfile was specified.'
bashio::log.fatal 'SSL is enabled, but no certfile was specified.'
bashio::exit.nok
fi
if ! bashio::config.has_value 'keyfile'; then
bashio::fatal 'SSL is enabled, but no keyfile was specified'
bashio::log.fatal 'SSL is enabled, but no keyfile was specified'
bashio::exit.nok
fi

View File

@@ -76,6 +76,8 @@ async def to_code(config):
pos = 0
for frameIndex in range(frames):
image.seek(frameIndex)
if CONF_RESIZE in config:
image.thumbnail(config[CONF_RESIZE])
frame = image.convert("RGB")
if CONF_RESIZE in config:
frame = frame.resize([width, height])

View File

@@ -105,6 +105,7 @@ void APIConnection::loop() {
ESP_LOGW(TAG, "%s didn't respond to ping request in time. Disconnecting...", this->client_info_.c_str());
}
} else if (now - this->last_traffic_ > keepalive) {
ESP_LOGVV(TAG, "Sending keepalive PING...");
this->sent_ping_ = true;
this->send_ping_request(PingRequest());
}
@@ -908,7 +909,7 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type)
}
return false;
}
this->last_traffic_ = millis();
// Do not set last_traffic_ on send
return true;
}
void APIConnection::on_unauthenticated_access() {

View File

@@ -9,18 +9,109 @@ static const char *const TAG = "bh1750.sensor";
static const uint8_t BH1750_COMMAND_POWER_ON = 0b00000001;
static const uint8_t BH1750_COMMAND_MT_REG_HI = 0b01000000; // last 3 bits
static const uint8_t BH1750_COMMAND_MT_REG_LO = 0b01100000; // last 5 bits
static const uint8_t BH1750_COMMAND_ONE_TIME_L = 0b00100011;
static const uint8_t BH1750_COMMAND_ONE_TIME_H = 0b00100000;
static const uint8_t BH1750_COMMAND_ONE_TIME_H2 = 0b00100001;
/*
bh1750 properties:
L-resolution mode:
- resolution 4lx (@ mtreg=69)
- measurement time: typ=16ms, max=24ms, scaled by MTreg value divided by 69
- formula: counts / 1.2 * (69 / MTreg) lx
H-resolution mode:
- resolution 1lx (@ mtreg=69)
- measurement time: typ=120ms, max=180ms, scaled by MTreg value divided by 69
- formula: counts / 1.2 * (69 / MTreg) lx
H-resolution mode2:
- resolution 0.5lx (@ mtreg=69)
- measurement time: typ=120ms, max=180ms, scaled by MTreg value divided by 69
- formula: counts / 1.2 * (69 / MTreg) / 2 lx
MTreg:
- min=31, default=69, max=254
-> only reason to use l-resolution is faster, but offers no higher range
-> below ~7000lx, makes sense to use H-resolution2 @ MTreg=254
-> try to maximize MTreg to get lowest noise level
*/
void BH1750Sensor::setup() {
ESP_LOGCONFIG(TAG, "Setting up BH1750 '%s'...", this->name_.c_str());
if (!this->write_bytes(BH1750_COMMAND_POWER_ON, nullptr, 0)) {
uint8_t turn_on = BH1750_COMMAND_POWER_ON;
if (this->write(&turn_on, 1) != i2c::ERROR_OK) {
this->mark_failed();
return;
}
}
uint8_t mtreg_hi = (this->measurement_duration_ >> 5) & 0b111;
uint8_t mtreg_lo = (this->measurement_duration_ >> 0) & 0b11111;
this->write_bytes(BH1750_COMMAND_MT_REG_HI | mtreg_hi, nullptr, 0);
this->write_bytes(BH1750_COMMAND_MT_REG_LO | mtreg_lo, nullptr, 0);
void BH1750Sensor::read_lx_(BH1750Mode mode, uint8_t mtreg, const std::function<void(float)> &f) {
// turn on (after one-shot sensor automatically powers down)
uint8_t turn_on = BH1750_COMMAND_POWER_ON;
if (this->write(&turn_on, 1) != i2c::ERROR_OK) {
ESP_LOGW(TAG, "Turning on BH1750 failed");
f(NAN);
return;
}
if (active_mtreg_ != mtreg) {
// set mtreg
uint8_t mtreg_hi = BH1750_COMMAND_MT_REG_HI | ((mtreg >> 5) & 0b111);
uint8_t mtreg_lo = BH1750_COMMAND_MT_REG_LO | ((mtreg >> 0) & 0b11111);
if (this->write(&mtreg_hi, 1) != i2c::ERROR_OK || this->write(&mtreg_lo, 1) != i2c::ERROR_OK) {
ESP_LOGW(TAG, "Setting measurement time for BH1750 failed");
active_mtreg_ = 0;
f(NAN);
return;
}
active_mtreg_ = mtreg;
}
uint8_t cmd;
uint16_t meas_time;
switch (mode) {
case BH1750_MODE_L:
cmd = BH1750_COMMAND_ONE_TIME_L;
meas_time = 24 * mtreg / 69;
break;
case BH1750_MODE_H:
cmd = BH1750_COMMAND_ONE_TIME_H;
meas_time = 180 * mtreg / 69;
break;
case BH1750_MODE_H2:
cmd = BH1750_COMMAND_ONE_TIME_H2;
meas_time = 180 * mtreg / 69;
break;
default:
f(NAN);
return;
}
if (this->write(&cmd, 1) != i2c::ERROR_OK) {
ESP_LOGW(TAG, "Starting measurement for BH1750 failed");
f(NAN);
return;
}
// probably not needed, but adjust for rounding
meas_time++;
this->set_timeout("read", meas_time, [this, mode, mtreg, f]() {
uint16_t raw_value;
if (this->read(reinterpret_cast<uint8_t *>(&raw_value), 2) != i2c::ERROR_OK) {
ESP_LOGW(TAG, "Reading BH1750 data failed");
f(NAN);
return;
}
raw_value = i2c::i2ctohs(raw_value);
float lx = float(raw_value) / 1.2f;
lx *= 69.0f / mtreg;
if (mode == BH1750_MODE_H2)
lx /= 2.0f;
f(lx);
});
}
void BH1750Sensor::dump_config() {
@@ -30,64 +121,49 @@ void BH1750Sensor::dump_config() {
ESP_LOGE(TAG, "Communication with BH1750 failed!");
}
const char *resolution_s;
switch (this->resolution_) {
case BH1750_RESOLUTION_0P5_LX:
resolution_s = "0.5";
break;
case BH1750_RESOLUTION_1P0_LX:
resolution_s = "1";
break;
case BH1750_RESOLUTION_4P0_LX:
resolution_s = "4";
break;
default:
resolution_s = "Unknown";
break;
}
ESP_LOGCONFIG(TAG, " Resolution: %s", resolution_s);
LOG_UPDATE_INTERVAL(this);
}
void BH1750Sensor::update() {
if (!this->write_bytes(this->resolution_, nullptr, 0))
return;
// first do a quick measurement in L-mode with full range
// to find right range
this->read_lx_(BH1750_MODE_L, 31, [this](float val) {
if (std::isnan(val)) {
this->status_set_warning();
this->publish_state(NAN);
return;
}
uint32_t wait = 0;
// use max conversion times
switch (this->resolution_) {
case BH1750_RESOLUTION_0P5_LX:
case BH1750_RESOLUTION_1P0_LX:
wait = 180;
break;
case BH1750_RESOLUTION_4P0_LX:
wait = 24;
break;
}
BH1750Mode use_mode;
uint8_t use_mtreg;
if (val <= 7000) {
use_mode = BH1750_MODE_H2;
use_mtreg = 254;
} else {
use_mode = BH1750_MODE_H;
// lx = counts / 1.2 * (69 / mtreg)
// -> mtreg = counts / 1.2 * (69 / lx)
// calculate for counts=50000 (allow some range to not saturate, but maximize mtreg)
// -> mtreg = 50000*(10/12)*(69/lx)
int ideal_mtreg = 50000 * 10 * 69 / (12 * (int) val);
use_mtreg = std::min(254, std::max(31, ideal_mtreg));
}
ESP_LOGV(TAG, "L result: %f -> Calculated mode=%d, mtreg=%d", val, (int) use_mode, use_mtreg);
this->set_timeout("illuminance", wait, [this]() { this->read_data_(); });
this->read_lx_(use_mode, use_mtreg, [this](float val) {
if (std::isnan(val)) {
this->status_set_warning();
this->publish_state(NAN);
return;
}
ESP_LOGD(TAG, "'%s': Got illuminance=%.1flx", this->get_name().c_str(), val);
this->status_clear_warning();
this->publish_state(val);
});
});
}
float BH1750Sensor::get_setup_priority() const { return setup_priority::DATA; }
void BH1750Sensor::read_data_() {
uint16_t raw_value;
if (this->read(reinterpret_cast<uint8_t *>(&raw_value), 2) != i2c::ERROR_OK) {
this->status_set_warning();
return;
}
raw_value = i2c::i2ctohs(raw_value);
float lx = float(raw_value) / 1.2f;
lx *= 69.0f / this->measurement_duration_;
if (this->resolution_ == BH1750_RESOLUTION_0P5_LX) {
lx /= 2.0f;
}
ESP_LOGD(TAG, "'%s': Got illuminance=%.1flx", this->get_name().c_str(), lx);
this->publish_state(lx);
this->status_clear_warning();
}
void BH1750Sensor::set_resolution(BH1750Resolution resolution) { this->resolution_ = resolution; }
} // namespace bh1750
} // namespace esphome

View File

@@ -7,29 +7,15 @@
namespace esphome {
namespace bh1750 {
/// Enum listing all resolutions that can be used with the BH1750
enum BH1750Resolution {
BH1750_RESOLUTION_4P0_LX = 0b00100011, // one-time low resolution mode
BH1750_RESOLUTION_1P0_LX = 0b00100000, // one-time high resolution mode 1
BH1750_RESOLUTION_0P5_LX = 0b00100001, // one-time high resolution mode 2
enum BH1750Mode {
BH1750_MODE_L,
BH1750_MODE_H,
BH1750_MODE_H2,
};
/// This class implements support for the i2c-based BH1750 ambient light sensor.
class BH1750Sensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice {
public:
/** Set the resolution of this sensor.
*
* Possible values are:
*
* - `BH1750_RESOLUTION_4P0_LX`
* - `BH1750_RESOLUTION_1P0_LX`
* - `BH1750_RESOLUTION_0P5_LX` (default)
*
* @param resolution The new resolution of the sensor.
*/
void set_resolution(BH1750Resolution resolution);
void set_measurement_duration(uint8_t measurement_duration) { measurement_duration_ = measurement_duration; }
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
void setup() override;
@@ -38,10 +24,9 @@ class BH1750Sensor : public sensor::Sensor, public PollingComponent, public i2c:
float get_setup_priority() const override;
protected:
void read_data_();
void read_lx_(BH1750Mode mode, uint8_t mtreg, const std::function<void(float)> &f);
BH1750Resolution resolution_{BH1750_RESOLUTION_0P5_LX};
uint8_t measurement_duration_;
uint8_t active_mtreg_{0};
};
} // namespace bh1750

View File

@@ -2,28 +2,20 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor
from esphome.const import (
CONF_RESOLUTION,
DEVICE_CLASS_ILLUMINANCE,
STATE_CLASS_MEASUREMENT,
UNIT_LUX,
CONF_MEASUREMENT_DURATION,
)
DEPENDENCIES = ["i2c"]
CODEOWNERS = ["@OttoWinter"]
bh1750_ns = cg.esphome_ns.namespace("bh1750")
BH1750Resolution = bh1750_ns.enum("BH1750Resolution")
BH1750_RESOLUTIONS = {
4.0: BH1750Resolution.BH1750_RESOLUTION_4P0_LX,
1.0: BH1750Resolution.BH1750_RESOLUTION_1P0_LX,
0.5: BH1750Resolution.BH1750_RESOLUTION_0P5_LX,
}
BH1750Sensor = bh1750_ns.class_(
"BH1750Sensor", sensor.Sensor, cg.PollingComponent, i2c.I2CDevice
)
CONF_MEASUREMENT_TIME = "measurement_time"
CONFIG_SCHEMA = (
sensor.sensor_schema(
BH1750Sensor,
@@ -34,14 +26,11 @@ CONFIG_SCHEMA = (
)
.extend(
{
cv.Optional(CONF_RESOLUTION, default=0.5): cv.enum(
BH1750_RESOLUTIONS, float=True
cv.Optional("resolution"): cv.invalid(
"The 'resolution' option has been removed. The optimal value is now dynamically calculated."
),
cv.Optional(CONF_MEASUREMENT_DURATION, default=69): cv.int_range(
min=31, max=254
),
cv.Optional(CONF_MEASUREMENT_TIME): cv.invalid(
"The 'measurement_time' option has been replaced with 'measurement_duration' in 1.18.0"
cv.Optional("measurement_duration"): cv.invalid(
"The 'measurement_duration' option has been removed. The optimal value is now dynamically calculated."
),
}
)
@@ -54,6 +43,3 @@ async def to_code(config):
var = await sensor.new_sensor(config)
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
cg.add(var.set_resolution(config[CONF_RESOLUTION]))
cg.add(var.set_measurement_duration(config[CONF_MEASUREMENT_DURATION]))

View File

@@ -0,0 +1,121 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import text_sensor, ble_client, esp32_ble_tracker
from esphome.const import (
CONF_ID,
CONF_TRIGGER_ID,
CONF_SERVICE_UUID,
)
from esphome import automation
from .. import ble_client_ns
DEPENDENCIES = ["ble_client"]
CONF_CHARACTERISTIC_UUID = "characteristic_uuid"
CONF_DESCRIPTOR_UUID = "descriptor_uuid"
CONF_NOTIFY = "notify"
CONF_ON_NOTIFY = "on_notify"
adv_data_t = cg.std_vector.template(cg.uint8)
adv_data_t_const_ref = adv_data_t.operator("ref").operator("const")
BLETextSensor = ble_client_ns.class_(
"BLETextSensor",
text_sensor.TextSensor,
cg.PollingComponent,
ble_client.BLEClientNode,
)
BLETextSensorNotifyTrigger = ble_client_ns.class_(
"BLETextSensorNotifyTrigger", automation.Trigger.template(cg.std_string)
)
CONFIG_SCHEMA = cv.All(
text_sensor.TEXT_SENSOR_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(BLETextSensor),
cv.Required(CONF_SERVICE_UUID): esp32_ble_tracker.bt_uuid,
cv.Required(CONF_CHARACTERISTIC_UUID): esp32_ble_tracker.bt_uuid,
cv.Optional(CONF_DESCRIPTOR_UUID): esp32_ble_tracker.bt_uuid,
cv.Optional(CONF_NOTIFY, default=False): cv.boolean,
cv.Optional(CONF_ON_NOTIFY): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
BLETextSensorNotifyTrigger
),
}
),
}
)
.extend(cv.polling_component_schema("60s"))
.extend(ble_client.BLE_CLIENT_SCHEMA)
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
if len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
cg.add(
var.set_service_uuid16(esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID]))
)
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid32_format):
cg.add(
var.set_service_uuid32(esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID]))
)
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid128_format):
uuid128 = esp32_ble_tracker.as_reversed_hex_array(config[CONF_SERVICE_UUID])
cg.add(var.set_service_uuid128(uuid128))
if len(config[CONF_CHARACTERISTIC_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
cg.add(
var.set_char_uuid16(
esp32_ble_tracker.as_hex(config[CONF_CHARACTERISTIC_UUID])
)
)
elif len(config[CONF_CHARACTERISTIC_UUID]) == len(
esp32_ble_tracker.bt_uuid32_format
):
cg.add(
var.set_char_uuid32(
esp32_ble_tracker.as_hex(config[CONF_CHARACTERISTIC_UUID])
)
)
elif len(config[CONF_CHARACTERISTIC_UUID]) == len(
esp32_ble_tracker.bt_uuid128_format
):
uuid128 = esp32_ble_tracker.as_reversed_hex_array(
config[CONF_CHARACTERISTIC_UUID]
)
cg.add(var.set_char_uuid128(uuid128))
if CONF_DESCRIPTOR_UUID in config:
if len(config[CONF_DESCRIPTOR_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
cg.add(
var.set_descr_uuid16(
esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])
)
)
elif len(config[CONF_DESCRIPTOR_UUID]) == len(
esp32_ble_tracker.bt_uuid32_format
):
cg.add(
var.set_descr_uuid32(
esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])
)
)
elif len(config[CONF_DESCRIPTOR_UUID]) == len(
esp32_ble_tracker.bt_uuid128_format
):
uuid128 = esp32_ble_tracker.as_reversed_hex_array(
config[CONF_DESCRIPTOR_UUID]
)
cg.add(var.set_descr_uuid128(uuid128))
await cg.register_component(var, config)
await ble_client.register_ble_node(var, config)
cg.add(var.set_enable_notify(config[CONF_NOTIFY]))
await text_sensor.register_text_sensor(var, config)
for conf in config.get(CONF_ON_NOTIFY, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await ble_client.register_ble_node(trigger, config)
await automation.build_automation(trigger, [(cg.std_string, "x")], conf)

View File

@@ -0,0 +1,38 @@
#pragma once
#include "esphome/core/automation.h"
#include "esphome/components/ble_client/text_sensor/ble_text_sensor.h"
#ifdef USE_ESP32
namespace esphome {
namespace ble_client {
class BLETextSensorNotifyTrigger : public Trigger<std::string>, public BLETextSensor {
public:
explicit BLETextSensorNotifyTrigger(BLETextSensor *sensor) { sensor_ = sensor; }
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) override {
switch (event) {
case ESP_GATTC_SEARCH_CMPL_EVT: {
this->sensor_->node_state = espbt::ClientState::ESTABLISHED;
break;
}
case ESP_GATTC_NOTIFY_EVT: {
if (param->notify.conn_id != this->sensor_->parent()->conn_id || param->notify.handle != this->sensor_->handle)
break;
this->trigger(this->sensor_->parse_data(param->notify.value, param->notify.value_len));
}
default:
break;
}
}
protected:
BLETextSensor *sensor_;
};
} // namespace ble_client
} // namespace esphome
#endif

View File

@@ -0,0 +1,137 @@
#include "ble_text_sensor.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include "esphome/core/application.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
namespace esphome {
namespace ble_client {
static const char *const TAG = "ble_text_sensor";
static const std::string EMPTY = "";
uint32_t BLETextSensor::hash_base() { return 193967603UL; }
void BLETextSensor::loop() {}
void BLETextSensor::dump_config() {
LOG_TEXT_SENSOR("", "BLE Text Sensor", this);
ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent()->address_str().c_str());
ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_string().c_str());
ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_string().c_str());
ESP_LOGCONFIG(TAG, " Descriptor UUID : %s", this->descr_uuid_.to_string().c_str());
ESP_LOGCONFIG(TAG, " Notifications : %s", YESNO(this->notify_));
LOG_UPDATE_INTERVAL(this);
}
void BLETextSensor::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) {
switch (event) {
case ESP_GATTC_OPEN_EVT: {
if (param->open.status == ESP_GATT_OK) {
ESP_LOGI(TAG, "[%s] Connected successfully!", this->get_name().c_str());
break;
}
break;
}
case ESP_GATTC_DISCONNECT_EVT: {
ESP_LOGW(TAG, "[%s] Disconnected!", this->get_name().c_str());
this->status_set_warning();
this->publish_state(EMPTY);
break;
}
case ESP_GATTC_SEARCH_CMPL_EVT: {
this->handle = 0;
auto *chr = this->parent()->get_characteristic(this->service_uuid_, this->char_uuid_);
if (chr == nullptr) {
this->status_set_warning();
this->publish_state(EMPTY);
ESP_LOGW(TAG, "No sensor characteristic found at service %s char %s", this->service_uuid_.to_string().c_str(),
this->char_uuid_.to_string().c_str());
break;
}
this->handle = chr->handle;
if (this->descr_uuid_.get_uuid().len > 0) {
auto *descr = chr->get_descriptor(this->descr_uuid_);
if (descr == nullptr) {
this->status_set_warning();
this->publish_state(EMPTY);
ESP_LOGW(TAG, "No sensor descriptor found at service %s char %s descr %s",
this->service_uuid_.to_string().c_str(), this->char_uuid_.to_string().c_str(),
this->descr_uuid_.to_string().c_str());
break;
}
this->handle = descr->handle;
}
if (this->notify_) {
auto status =
esp_ble_gattc_register_for_notify(this->parent()->gattc_if, this->parent()->remote_bda, chr->handle);
if (status) {
ESP_LOGW(TAG, "esp_ble_gattc_register_for_notify failed, status=%d", status);
}
} else {
this->node_state = espbt::ClientState::ESTABLISHED;
}
break;
}
case ESP_GATTC_READ_CHAR_EVT: {
if (param->read.conn_id != this->parent()->conn_id)
break;
if (param->read.status != ESP_GATT_OK) {
ESP_LOGW(TAG, "Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
break;
}
if (param->read.handle == this->handle) {
this->status_clear_warning();
this->publish_state(this->parse_data(param->read.value, param->read.value_len));
}
break;
}
case ESP_GATTC_NOTIFY_EVT: {
if (param->notify.conn_id != this->parent()->conn_id || param->notify.handle != this->handle)
break;
ESP_LOGV(TAG, "[%s] ESP_GATTC_NOTIFY_EVT: handle=0x%x, value=0x%x", this->get_name().c_str(),
param->notify.handle, param->notify.value[0]);
this->publish_state(this->parse_data(param->notify.value, param->notify.value_len));
break;
}
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
this->node_state = espbt::ClientState::ESTABLISHED;
break;
}
default:
break;
}
}
std::string BLETextSensor::parse_data(uint8_t *value, uint16_t value_len) {
std::string text(value, value + value_len);
return text;
}
void BLETextSensor::update() {
if (this->node_state != espbt::ClientState::ESTABLISHED) {
ESP_LOGW(TAG, "[%s] Cannot poll, not connected", this->get_name().c_str());
return;
}
if (this->handle == 0) {
ESP_LOGW(TAG, "[%s] Cannot poll, no service or characteristic found", this->get_name().c_str());
return;
}
auto status =
esp_ble_gattc_read_char(this->parent()->gattc_if, this->parent()->conn_id, this->handle, ESP_GATT_AUTH_REQ_NONE);
if (status) {
this->status_set_warning();
this->publish_state(EMPTY);
ESP_LOGW(TAG, "[%s] Error sending read request for sensor, status=%d", this->get_name().c_str(), status);
}
}
} // namespace ble_client
} // namespace esphome
#endif

View File

@@ -0,0 +1,47 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/ble_client/ble_client.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include "esphome/components/text_sensor/text_sensor.h"
#ifdef USE_ESP32
#include <esp_gattc_api.h>
namespace esphome {
namespace ble_client {
namespace espbt = esphome::esp32_ble_tracker;
class BLETextSensor : public text_sensor::TextSensor, public PollingComponent, public BLEClientNode {
public:
void loop() override;
void update() override;
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
void set_service_uuid16(uint16_t uuid) { this->service_uuid_ = espbt::ESPBTUUID::from_uint16(uuid); }
void set_service_uuid32(uint32_t uuid) { this->service_uuid_ = espbt::ESPBTUUID::from_uint32(uuid); }
void set_service_uuid128(uint8_t *uuid) { this->service_uuid_ = espbt::ESPBTUUID::from_raw(uuid); }
void set_char_uuid16(uint16_t uuid) { this->char_uuid_ = espbt::ESPBTUUID::from_uint16(uuid); }
void set_char_uuid32(uint32_t uuid) { this->char_uuid_ = espbt::ESPBTUUID::from_uint32(uuid); }
void set_char_uuid128(uint8_t *uuid) { this->char_uuid_ = espbt::ESPBTUUID::from_raw(uuid); }
void set_descr_uuid16(uint16_t uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_uint16(uuid); }
void set_descr_uuid32(uint32_t uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_uint32(uuid); }
void set_descr_uuid128(uint8_t *uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_raw(uuid); }
void set_enable_notify(bool notify) { this->notify_ = notify; }
std::string parse_data(uint8_t *value, uint16_t value_len);
uint16_t handle;
protected:
uint32_t hash_base() override;
bool notify_;
espbt::ESPBTUUID service_uuid_;
espbt::ESPBTUUID char_uuid_;
espbt::ESPBTUUID descr_uuid_;
};
} // namespace ble_client
} // namespace esphome
#endif

View File

@@ -18,11 +18,7 @@ void Button::add_on_press_callback(std::function<void()> &&callback) { this->pre
uint32_t Button::hash_base() { return 1495763804UL; }
void Button::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
std::string Button::get_device_class() {
if (this->device_class_.has_value())
return *this->device_class_;
return "";
}
std::string Button::get_device_class() { return this->device_class_; }
} // namespace button
} // namespace esphome

View File

@@ -45,12 +45,12 @@ class Button : public EntityBase {
protected:
/** You should implement this virtual method if you want to create your own button.
*/
virtual void press_action(){};
virtual void press_action() = 0;
uint32_t hash_base() override;
CallbackManager<void()> press_callback_{};
optional<std::string> device_class_{};
std::string device_class_{};
};
} // namespace button

View File

@@ -1,4 +1,5 @@
#include "climate.h"
#include "esphome/core/macros.h"
namespace esphome {
namespace climate {
@@ -326,14 +327,17 @@ optional<ClimateDeviceRestoreState> Climate::restore_state_() {
return recovered;
}
void Climate::save_state_() {
#if defined(USE_ESP_IDF) && !defined(CLANG_TIDY)
#if (defined(USE_ESP_IDF) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
!defined(CLANG_TIDY)
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#define TEMP_IGNORE_MEMACCESS
#endif
ClimateDeviceRestoreState state{};
// initialize as zero to prevent random data on stack triggering erase
memset(&state, 0, sizeof(ClimateDeviceRestoreState));
#if USE_ESP_IDF && !defined(CLANG_TIDY)
#ifdef TEMP_IGNORE_MEMACCESS
#pragma GCC diagnostic pop
#undef TEMP_IGNORE_MEMACCESS
#endif
state.mode = this->mode;

View File

@@ -141,7 +141,7 @@ class ClimateTraits {
}
bool supports_swing_mode(ClimateSwingMode swing_mode) const { return supported_swing_modes_.count(swing_mode); }
bool get_supports_swing_modes() const { return !supported_swing_modes_.empty(); }
std::set<ClimateSwingMode> get_supported_swing_modes() { return supported_swing_modes_; }
std::set<ClimateSwingMode> get_supported_swing_modes() const { return supported_swing_modes_; }
float get_visual_min_temperature() const { return visual_min_temperature_; }
void set_visual_min_temperature(float visual_min_temperature) { visual_min_temperature_ = visual_min_temperature; }

View File

@@ -0,0 +1,5 @@
import esphome.codegen as cg
CODEOWNERS = ["@OttoWinter"]
copy_ns = cg.esphome_ns.namespace("copy")

View File

@@ -0,0 +1,41 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor
from esphome.const import (
CONF_DEVICE_CLASS,
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopyBinarySensor = copy_ns.class_(
"CopyBinarySensor", binary_sensor.BinarySensor, cg.Component
)
CONFIG_SCHEMA = (
binary_sensor.binary_sensor_schema(CopyBinarySensor)
.extend(
{
cv.Required(CONF_SOURCE_ID): cv.use_id(binary_sensor.BinarySensor),
}
)
.extend(cv.COMPONENT_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
inherit_property_from(CONF_DEVICE_CLASS, CONF_SOURCE_ID),
)
async def to_code(config):
var = await binary_sensor.new_binary_sensor(config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,18 @@
#include "copy_binary_sensor.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.binary_sensor";
void CopyBinarySensor::setup() {
source_->add_on_state_callback([this](bool value) { this->publish_state(value); });
if (source_->has_state())
this->publish_state(source_->state);
}
void CopyBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Copy Binary Sensor", this); }
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,21 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
namespace esphome {
namespace copy {
class CopyBinarySensor : public binary_sensor::BinarySensor, public Component {
public:
void set_source(binary_sensor::BinarySensor *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
binary_sensor::BinarySensor *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,42 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import button
from esphome.const import (
CONF_DEVICE_CLASS,
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_ID,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopyButton = copy_ns.class_("CopyButton", button.Button, cg.Component)
CONFIG_SCHEMA = (
button.button_schema()
.extend(
{
cv.GenerateID(): cv.declare_id(CopyButton),
cv.Required(CONF_SOURCE_ID): cv.use_id(button.Button),
}
)
.extend(cv.COMPONENT_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
inherit_property_from(CONF_DEVICE_CLASS, CONF_SOURCE_ID),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await button.register_button(var, config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,14 @@
#include "copy_button.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.button";
void CopyButton::dump_config() { LOG_BUTTON("", "Copy Button", this); }
void CopyButton::press_action() { source_->press(); }
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,22 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/button/button.h"
namespace esphome {
namespace copy {
class CopyButton : public button::Button, public Component {
public:
void set_source(button::Button *source) { source_ = source; }
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
void press_action() override;
button::Button *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,38 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import cover
from esphome.const import (
CONF_DEVICE_CLASS,
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_ID,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopyCover = copy_ns.class_("CopyCover", cover.Cover, cg.Component)
CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(CopyCover),
cv.Required(CONF_SOURCE_ID): cv.use_id(cover.Cover),
}
).extend(cv.COMPONENT_SCHEMA)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
inherit_property_from(CONF_DEVICE_CLASS, CONF_SOURCE_ID),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cover.register_cover(var, config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,50 @@
#include "copy_cover.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.cover";
void CopyCover::setup() {
source_->add_on_state_callback([this]() {
this->current_operation = this->source_->current_operation;
this->position = this->source_->position;
this->tilt = this->source_->tilt;
this->publish_state();
});
this->current_operation = this->source_->current_operation;
this->position = this->source_->position;
this->tilt = this->source_->tilt;
this->publish_state();
}
void CopyCover::dump_config() { LOG_COVER("", "Copy Cover", this); }
cover::CoverTraits CopyCover::get_traits() {
auto base = source_->get_traits();
cover::CoverTraits traits{};
// copy traits manually so it doesn't break when new options are added
// but the control() method hasn't implemented them yet.
traits.set_is_assumed_state(base.get_is_assumed_state());
traits.set_supports_position(base.get_supports_position());
traits.set_supports_tilt(base.get_supports_tilt());
traits.set_supports_toggle(base.get_supports_toggle());
return traits;
}
void CopyCover::control(const cover::CoverCall &call) {
auto call2 = source_->make_call();
call2.set_stop(call.get_stop());
if (call.get_tilt().has_value())
call2.set_tilt(*call.get_tilt());
if (call.get_position().has_value())
call2.set_position(*call.get_position());
if (call.get_tilt().has_value())
call2.set_tilt(*call.get_tilt());
call2.perform();
}
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,25 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/cover/cover.h"
namespace esphome {
namespace copy {
class CopyCover : public cover::Cover, public Component {
public:
void set_source(cover::Cover *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
cover::CoverTraits get_traits() override;
protected:
void control(const cover::CoverCall &call) override;
cover::Cover *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,36 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import fan
from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_ID,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopyFan = copy_ns.class_("CopyFan", fan.Fan, cg.Component)
CONFIG_SCHEMA = fan.FAN_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(CopyFan),
cv.Required(CONF_SOURCE_ID): cv.use_id(fan.Fan),
}
).extend(cv.COMPONENT_SCHEMA)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await fan.register_fan(var, config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,53 @@
#include "copy_fan.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.fan";
void CopyFan::setup() {
source_->add_on_state_callback([this]() {
this->state = source_->state;
this->oscillating = source_->oscillating;
this->speed = source_->speed;
this->direction = source_->direction;
this->publish_state();
});
this->state = source_->state;
this->oscillating = source_->oscillating;
this->speed = source_->speed;
this->direction = source_->direction;
this->publish_state();
}
void CopyFan::dump_config() { LOG_FAN("", "Copy Fan", this); }
fan::FanTraits CopyFan::get_traits() {
fan::FanTraits traits;
auto base = source_->get_traits();
// copy traits manually so it doesn't break when new options are added
// but the control() method hasn't implemented them yet.
traits.set_oscillation(base.supports_oscillation());
traits.set_speed(base.supports_speed());
traits.set_supported_speed_count(base.supported_speed_count());
traits.set_direction(base.supports_direction());
return traits;
}
void CopyFan::control(const fan::FanCall &call) {
auto call2 = source_->make_call();
if (call.get_state().has_value())
call2.set_state(*call.get_state());
if (call.get_oscillating().has_value())
call2.set_oscillating(*call.get_oscillating());
if (call.get_speed().has_value())
call2.set_speed(*call.get_speed());
if (call.get_direction().has_value())
call2.set_direction(*call.get_direction());
call2.perform();
}
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,26 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/fan/fan.h"
namespace esphome {
namespace copy {
class CopyFan : public fan::Fan, public Component {
public:
void set_source(fan::Fan *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
fan::FanTraits get_traits() override;
protected:
void control(const fan::FanCall &call) override;
;
fan::Fan *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,36 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import lock
from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_ID,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopyLock = copy_ns.class_("CopyLock", lock.Lock, cg.Component)
CONFIG_SCHEMA = lock.LOCK_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(CopyLock),
cv.Required(CONF_SOURCE_ID): cv.use_id(lock.Lock),
}
).extend(cv.COMPONENT_SCHEMA)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await lock.register_lock(var, config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,29 @@
#include "copy_lock.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.lock";
void CopyLock::setup() {
source_->add_on_state_callback([this]() { this->publish_state(source_->state); });
traits.set_assumed_state(source_->traits.get_assumed_state());
traits.set_requires_code(source_->traits.get_requires_code());
traits.set_supported_states(source_->traits.get_supported_states());
traits.set_supports_open(source_->traits.get_supports_open());
this->publish_state(source_->state);
}
void CopyLock::dump_config() { LOG_LOCK("", "Copy Lock", this); }
void CopyLock::control(const lock::LockCall &call) {
auto call2 = source_->make_call();
call2.set_state(call.get_state());
call2.perform();
}
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,23 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/lock/lock.h"
namespace esphome {
namespace copy {
class CopyLock : public lock::Lock, public Component {
public:
void set_source(lock::Lock *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
void control(const lock::LockCall &call) override;
lock::Lock *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,38 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import number
from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_MODE,
CONF_SOURCE_ID,
CONF_UNIT_OF_MEASUREMENT,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopyNumber = copy_ns.class_("CopyNumber", number.Number, cg.Component)
CONFIG_SCHEMA = number.NUMBER_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(CopyNumber),
cv.Required(CONF_SOURCE_ID): cv.use_id(number.Number),
}
).extend(cv.COMPONENT_SCHEMA)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
inherit_property_from(CONF_UNIT_OF_MEASUREMENT, CONF_SOURCE_ID),
inherit_property_from(CONF_MODE, CONF_SOURCE_ID),
)
async def to_code(config):
var = await number.new_number(config, min_value=0, max_value=0, step=0)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,29 @@
#include "copy_number.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.number";
void CopyNumber::setup() {
source_->add_on_state_callback([this](float value) { this->publish_state(value); });
traits.set_min_value(source_->traits.get_min_value());
traits.set_max_value(source_->traits.get_max_value());
traits.set_step(source_->traits.get_step());
if (source_->has_state())
this->publish_state(source_->state);
}
void CopyNumber::dump_config() { LOG_NUMBER("", "Copy Number", this); }
void CopyNumber::control(float value) {
auto call2 = source_->make_call();
call2.set_value(value);
call2.perform();
}
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,23 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/number/number.h"
namespace esphome {
namespace copy {
class CopyNumber : public number::Number, public Component {
public:
void set_source(number::Number *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
void control(float value) override;
number::Number *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,36 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import select
from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_ID,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopySelect = copy_ns.class_("CopySelect", select.Select, cg.Component)
CONFIG_SCHEMA = select.SELECT_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(CopySelect),
cv.Required(CONF_SOURCE_ID): cv.use_id(select.Select),
}
).extend(cv.COMPONENT_SCHEMA)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await select.register_select(var, config, options=[])
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,27 @@
#include "copy_select.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.select";
void CopySelect::setup() {
source_->add_on_state_callback([this](const std::string &value) { this->publish_state(value); });
traits.set_options(source_->traits.get_options());
if (source_->has_state())
this->publish_state(source_->state);
}
void CopySelect::dump_config() { LOG_SELECT("", "Copy Select", this); }
void CopySelect::control(const std::string &value) {
auto call = source_->make_call();
call.set_option(value);
call.perform();
}
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,23 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/select/select.h"
namespace esphome {
namespace copy {
class CopySelect : public select::Select, public Component {
public:
void set_source(select::Select *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
void control(const std::string &value) override;
select::Select *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,45 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import (
CONF_DEVICE_CLASS,
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_SOURCE_ID,
CONF_STATE_CLASS,
CONF_UNIT_OF_MEASUREMENT,
CONF_ACCURACY_DECIMALS,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopySensor = copy_ns.class_("CopySensor", sensor.Sensor, cg.Component)
CONFIG_SCHEMA = (
sensor.sensor_schema(CopySensor)
.extend(
{
cv.Required(CONF_SOURCE_ID): cv.use_id(sensor.Sensor),
}
)
.extend(cv.COMPONENT_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_UNIT_OF_MEASUREMENT, CONF_SOURCE_ID),
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ACCURACY_DECIMALS, CONF_SOURCE_ID),
inherit_property_from(CONF_DEVICE_CLASS, CONF_SOURCE_ID),
inherit_property_from(CONF_STATE_CLASS, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
)
async def to_code(config):
var = await sensor.new_sensor(config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,18 @@
#include "copy_sensor.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.sensor";
void CopySensor::setup() {
source_->add_on_state_callback([this](float value) { this->publish_state(value); });
if (source_->has_state())
this->publish_state(source_->state);
}
void CopySensor::dump_config() { LOG_SENSOR("", "Copy Sensor", this); }
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,21 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace copy {
class CopySensor : public sensor::Sensor, public Component {
public:
void set_source(sensor::Sensor *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
sensor::Sensor *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,38 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import switch
from esphome.const import (
CONF_DEVICE_CLASS,
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_ID,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopySwitch = copy_ns.class_("CopySwitch", switch.Switch, cg.Component)
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(CopySwitch),
cv.Required(CONF_SOURCE_ID): cv.use_id(switch.Switch),
}
).extend(cv.COMPONENT_SCHEMA)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
inherit_property_from(CONF_DEVICE_CLASS, CONF_SOURCE_ID),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await switch.register_switch(var, config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,26 @@
#include "copy_switch.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.switch";
void CopySwitch::setup() {
source_->add_on_state_callback([this](float value) { this->publish_state(value); });
this->publish_state(source_->state);
}
void CopySwitch::dump_config() { LOG_SWITCH("", "Copy Switch", this); }
void CopySwitch::write_state(bool state) {
if (state) {
source_->turn_on();
} else {
source_->turn_off();
}
}
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,23 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/switch/switch.h"
namespace esphome {
namespace copy {
class CopySwitch : public switch_::Switch, public Component {
public:
void set_source(switch_::Switch *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
void write_state(bool state) override;
switch_::Switch *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,37 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import text_sensor
from esphome.const import (
CONF_ENTITY_CATEGORY,
CONF_ICON,
CONF_SOURCE_ID,
)
from esphome.core.entity_helpers import inherit_property_from
from .. import copy_ns
CopyTextSensor = copy_ns.class_("CopyTextSensor", text_sensor.TextSensor, cg.Component)
CONFIG_SCHEMA = (
text_sensor.text_sensor_schema(CopyTextSensor)
.extend(
{
cv.Required(CONF_SOURCE_ID): cv.use_id(text_sensor.TextSensor),
}
)
.extend(cv.COMPONENT_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = cv.All(
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
)
async def to_code(config):
var = await text_sensor.new_text_sensor(config)
await cg.register_component(var, config)
source = await cg.get_variable(config[CONF_SOURCE_ID])
cg.add(var.set_source(source))

View File

@@ -0,0 +1,18 @@
#include "copy_text_sensor.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.text_sensor";
void CopyTextSensor::setup() {
source_->add_on_state_callback([this](const std::string &value) { this->publish_state(value); });
if (source_->has_state())
this->publish_state(source_->state);
}
void CopyTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Copy Sensor", this); }
} // namespace copy
} // namespace esphome

View File

@@ -0,0 +1,21 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/text_sensor/text_sensor.h"
namespace esphome {
namespace copy {
class CopyTextSensor : public text_sensor::TextSensor, public Component {
public:
void set_source(text_sensor::TextSensor *source) { source_ = source; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
text_sensor::TextSensor *source_;
};
} // namespace copy
} // namespace esphome

View File

@@ -111,6 +111,9 @@ void DallasComponent::update() {
if (!result) {
ESP_LOGE(TAG, "Requesting conversion failed");
this->status_set_warning();
for (auto *sensor : this->sensors_) {
sensor->publish_state(NAN);
}
return;
}

View File

@@ -11,9 +11,39 @@ from esphome.const import (
CONF_WAKEUP_PIN,
)
from esphome.components.esp32 import get_esp32_variant
from esphome.components.esp32.const import (
VARIANT_ESP32,
VARIANT_ESP32C3,
)
WAKEUP_PINS = {
VARIANT_ESP32: [
0,
2,
4,
12,
13,
14,
15,
25,
26,
27,
32,
33,
34,
35,
36,
37,
38,
39,
],
VARIANT_ESP32C3: [0, 1, 2, 3, 4, 5],
}
def validate_pin_number(value):
valid_pins = [0, 2, 4, 12, 13, 14, 15, 25, 26, 27, 32, 33, 34, 35, 36, 37, 38, 39]
valid_pins = WAKEUP_PINS.get(get_esp32_variant(), WAKEUP_PINS[VARIANT_ESP32])
if value[CONF_NUMBER] not in valid_pins:
raise cv.Invalid(
f"Only pins {', '.join(str(x) for x in valid_pins)} support wakeup"
@@ -21,6 +51,14 @@ def validate_pin_number(value):
return value
def validate_config(config):
if get_esp32_variant() == VARIANT_ESP32C3 and CONF_ESP32_EXT1_WAKEUP in config:
raise cv.Invalid("ESP32-C3 does not support wakeup from touch.")
if get_esp32_variant() == VARIANT_ESP32C3 and CONF_TOUCH_WAKEUP in config:
raise cv.Invalid("ESP32-C3 does not support wakeup from ext1")
return config
deep_sleep_ns = cg.esphome_ns.namespace("deep_sleep")
DeepSleepComponent = deep_sleep_ns.class_("DeepSleepComponent", cg.Component)
EnterDeepSleepAction = deep_sleep_ns.class_("EnterDeepSleepAction", automation.Action)

View File

@@ -104,7 +104,7 @@ void DeepSleepComponent::begin_sleep(bool manual) {
App.run_safe_shutdown_hooks();
#ifdef USE_ESP32
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3)
if (this->sleep_duration_.has_value())
esp_sleep_enable_timer_wakeup(*this->sleep_duration_);
if (this->wakeup_pin_ != nullptr) {
@@ -126,6 +126,18 @@ void DeepSleepComponent::begin_sleep(bool manual) {
esp_deep_sleep_start();
#endif
#ifdef USE_ESP32_VARIANT_ESP32C3
if (this->sleep_duration_.has_value())
esp_sleep_enable_timer_wakeup(*this->sleep_duration_);
if (this->wakeup_pin_ != nullptr) {
bool level = !this->wakeup_pin_->is_inverted();
if (this->wakeup_pin_mode_ == WAKEUP_PIN_MODE_INVERT_WAKEUP && this->wakeup_pin_->digital_read()) {
level = !level;
}
esp_deep_sleep_enable_gpio_wakeup(gpio_num_t(this->wakeup_pin_->get_pin()), level);
}
#endif
#ifdef USE_ESP8266
ESP.deepSleep(*this->sleep_duration_); // NOLINT(readability-static-accessed-through-instance)
#endif

View File

@@ -57,13 +57,16 @@ class DeepSleepComponent : public Component {
public:
/// Set the duration in ms the component should sleep once it's in deep sleep mode.
void set_sleep_duration(uint32_t time_ms);
#ifdef USE_ESP32
#if defined(USE_ESP32)
/** Set the pin to wake up to on the ESP32 once it's in deep sleep mode.
* Use the inverted property to set the wakeup level.
*/
void set_wakeup_pin(InternalGPIOPin *pin) { this->wakeup_pin_ = pin; }
void set_wakeup_pin_mode(WakeupPinMode wakeup_pin_mode);
#endif
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3)
void set_ext1_wakeup(Ext1Wakeup ext1_wakeup);

View File

@@ -61,12 +61,30 @@ def set_core_data(config):
return config
def get_esp32_variant():
return CORE.data[KEY_ESP32][KEY_VARIANT]
def get_esp32_variant(core_obj=None):
return (core_obj or CORE).data[KEY_ESP32][KEY_VARIANT]
def is_esp32c3():
return get_esp32_variant() == VARIANT_ESP32C3
def only_on_variant(*, supported=None, unsupported=None):
"""Config validator for features only available on some ESP32 variants."""
if supported is not None and not isinstance(supported, list):
supported = [supported]
if unsupported is not None and not isinstance(unsupported, list):
unsupported = [unsupported]
def validator_(obj):
variant = get_esp32_variant()
if supported is not None and variant not in supported:
raise cv.Invalid(
f"This feature is only available on {', '.join(supported)}"
)
if unsupported is not None and variant in unsupported:
raise cv.Invalid(
f"This feature is not available on {', '.join(unsupported)}"
)
return obj
return validator_
@dataclass

View File

@@ -1,6 +1,10 @@
# Source https://github.com/letscontrolit/ESPEasy/pull/3845#issuecomment-1005864664
import esptool
import os
if os.environ.get("ESPHOME_USE_SUBPROCESS") is None:
import esptool
else:
import subprocess
from SCons.Script import ARGUMENTS
# pylint: disable=E0602
@@ -42,8 +46,11 @@ def esp32_create_combined_bin(source, target, env):
print()
print(f"Using esptool.py arguments: {' '.join(cmd)}")
print()
esptool.main(cmd)
if os.environ.get("ESPHOME_USE_SUBPROCESS") is None:
esptool.main(cmd)
else:
subprocess.run(["esptool.py", *cmd])
# pylint: disable=E0602
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp32_create_combined_bin) # noqa

View File

@@ -17,29 +17,29 @@ const uint8_t FUJITSU_GENERAL_TEMP_MAX = 30; // Celsius
* turn
* on temp mode fan swing
* * | | | | | | *
*
*
* temperatures 1 1248 124 124 1
* auto auto 18 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000100 00000000 00000000 00000000 00000000 00000000 00000100 11110001
* auto auto 19 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10001100 00000000 00000000 00000000 00000000 00000000 00000100 11111110
* auto auto 30 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000111 00000000 00000000 00000000 00000000 00000000 00000100 11110011
*
*
* on flag:
* on at 16 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000000 00100000 00000000 00000000 00000000 00000000 00000100 11010101
* down to 16 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 00000000 00100000 00000000 00000000 00000000 00000000 00000100 00110101
*
*
* mode options:
* auto auto 30 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000111 00000000 00000000 00000000 00000000 00000000 00000100 11110011
* cool auto 30 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000111 10000000 00000000 00000000 00000000 00000000 00000100 01110011
* dry auto 30 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000111 01000000 00000000 00000000 00000000 00000000 00000100 10110011
* fan (auto) (30) 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000111 11000000 00000000 00000000 00000000 00000000 00000100 00110011
* heat auto 30 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000111 00100000 00000000 00000000 00000000 00000000 00000100 11010011
*
*
* fan options:
* heat 30 high 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 10000111 00100000 10000000 00000000 00000000 00000000 00000100 01010011
* heat 30 med 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 00000111 00100000 01000000 00000000 00000000 00000000 00000100 01010011
* heat 30 low 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 00000111 00100000 11000000 00000000 00000000 00000000 00000100 10010011
* heat 30 quiet 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 00000111 00100000 00100000 00000000 00000000 00000000 00000100 00010011
*
*
* swing options:
* heat 30 swing vert 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 00000111 00100000 00101000 00000000 00000000 00000000 00000100 00011101
* heat 30 noswing 00101000 11000110 00000000 00001000 00001000 01111111 10010000 00001100 00000111 00100000 00100000 00000000 00000000 00000000 00000100 00010011

View File

@@ -0,0 +1 @@
"""Support for Honeywell ABP"""

View File

@@ -0,0 +1,102 @@
#include "honeywellabp.h"
#include "esphome/core/log.h"
namespace esphome {
namespace honeywellabp {
static const char *const TAG = "honeywellabp";
const float MIN_COUNT = 1638.4; // 1638 counts (10% of 2^14 counts or 0x0666)
const float MAX_COUNT = 14745.6; // 14745 counts (90% of 2^14 counts or 0x3999)
void HONEYWELLABPSensor::setup() {
ESP_LOGD(TAG, "Setting up Honeywell ABP Sensor ");
this->spi_setup();
}
uint8_t HONEYWELLABPSensor::readsensor_() {
// Polls the sensor for new data.
// transfer 4 bytes (the last two are temperature only used by some sensors)
this->enable();
buf_[0] = this->read_byte();
buf_[1] = this->read_byte();
buf_[2] = this->read_byte();
buf_[3] = this->read_byte();
this->disable();
// Check the status codes:
// status = 0 : normal operation
// status = 1 : device in command mode
// status = 2 : stale data
// status = 3 : diagnostic condition
status_ = buf_[0] >> 6 & 0x3;
ESP_LOGV(TAG, "Sensor status %d", status_);
// if device is normal and there is new data, bitmask and save the raw data
if (status_ == 0) {
// 14 - bit pressure is the last 6 bits of byte 0 (high bits) & all of byte 1 (lowest 8 bits)
pressure_count_ = ((uint16_t)(buf_[0]) << 8 & 0x3F00) | ((uint16_t)(buf_[1]) & 0xFF);
// 11 - bit temperature is all of byte 2 (lowest 8 bits) and the first three bits of byte 3
temperature_count_ = (((uint16_t)(buf_[2]) << 3) & 0x7F8) | (((uint16_t)(buf_[3]) >> 5) & 0x7);
ESP_LOGV(TAG, "Sensor pressure_count_ %d", pressure_count_);
ESP_LOGV(TAG, "Sensor temperature_count_ %d", temperature_count_);
}
return status_;
}
// returns status
uint8_t HONEYWELLABPSensor::readstatus_() { return status_; }
// The pressure value from the most recent reading in raw counts
int HONEYWELLABPSensor::rawpressure_() { return pressure_count_; }
// The temperature value from the most recent reading in raw counts
int HONEYWELLABPSensor::rawtemperature_() { return temperature_count_; }
// Converts a digital pressure measurement in counts to pressure measured
float HONEYWELLABPSensor::countstopressure_(const int counts, const float min_pressure, const float max_pressure) {
return ((((float) counts - MIN_COUNT) * (max_pressure - min_pressure)) / (MAX_COUNT - MIN_COUNT)) + min_pressure;
}
// Converts a digital temperature measurement in counts to temperature in C
// This will be invalid if sensore daoes not have temperature measurement capability
float HONEYWELLABPSensor::countstotemperatures_(const int counts) { return (((float) counts / 2047.0) * 200.0) - 50.0; }
// Pressure value from the most recent reading in units
float HONEYWELLABPSensor::read_pressure_() {
return countstopressure_(pressure_count_, honeywellabp_min_pressure_, honeywellabp_max_pressure_);
}
// Temperature value from the most recent reading in degrees C
float HONEYWELLABPSensor::read_temperature_() { return countstotemperatures_(temperature_count_); }
void HONEYWELLABPSensor::update() {
ESP_LOGV(TAG, "Update Honeywell ABP Sensor");
if (readsensor_() == 0) {
if (this->pressure_sensor_ != nullptr)
this->pressure_sensor_->publish_state(read_pressure_() * 1.0);
if (this->temperature_sensor_ != nullptr)
this->temperature_sensor_->publish_state(read_temperature_() * 1.0);
}
}
float HONEYWELLABPSensor::get_setup_priority() const { return setup_priority::LATE; }
void HONEYWELLABPSensor::dump_config() {
// LOG_SENSOR("", "HONEYWELLABP", this);
LOG_PIN(" CS Pin: ", this->cs_);
ESP_LOGCONFIG(TAG, " Min Pressure Range: %0.1f", honeywellabp_min_pressure_);
ESP_LOGCONFIG(TAG, " Max Pressure Range: %0.1f", honeywellabp_max_pressure_);
LOG_UPDATE_INTERVAL(this);
}
void HONEYWELLABPSensor::set_honeywellabp_min_pressure(float min_pressure) {
this->honeywellabp_min_pressure_ = min_pressure;
}
void HONEYWELLABPSensor::set_honeywellabp_max_pressure(float max_pressure) {
this->honeywellabp_max_pressure_ = max_pressure;
}
} // namespace honeywellabp
} // namespace esphome

View File

@@ -0,0 +1,45 @@
// for Honeywell ABP sensor
// adapting code from https://github.com/vwls/Honeywell_pressure_sensors
#pragma once
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/spi/spi.h"
#include "esphome/core/component.h"
namespace esphome {
namespace honeywellabp {
class HONEYWELLABPSensor : public PollingComponent,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_200KHZ> {
public:
void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
void setup() override;
void update() override;
float get_setup_priority() const override;
void dump_config() override;
void set_honeywellabp_min_pressure(float min_pressure);
void set_honeywellabp_max_pressure(float max_pressure);
protected:
float honeywellabp_min_pressure_ = 0.0;
float honeywellabp_max_pressure_ = 0.0;
uint8_t buf_[4]; // buffer to hold sensor data
uint8_t status_ = 0; // byte to hold status information.
int pressure_count_ = 0; // hold raw pressure data (14 - bit, 0 - 16384)
int temperature_count_ = 0; // hold raw temperature data (11 - bit, 0 - 2048)
sensor::Sensor *pressure_sensor_;
sensor::Sensor *temperature_sensor_;
uint8_t readsensor_();
uint8_t readstatus_();
int rawpressure_();
int rawtemperature_();
float countstopressure_(int counts, float min_pressure, float max_pressure);
float countstotemperatures_(int counts);
float read_pressure_();
float read_temperature_();
};
} // namespace honeywellabp
} // namespace esphome

View File

@@ -0,0 +1,70 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.components import spi
from esphome.const import (
CONF_ID,
CONF_PRESSURE,
CONF_TEMPERATURE,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
)
DEPENDENCIES = ["spi"]
CODEOWNERS = ["@RubyBailey"]
CONF_MIN_PRESSURE = "min_pressure"
CONF_MAX_PRESSURE = "max_pressure"
honeywellabp_ns = cg.esphome_ns.namespace("honeywellabp")
HONEYWELLABPSensor = honeywellabp_ns.class_(
"HONEYWELLABPSensor", sensor.Sensor, cg.PollingComponent, spi.SPIDevice
)
CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(HONEYWELLABPSensor),
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
unit_of_measurement="psi",
accuracy_decimals=1,
device_class=DEVICE_CLASS_PRESSURE,
state_class=STATE_CLASS_MEASUREMENT,
).extend(
{
cv.Required(CONF_MIN_PRESSURE): cv.float_,
cv.Required(CONF_MAX_PRESSURE): cv.float_,
}
),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS,
accuracy_decimals=1,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
}
)
.extend(cv.polling_component_schema("60s"))
.extend(spi.spi_device_schema(cs_pin_required=True))
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await spi.register_spi_device(var, config)
if CONF_PRESSURE in config:
conf = config[CONF_PRESSURE]
sens = await sensor.new_sensor(conf)
cg.add(var.set_pressure_sensor(sens))
cg.add(var.set_honeywellabp_min_pressure(conf[CONF_MIN_PRESSURE]))
cg.add(var.set_honeywellabp_max_pressure(conf[CONF_MAX_PRESSURE]))
if CONF_TEMPERATURE in config:
conf = config[CONF_TEMPERATURE]
sens = await sensor.new_sensor(conf)
cg.add(var.set_temperature_sensor(sens))

View File

@@ -25,10 +25,10 @@ static const uint8_t PROGMEM INITCMD_M5STACK[] = {
0xF2, 1, 0x00, // 3Gamma Function Disable
ILI9341_GAMMASET , 1, 0x01, // Gamma curve selected
ILI9341_GMCTRP1 , 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, // Set Gamma
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03,
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03,
0x0E, 0x09, 0x00,
ILI9341_GMCTRN1 , 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, // Set Gamma
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C,
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C,
0x31, 0x36, 0x0F,
ILI9341_SLPOUT , 0x80, // Exit Sleep
ILI9341_DISPON , 0x80, // Display on
@@ -55,10 +55,10 @@ static const uint8_t PROGMEM INITCMD_TFT[] = {
0xF2, 1, 0x00, // 3Gamma Function Disable
ILI9341_GAMMASET , 1, 0x01, // Gamma curve selected
ILI9341_GMCTRP1 , 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, // Set Gamma
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03,
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03,
0x0E, 0x09, 0x00,
ILI9341_GMCTRN1 , 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, // Set Gamma
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C,
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C,
0x31, 0x36, 0x0F,
ILI9341_SLPOUT , 0x80, // Exit Sleep
ILI9341_DISPON , 0x80, // Display on

View File

@@ -22,7 +22,7 @@ std::string build_json(const json_build_t &f) {
#ifdef USE_ESP8266
const size_t free_heap = ESP.getMaxFreeBlockSize() - 2048; // NOLINT(readability-static-accessed-through-instance)
#elif defined(USE_ESP32)
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT) - 2048;
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL) - 2048;
#endif
DynamicJsonDocument json_document(free_heap);
@@ -42,7 +42,7 @@ void parse_json(const std::string &data, const json_parse_t &f) {
#ifdef USE_ESP8266
const size_t free_heap = ESP.getMaxFreeBlockSize() - 2048; // NOLINT(readability-static-accessed-through-instance)
#elif defined(USE_ESP32)
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT) - 2048;
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL) - 2048;
#endif
DynamicJsonDocument json_document(free_heap);

View File

@@ -52,6 +52,8 @@ RESTORE_MODES = {
"ALWAYS_ON": LightRestoreMode.LIGHT_ALWAYS_ON,
"RESTORE_INVERTED_DEFAULT_OFF": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_OFF,
"RESTORE_INVERTED_DEFAULT_ON": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_ON,
"RESTORE_AND_OFF": LightRestoreMode.LIGHT_RESTORE_AND_OFF,
"RESTORE_AND_ON": LightRestoreMode.LIGHT_RESTORE_AND_ON,
}
LIGHT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend(

View File

@@ -68,6 +68,12 @@ void LightState::setup() {
recovered.state = !recovered.state;
}
break;
case LIGHT_RESTORE_AND_OFF:
case LIGHT_RESTORE_AND_ON:
this->rtc_ = global_preferences->make_preference<LightStateRTCState>(this->get_object_id_hash());
this->rtc_.load(&recovered);
recovered.state = (this->restore_mode_ == LIGHT_RESTORE_AND_ON);
break;
case LIGHT_ALWAYS_OFF:
recovered.state = false;
break;

View File

@@ -22,6 +22,8 @@ enum LightRestoreMode {
LIGHT_ALWAYS_ON,
LIGHT_RESTORE_INVERTED_DEFAULT_OFF,
LIGHT_RESTORE_INVERTED_DEFAULT_ON,
LIGHT_RESTORE_AND_OFF,
LIGHT_RESTORE_AND_ON,
};
/** This class represents the communication layer between the front-end MQTT layer and the

View File

@@ -113,8 +113,27 @@ void LilygoT547Touchscreen::loop() {
if (tp.state == 0x06)
tp.state = 0x07;
tp.y = (uint16_t)((buffer[i * 5 + 1 + offset] << 4) | ((buffer[i * 5 + 3 + offset] >> 4) & 0x0F));
tp.x = (uint16_t)((buffer[i * 5 + 2 + offset] << 4) | (buffer[i * 5 + 3 + offset] & 0x0F));
uint16_t y = (uint16_t)((buffer[i * 5 + 1 + offset] << 4) | ((buffer[i * 5 + 3 + offset] >> 4) & 0x0F));
uint16_t x = (uint16_t)((buffer[i * 5 + 2 + offset] << 4) | (buffer[i * 5 + 3 + offset] & 0x0F));
switch (this->rotation_) {
case ROTATE_0_DEGREES:
tp.y = this->display_height_ - y;
tp.x = x;
break;
case ROTATE_90_DEGREES:
tp.x = this->display_height_ - y;
tp.y = this->display_width_ - x;
break;
case ROTATE_180_DEGREES:
tp.y = y;
tp.x = this->display_width_ - x;
break;
case ROTATE_270_DEGREES:
tp.x = y;
tp.y = x;
break;
}
this->defer([this, tp]() { this->send_touch_(tp); });
}
@@ -122,8 +141,28 @@ void LilygoT547Touchscreen::loop() {
TouchPoint tp;
tp.id = (buffer[0] >> 4) & 0x0F;
tp.state = 0x06;
tp.y = (uint16_t)((buffer[0 * 5 + 1] << 4) | ((buffer[0 * 5 + 3] >> 4) & 0x0F));
tp.x = (uint16_t)((buffer[0 * 5 + 2] << 4) | (buffer[0 * 5 + 3] & 0x0F));
uint16_t y = (uint16_t)((buffer[0 * 5 + 1] << 4) | ((buffer[0 * 5 + 3] >> 4) & 0x0F));
uint16_t x = (uint16_t)((buffer[0 * 5 + 2] << 4) | (buffer[0 * 5 + 3] & 0x0F));
switch (this->rotation_) {
case ROTATE_0_DEGREES:
tp.y = this->display_height_ - y;
tp.x = x;
break;
case ROTATE_90_DEGREES:
tp.x = this->display_height_ - y;
tp.y = this->display_width_ - x;
break;
case ROTATE_180_DEGREES:
tp.y = y;
tp.x = this->display_width_ - x;
break;
case ROTATE_270_DEGREES:
tp.x = y;
tp.y = x;
break;
}
this->defer([this, tp]() { this->send_touch_(tp); });
}

View File

View File

@@ -0,0 +1,144 @@
#include "max44009.h"
#include "esphome/core/log.h"
namespace esphome {
namespace max44009 {
static const char *const TAG = "max44009.sensor";
// REGISTERS
static const uint8_t MAX44009_REGISTER_CONFIGURATION = 0x02;
static const uint8_t MAX44009_LUX_READING_HIGH = 0x03;
static const uint8_t MAX44009_LUX_READING_LOW = 0x04;
// CONFIGURATION MASKS
static const uint8_t MAX44009_CFG_CONTINUOUS = 0x80;
// ERROR CODES
static const uint8_t MAX44009_OK = 0;
static const uint8_t MAX44009_ERROR_WIRE_REQUEST = -10;
static const uint8_t MAX44009_ERROR_OVERFLOW = -20;
static const uint8_t MAX44009_ERROR_HIGH_BYTE = -30;
static const uint8_t MAX44009_ERROR_LOW_BYTE = -31;
void MAX44009Sensor::setup() {
ESP_LOGCONFIG(TAG, "Setting up MAX44009...");
bool state_ok = false;
if (this->mode_ == MAX44009Mode::MAX44009_MODE_LOW_POWER) {
state_ok = this->set_low_power_mode();
} else if (this->mode_ == MAX44009Mode::MAX44009_MODE_CONTINUOUS) {
state_ok = this->set_continuous_mode();
} else {
/*
* Mode AUTO: Set mode depending on update interval
* - On low power mode, the IC measures lux intensity only once every 800ms
* regardless of integration time
* - On continuous mode, the IC continuously measures lux intensity
*/
if (this->get_update_interval() < 800) {
state_ok = this->set_continuous_mode();
} else {
state_ok = this->set_low_power_mode();
}
}
if (!state_ok)
this->mark_failed();
}
void MAX44009Sensor::dump_config() {
ESP_LOGCONFIG(TAG, "MAX44009:");
LOG_I2C_DEVICE(this);
if (this->is_failed()) {
ESP_LOGE(TAG, "Communication with MAX44009 failed!");
}
}
float MAX44009Sensor::get_setup_priority() const { return setup_priority::DATA; }
void MAX44009Sensor::update() {
// update sensor illuminance value
float lux = this->read_illuminance_();
if (this->error_ != MAX44009_OK) {
this->status_set_warning();
this->publish_state(NAN);
} else {
this->status_clear_warning();
this->publish_state(lux);
}
}
float MAX44009Sensor::read_illuminance_() {
uint8_t datahigh = this->read_(MAX44009_LUX_READING_HIGH);
if (error_ != MAX44009_OK) {
this->error_ = MAX44009_ERROR_HIGH_BYTE;
return this->error_;
}
uint8_t datalow = this->read_(MAX44009_LUX_READING_LOW);
if (error_ != MAX44009_OK) {
this->error_ = MAX44009_ERROR_LOW_BYTE;
return this->error_;
}
uint8_t exponent = datahigh >> 4;
if (exponent == 0x0F) {
this->error_ = MAX44009_ERROR_OVERFLOW;
return this->error_;
}
return this->convert_to_lux_(datahigh, datalow);
}
float MAX44009Sensor::convert_to_lux_(uint8_t data_high, uint8_t data_low) {
uint8_t exponent = data_high >> 4;
uint32_t mantissa = ((data_high & 0x0F) << 4) + (data_low & 0x0F);
return ((0x0001 << exponent) * 0.045) * mantissa;
}
bool MAX44009Sensor::set_continuous_mode() {
uint8_t config = this->read_(MAX44009_REGISTER_CONFIGURATION);
if (this->error_ == MAX44009_OK) {
config |= MAX44009_CFG_CONTINUOUS;
this->write_(MAX44009_REGISTER_CONFIGURATION, config);
this->status_clear_warning();
ESP_LOGV(TAG, "set to continuous mode");
return true;
} else {
this->status_set_warning();
return false;
}
}
bool MAX44009Sensor::set_low_power_mode() {
uint8_t config = this->read_(MAX44009_REGISTER_CONFIGURATION);
if (this->error_ == MAX44009_OK) {
config &= ~MAX44009_CFG_CONTINUOUS;
this->write_(MAX44009_REGISTER_CONFIGURATION, config);
this->status_clear_warning();
ESP_LOGV(TAG, "set to low power mode");
return true;
} else {
this->status_set_warning();
return false;
}
}
uint8_t MAX44009Sensor::read_(uint8_t reg) {
uint8_t data = 0;
if (!this->read_byte(reg, &data)) {
this->error_ = MAX44009_ERROR_WIRE_REQUEST;
} else {
this->error_ = MAX44009_OK;
}
return data;
}
void MAX44009Sensor::write_(uint8_t reg, uint8_t value) {
if (!this->write_byte(reg, value)) {
this->error_ = MAX44009_ERROR_WIRE_REQUEST;
} else {
this->error_ = MAX44009_OK;
}
}
void MAX44009Sensor::set_mode(MAX44009Mode mode) { this->mode_ = mode; }
} // namespace max44009
} // namespace esphome

View File

@@ -0,0 +1,37 @@
#pragma once
#include "esphome/components/i2c/i2c.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/core/component.h"
namespace esphome {
namespace max44009 {
enum MAX44009Mode { MAX44009_MODE_AUTO, MAX44009_MODE_LOW_POWER, MAX44009_MODE_CONTINUOUS };
/// This class implements support for the MAX44009 Illuminance i2c sensor.
class MAX44009Sensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice {
public:
MAX44009Sensor() {}
void setup() override;
void dump_config() override;
float get_setup_priority() const override;
void update() override;
void set_mode(MAX44009Mode mode);
bool set_continuous_mode();
bool set_low_power_mode();
protected:
/// Read the illuminance value
float read_illuminance_();
float convert_to_lux_(uint8_t data_high, uint8_t data_low);
uint8_t read_(uint8_t reg);
void write_(uint8_t reg, uint8_t value);
int error_;
MAX44009Mode mode_;
};
} // namespace max44009
} // namespace esphome

View File

@@ -0,0 +1,53 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, i2c
from esphome.const import (
CONF_ID,
CONF_MODE,
DEVICE_CLASS_ILLUMINANCE,
STATE_CLASS_MEASUREMENT,
UNIT_LUX,
)
CODEOWNERS = ["@berfenger"]
DEPENDENCIES = ["i2c"]
max44009_ns = cg.esphome_ns.namespace("max44009")
MAX44009Sensor = max44009_ns.class_(
"MAX44009Sensor", sensor.Sensor, cg.PollingComponent, i2c.I2CDevice
)
MAX44009Mode = max44009_ns.enum("MAX44009Mode")
MODE_OPTIONS = {
"auto": MAX44009Mode.MAX44009_MODE_AUTO,
"low_power": MAX44009Mode.MAX44009_MODE_LOW_POWER,
"continuous": MAX44009Mode.MAX44009_MODE_CONTINUOUS,
}
CONFIG_SCHEMA = (
sensor.sensor_schema(
unit_of_measurement=UNIT_LUX,
accuracy_decimals=3,
device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT,
)
.extend(
{
cv.GenerateID(): cv.declare_id(MAX44009Sensor),
cv.Optional(CONF_MODE, default="low_power"): cv.enum(
MODE_OPTIONS, lower=True
),
}
)
.extend(cv.polling_component_schema("60s"))
.extend(i2c.i2c_device_schema(0x4A))
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
await sensor.register_sensor(var, config)
cg.add(var.set_mode(config[CONF_MODE]))

View File

@@ -0,0 +1,29 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c
from esphome.const import CONF_ID
CODEOWNERS = ["@berfenger"]
DEPENDENCIES = ["i2c"]
MULTI_CONF = True
CONF_STORE_IN_EEPROM = "store_in_eeprom"
mcp4728_ns = cg.esphome_ns.namespace("mcp4728")
MCP4728Component = mcp4728_ns.class_("MCP4728Component", cg.Component, i2c.I2CDevice)
CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(MCP4728Component),
cv.Optional(CONF_STORE_IN_EEPROM, default=False): cv.boolean,
}
)
.extend(cv.COMPONENT_SCHEMA)
.extend(i2c.i2c_device_schema(0x60))
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID], config[CONF_STORE_IN_EEPROM])
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)

View File

@@ -0,0 +1,121 @@
#include "mcp4728_output.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome {
namespace mcp4728 {
static const char *const TAG = "mcp4728";
void MCP4728Component::setup() {
ESP_LOGCONFIG(TAG, "Setting up MCP4728 (0x%02X)...", this->address_);
auto err = this->write(nullptr, 0);
if (err != i2c::ERROR_OK) {
this->mark_failed();
return;
}
}
void MCP4728Component::dump_config() {
ESP_LOGCONFIG(TAG, "MCP4728:");
LOG_I2C_DEVICE(this);
if (this->is_failed()) {
ESP_LOGE(TAG, "Communication with MCP4728 failed!");
}
}
void MCP4728Component::loop() {
if (this->update_) {
this->update_ = false;
if (this->store_in_eeprom_) {
if (!this->seq_write_()) {
this->status_set_error();
} else {
this->status_clear_error();
}
} else {
if (!this->multi_write_()) {
this->status_set_error();
} else {
this->status_clear_error();
}
}
}
}
void MCP4728Component::set_channel_value_(MCP4728ChannelIdx channel, uint16_t value) {
uint8_t cn = 0;
if (channel == MCP4728_CHANNEL_A) {
cn = 'A';
} else if (channel == MCP4728_CHANNEL_B) {
cn = 'B';
} else if (channel == MCP4728_CHANNEL_C) {
cn = 'C';
} else {
cn = 'D';
}
ESP_LOGV(TAG, "Setting MCP4728 channel %c to %d!", cn, value);
reg_[channel].data = value;
this->update_ = true;
}
bool MCP4728Component::multi_write_() {
i2c::ErrorCode err[4];
for (uint8_t i = 0; i < 4; ++i) {
uint8_t wd[3];
wd[0] = ((uint8_t) CMD::MULTI_WRITE | (i << 1)) & 0xFE;
wd[1] = ((uint8_t) reg_[i].vref << 7) | ((uint8_t) reg_[i].pd << 5) | ((uint8_t) reg_[i].gain << 4) |
(reg_[i].data >> 8);
wd[2] = reg_[i].data & 0xFF;
err[i] = this->write(wd, sizeof(wd));
}
bool ok = true;
for (auto &e : err) {
if (e != i2c::ERROR_OK) {
ok = false;
break;
}
}
return ok;
}
bool MCP4728Component::seq_write_() {
uint8_t wd[9];
wd[0] = (uint8_t) CMD::SEQ_WRITE;
for (uint8_t i = 0; i < 4; i++) {
wd[i * 2 + 1] = ((uint8_t) reg_[i].vref << 7) | ((uint8_t) reg_[i].pd << 5) | ((uint8_t) reg_[i].gain << 4) |
(reg_[i].data >> 8);
wd[i * 2 + 2] = reg_[i].data & 0xFF;
}
auto err = this->write(wd, sizeof(wd));
return err == i2c::ERROR_OK;
}
void MCP4728Component::select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref) {
reg_[channel].vref = vref;
this->update_ = true;
}
void MCP4728Component::select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd) {
reg_[channel].pd = pd;
this->update_ = true;
}
void MCP4728Component::select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain) {
reg_[channel].gain = gain;
this->update_ = true;
}
void MCP4728Channel::write_state(float state) {
const uint16_t max_duty = 4095;
const float duty_rounded = roundf(state * max_duty);
auto duty = static_cast<uint16_t>(duty_rounded);
this->parent_->set_channel_value_(this->channel_, duty);
}
} // namespace mcp4728
} // namespace esphome

View File

@@ -0,0 +1,91 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/output/float_output.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace mcp4728 {
enum class CMD {
FAST_WRITE = 0x00,
MULTI_WRITE = 0x40,
SINGLE_WRITE = 0x58,
SEQ_WRITE = 0x50,
SELECT_VREF = 0x80,
SELECT_GAIN = 0xC0,
SELECT_POWER_DOWN = 0xA0
};
enum MCP4728Vref { MCP4728_VREF_VDD = 0, MCP4728_VREF_INTERNAL_2_8V = 1 };
enum MCP4728PwrDown {
MCP4728_PD_NORMAL = 0,
MCP4728_PD_GND_1KOHM = 1,
MCP4728_PD_GND_100KOHM = 2,
MCP4728_PD_GND_500KOHM = 3
};
enum MCP4728Gain { MCP4728_GAIN_X1 = 0, MCP4728_GAIN_X2 = 1 };
enum MCP4728ChannelIdx { MCP4728_CHANNEL_A = 0, MCP4728_CHANNEL_B = 1, MCP4728_CHANNEL_C = 2, MCP4728_CHANNEL_D = 3 };
struct DACInputData {
MCP4728Vref vref;
MCP4728PwrDown pd;
MCP4728Gain gain;
uint16_t data;
};
class MCP4728Channel;
/// MCP4728 float output component.
class MCP4728Component : public Component, public i2c::I2CDevice {
public:
MCP4728Component(bool store_in_eeprom) : store_in_eeprom_(store_in_eeprom) {}
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::HARDWARE; }
void loop() override;
protected:
friend MCP4728Channel;
void set_channel_value_(MCP4728ChannelIdx channel, uint16_t value);
bool multi_write_();
bool seq_write_();
void select_vref_(MCP4728ChannelIdx channel, MCP4728Vref vref);
void select_power_down_(MCP4728ChannelIdx channel, MCP4728PwrDown pd);
void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain);
private:
DACInputData reg_[4];
bool store_in_eeprom_ = false;
bool update_ = false;
};
class MCP4728Channel : public output::FloatOutput {
public:
MCP4728Channel(MCP4728Component *parent, MCP4728ChannelIdx channel, MCP4728Vref vref, MCP4728Gain gain,
MCP4728PwrDown pwrdown)
: parent_(parent), channel_(channel), vref_(vref), gain_(gain), pwrdown_(pwrdown) {
// update VREF
parent->select_vref_(channel, vref_);
// update PD
parent->select_power_down_(channel, pwrdown_);
// update GAIN
parent->select_gain_(channel, gain_);
}
protected:
void write_state(float state) override;
MCP4728Component *parent_;
MCP4728ChannelIdx channel_;
MCP4728Vref vref_;
MCP4728Gain gain_;
MCP4728PwrDown pwrdown_;
};
} // namespace mcp4728
} // namespace esphome

View File

@@ -0,0 +1,63 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import output
from esphome.const import CONF_CHANNEL, CONF_ID, CONF_GAIN
from . import MCP4728Component, mcp4728_ns
DEPENDENCIES = ["mcp4728"]
MCP4728Channel = mcp4728_ns.class_("MCP4728Channel", output.FloatOutput)
CONF_MCP4728_ID = "mcp4728_id"
CONF_VREF = "vref"
CONF_POWER_DOWN = "power_down"
MCP4728Vref = mcp4728_ns.enum("MCP4728Vref")
VREF_OPTIONS = {
"vdd": MCP4728Vref.MCP4728_VREF_VDD,
"internal": MCP4728Vref.MCP4728_VREF_INTERNAL_2_8V,
}
MCP4728Gain = mcp4728_ns.enum("MCP4728Gain")
GAIN_OPTIONS = {"X1": MCP4728Gain.MCP4728_GAIN_X1, "X2": MCP4728Gain.MCP4728_GAIN_X2}
MCP4728PwrDown = mcp4728_ns.enum("MCP4728PwrDown")
PWRDOWN_OPTIONS = {
"normal": MCP4728PwrDown.MCP4728_PD_NORMAL,
"gnd_1k": MCP4728PwrDown.MCP4728_PD_GND_1KOHM,
"gnd_100k": MCP4728PwrDown.MCP4728_PD_GND_100KOHM,
"gnd_500k": MCP4728PwrDown.MCP4728_PD_GND_500KOHM,
}
MCP4728ChannelIdx = mcp4728_ns.enum("MCP4728ChannelIdx")
CHANNEL_OPTIONS = {
"A": MCP4728ChannelIdx.MCP4728_CHANNEL_A,
"B": MCP4728ChannelIdx.MCP4728_CHANNEL_B,
"C": MCP4728ChannelIdx.MCP4728_CHANNEL_C,
"D": MCP4728ChannelIdx.MCP4728_CHANNEL_D,
}
CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend(
{
cv.Required(CONF_ID): cv.declare_id(MCP4728Channel),
cv.GenerateID(CONF_MCP4728_ID): cv.use_id(MCP4728Component),
cv.Required(CONF_CHANNEL): cv.enum(CHANNEL_OPTIONS, upper=True),
cv.Optional(CONF_VREF, default="vdd"): cv.enum(VREF_OPTIONS, upper=False),
cv.Optional(CONF_POWER_DOWN, default="normal"): cv.enum(
PWRDOWN_OPTIONS, upper=False
),
cv.Optional(CONF_GAIN, default="X1"): cv.enum(GAIN_OPTIONS, upper=True),
}
)
async def to_code(config):
paren = await cg.get_variable(config[CONF_MCP4728_ID])
var = cg.new_Pvariable(
config[CONF_ID],
paren,
config[CONF_CHANNEL],
config[CONF_VREF],
config[CONF_GAIN],
config[CONF_POWER_DOWN],
)
await output.register_output(var, config)

View File

@@ -11,6 +11,7 @@ from esphome.const import (
)
from .. import (
MODBUS_WRITE_REGISTER_TYPE,
add_modbus_base_properties,
modbus_controller_ns,
modbus_calc_properties,
@@ -24,6 +25,7 @@ from ..const import (
CONF_CUSTOM_COMMAND,
CONF_FORCE_NEW_RANGE,
CONF_MODBUS_CONTROLLER_ID,
CONF_REGISTER_TYPE,
CONF_SKIP_UPDATES,
CONF_USE_WRITE_MULTIPLE,
CONF_VALUE_TYPE,
@@ -61,6 +63,9 @@ CONFIG_SCHEMA = cv.All(
number.NUMBER_SCHEMA.extend(ModbusItemBaseSchema).extend(
{
cv.GenerateID(): cv.declare_id(ModbusNumber),
cv.Optional(CONF_REGISTER_TYPE, default="holding"): cv.enum(
MODBUS_WRITE_REGISTER_TYPE
),
cv.Optional(CONF_VALUE_TYPE, default="U_WORD"): cv.enum(SENSOR_VALUE_TYPE),
cv.Optional(CONF_WRITE_LAMBDA): cv.returning_lambda,
# 24 bits are the maximum value for fp32 before precison is lost
@@ -81,6 +86,7 @@ async def to_code(config):
byte_offset, reg_count = modbus_calc_properties(config)
var = cg.new_Pvariable(
config[CONF_ID],
config[CONF_REGISTER_TYPE],
config[CONF_ADDRESS],
byte_offset,
config[CONF_BITMASK],

View File

@@ -11,9 +11,9 @@ using value_to_data_t = std::function<float>(float);
class ModbusNumber : public number::Number, public Component, public SensorItem {
public:
ModbusNumber(uint16_t start_address, uint8_t offset, uint32_t bitmask, SensorValueType value_type, int register_count,
uint8_t skip_updates, bool force_new_range) {
this->register_type = ModbusRegisterType::HOLDING;
ModbusNumber(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask,
SensorValueType value_type, int register_count, uint8_t skip_updates, bool force_new_range) {
this->register_type = register_type;
this->start_address = start_address;
this->offset = offset;
this->bitmask = bitmask;

View File

@@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import select
from esphome.const import CONF_ADDRESS, CONF_ID, CONF_LAMBDA
from esphome.const import CONF_ADDRESS, CONF_ID, CONF_LAMBDA, CONF_OPTIMISTIC
from esphome.jsonschema import jschema_composite
from .. import (
@@ -79,6 +79,7 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_FORCE_NEW_RANGE, default=False): cv.boolean,
cv.Required(CONF_OPTIONSMAP): ensure_option_map(),
cv.Optional(CONF_USE_WRITE_MULTIPLE, default=False): cv.boolean,
cv.Optional(CONF_OPTIMISTIC, default=False): cv.boolean,
cv.Optional(CONF_LAMBDA): cv.returning_lambda,
cv.Optional(CONF_WRITE_LAMBDA): cv.returning_lambda,
},
@@ -112,6 +113,7 @@ async def to_code(config):
cg.add(parent.add_sensor_item(var))
cg.add(var.set_parent(parent))
cg.add(var.set_use_write_mutiple(config[CONF_USE_WRITE_MULTIPLE]))
cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
if CONF_LAMBDA in config:
template_ = await cg.process_lambda(

View File

@@ -80,6 +80,9 @@ void ModbusSelect::control(const std::string &value) {
}
parent_->queue_command(write_cmd);
if (this->optimistic_)
this->publish_state(value);
}
} // namespace modbus_controller

View File

@@ -32,6 +32,7 @@ class ModbusSelect : public Component, public select::Select, public SensorItem
void set_parent(ModbusController *const parent) { this->parent_ = parent; }
void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
void set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
void set_template(transform_func_t &&f) { this->transform_func_ = f; }
void set_write_template(write_transform_func_t &&f) { this->write_transform_func_ = f; }
@@ -43,6 +44,7 @@ class ModbusSelect : public Component, public select::Select, public SensorItem
std::vector<int64_t> mapping_;
ModbusController *parent_;
bool use_write_multiple_{false};
bool optimistic_{false};
optional<transform_func_t> transform_func_;
optional<write_transform_func_t> write_transform_func_;
};

View File

@@ -0,0 +1,23 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import esp32_ble_tracker
from esphome.const import CONF_ID
CODEOWNERS = ["@spbrogan"]
DEPENDENCIES = ["esp32_ble_tracker"]
mopeka_ble_ns = cg.esphome_ns.namespace("mopeka_ble")
MopekaListener = mopeka_ble_ns.class_(
"MopekaListener", esp32_ble_tracker.ESPBTDeviceListener
)
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(MopekaListener),
}
).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await esp32_ble_tracker.register_ble_device(var, config)

View File

@@ -0,0 +1,50 @@
#include "mopeka_ble.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
namespace esphome {
namespace mopeka_ble {
static const char *const TAG = "mopeka_ble";
static const uint8_t MANUFACTURER_DATA_LENGTH = 10;
static const uint16_t MANUFACTURER_ID = 0x0059;
/**
* Parse all incoming BLE payloads to see if it is a Mopeka BLE advertisement.
* Currently this supports the following products:
*
* Mopeka Pro Check.
* If the sync button is pressed, report the MAC so a user can add this as a sensor.
*/
bool MopekaListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
const auto &manu_datas = device.get_manufacturer_datas();
if (manu_datas.size() != 1) {
return false;
}
const auto &manu_data = manu_datas[0];
if (manu_data.data.size() != MANUFACTURER_DATA_LENGTH) {
return false;
}
if (manu_data.uuid != esp32_ble_tracker::ESPBTUUID::from_uint16(MANUFACTURER_ID)) {
return false;
}
if (this->parse_sync_button_(manu_data.data)) {
// button pressed
ESP_LOGI(TAG, "SENSOR FOUND: %s", device.address_str().c_str());
}
return false;
}
bool MopekaListener::parse_sync_button_(const std::vector<uint8_t> &message) { return (message[2] & 0x80) != 0; }
} // namespace mopeka_ble
} // namespace esphome
#endif

View File

@@ -0,0 +1,22 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#ifdef USE_ESP32
namespace esphome {
namespace mopeka_ble {
class MopekaListener : public esp32_ble_tracker::ESPBTDeviceListener {
public:
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override;
protected:
bool parse_sync_button_(const std::vector<uint8_t> &message);
};
} // namespace mopeka_ble
} // namespace esphome
#endif

View File

@@ -0,0 +1 @@
CODEOWNERS = ["@spbrogan"]

View File

@@ -0,0 +1,136 @@
#include "mopeka_pro_check.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
namespace esphome {
namespace mopeka_pro_check {
static const char *const TAG = "mopeka_pro_check";
static const uint8_t MANUFACTURER_DATA_LENGTH = 10;
static const uint16_t MANUFACTURER_ID = 0x0059;
static const double MOPEKA_LPG_COEF[] = {0.573045, -0.002822, -0.00000535}; // Magic numbers provided by Mopeka
void MopekaProCheck::dump_config() {
ESP_LOGCONFIG(TAG, "Mopeka Pro Check");
LOG_SENSOR(" ", "Level", this->level_);
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);
LOG_SENSOR(" ", "Reading Distance", this->distance_);
}
/**
* Main parse function that gets called for all ble advertisements.
* Check if advertisement is for our sensor and if so decode it and
* update the sensor state data.
*/
bool MopekaProCheck::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
if (device.address_uint64() != this->address_) {
return false;
}
ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", device.address_str().c_str());
const auto &manu_datas = device.get_manufacturer_datas();
if (manu_datas.size() != 1) {
ESP_LOGE(TAG, "Unexpected manu_datas size (%d)", manu_datas.size());
return false;
}
const auto &manu_data = manu_datas[0];
ESP_LOGVV(TAG, "Manufacturer data:");
for (const uint8_t byte : manu_data.data) {
ESP_LOGVV(TAG, "0x%02x", byte);
}
if (manu_data.data.size() != MANUFACTURER_DATA_LENGTH) {
ESP_LOGE(TAG, "Unexpected manu_data size (%d)", manu_data.data.size());
return false;
}
// Now parse the data - See Datasheet for definition
if (static_cast<SensorType>(manu_data.data[0]) != STANDARD_BOTTOM_UP) {
ESP_LOGE(TAG, "Unsupported Sensor Type (0x%X)", manu_data.data[0]);
return false;
}
// Get battery level first
if (this->battery_level_ != nullptr) {
uint8_t level = this->parse_battery_level_(manu_data.data);
this->battery_level_->publish_state(level);
}
// Get distance and level if either are sensors
if ((this->distance_ != nullptr) || (this->level_ != nullptr)) {
uint32_t distance_value = this->parse_distance_(manu_data.data);
SensorReadQuality quality_value = this->parse_read_quality_(manu_data.data);
ESP_LOGD(TAG, "Distance Sensor: Quality (0x%X) Distance (%dmm)", quality_value, distance_value);
if (quality_value < QUALITY_HIGH) {
ESP_LOGW(TAG, "Poor read quality.");
}
if (quality_value < QUALITY_MED) {
// if really bad reading set to 0
ESP_LOGW(TAG, "Setting distance to 0");
distance_value = 0;
}
// update distance sensor
if (this->distance_ != nullptr) {
this->distance_->publish_state(distance_value);
}
// update level sensor
if (this->level_ != nullptr) {
uint8_t tank_level = 0;
if (distance_value >= this->full_mm_) {
tank_level = 100; // cap at 100%
} else if (distance_value > this->empty_mm_) {
tank_level = ((100.0f / (this->full_mm_ - this->empty_mm_)) * (distance_value - this->empty_mm_));
}
this->level_->publish_state(tank_level);
}
}
// Get temperature of sensor
if (this->temperature_ != nullptr) {
uint8_t temp_in_c = this->parse_temperature_(manu_data.data);
this->temperature_->publish_state(temp_in_c);
}
return true;
}
uint8_t MopekaProCheck::parse_battery_level_(const std::vector<uint8_t> &message) {
float v = (float) ((message[1] & 0x7F) / 32.0f);
// convert voltage and scale for CR2032
float percent = (v - 2.2f) / 0.65f * 100.0f;
if (percent < 0.0f) {
return 0;
}
if (percent > 100.0f) {
return 100;
}
return (uint8_t) percent;
}
uint32_t MopekaProCheck::parse_distance_(const std::vector<uint8_t> &message) {
uint16_t raw = (message[4] * 256) + message[3];
double raw_level = raw & 0x3FFF;
double raw_t = (message[2] & 0x7F);
return (uint32_t)(raw_level * (MOPEKA_LPG_COEF[0] + MOPEKA_LPG_COEF[1] * raw_t + MOPEKA_LPG_COEF[2] * raw_t * raw_t));
}
uint8_t MopekaProCheck::parse_temperature_(const std::vector<uint8_t> &message) { return (message[2] & 0x7F) - 40; }
SensorReadQuality MopekaProCheck::parse_read_quality_(const std::vector<uint8_t> &message) {
return static_cast<SensorReadQuality>(message[4] >> 6);
}
} // namespace mopeka_pro_check
} // namespace esphome
#endif

View File

@@ -0,0 +1,58 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#ifdef USE_ESP32
namespace esphome {
namespace mopeka_pro_check {
enum SensorType {
STANDARD_BOTTOM_UP = 0x03,
TOP_DOWN_AIR_ABOVE = 0x04,
BOTTOM_UP_WATER = 0x05
// all other values are reserved
};
// Sensor read quality. If sensor is poorly placed or tank level
// gets too low the read quality will show and the distanace
// measurement may be inaccurate.
enum SensorReadQuality { QUALITY_HIGH = 0x3, QUALITY_MED = 0x2, QUALITY_LOW = 0x1, QUALITY_NONE = 0x0 };
class MopekaProCheck : public Component, public esp32_ble_tracker::ESPBTDeviceListener {
public:
void set_address(uint64_t address) { address_ = address; };
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
void set_level(sensor::Sensor *level) { level_ = level; };
void set_temperature(sensor::Sensor *temperature) { temperature_ = temperature; };
void set_battery_level(sensor::Sensor *bat) { battery_level_ = bat; };
void set_distance(sensor::Sensor *distance) { distance_ = distance; };
void set_tank_full(float full) { full_mm_ = full; };
void set_tank_empty(float empty) { empty_mm_ = empty; };
protected:
uint64_t address_;
sensor::Sensor *level_{nullptr};
sensor::Sensor *temperature_{nullptr};
sensor::Sensor *distance_{nullptr};
sensor::Sensor *battery_level_{nullptr};
uint32_t full_mm_;
uint32_t empty_mm_;
uint8_t parse_battery_level_(const std::vector<uint8_t> &message);
uint32_t parse_distance_(const std::vector<uint8_t> &message);
uint8_t parse_temperature_(const std::vector<uint8_t> &message);
SensorReadQuality parse_read_quality_(const std::vector<uint8_t> &message);
};
} // namespace mopeka_pro_check
} // namespace esphome
#endif

View File

@@ -0,0 +1,131 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, esp32_ble_tracker
from esphome.const import (
CONF_DISTANCE,
CONF_MAC_ADDRESS,
CONF_ID,
ICON_THERMOMETER,
ICON_RULER,
UNIT_PERCENT,
CONF_LEVEL,
CONF_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE,
UNIT_CELSIUS,
STATE_CLASS_MEASUREMENT,
CONF_BATTERY_LEVEL,
DEVICE_CLASS_BATTERY,
)
CONF_TANK_TYPE = "tank_type"
CONF_CUSTOM_DISTANCE_FULL = "custom_distance_full"
CONF_CUSTOM_DISTANCE_EMPTY = "custom_distance_empty"
ICON_PROPANE_TANK = "mdi:propane-tank"
TANK_TYPE_CUSTOM = "CUSTOM"
UNIT_MILLIMETER = "mm"
def small_distance(value):
"""small_distance is stored in mm"""
meters = cv.distance(value)
return meters * 1000
#
# Map of standard tank types to their
# empty and full distance values.
# Format is - tank name: (empty distance in mm, full distance in mm)
#
CONF_SUPPORTED_TANKS_MAP = {
TANK_TYPE_CUSTOM: (0, 100),
"20LB_V": (38, 254), # empty/full readings for 20lb US tank
"30LB_V": (38, 381),
"40LB_V": (38, 508),
}
CODEOWNERS = ["@spbrogan"]
DEPENDENCIES = ["esp32_ble_tracker"]
mopeka_pro_check_ns = cg.esphome_ns.namespace("mopeka_pro_check")
MopekaProCheck = mopeka_pro_check_ns.class_(
"MopekaProCheck", esp32_ble_tracker.ESPBTDeviceListener, cg.Component
)
CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(MopekaProCheck),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_CUSTOM_DISTANCE_FULL): small_distance,
cv.Optional(CONF_CUSTOM_DISTANCE_EMPTY): small_distance,
cv.Required(CONF_TANK_TYPE): cv.enum(CONF_SUPPORTED_TANKS_MAP, upper=True),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS,
icon=ICON_THERMOMETER,
accuracy_decimals=0,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_LEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT,
icon=ICON_PROPANE_TANK,
accuracy_decimals=0,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_DISTANCE): sensor.sensor_schema(
unit_of_measurement=UNIT_MILLIMETER,
icon=ICON_RULER,
accuracy_decimals=0,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT,
accuracy_decimals=0,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
),
}
)
.extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
.extend(cv.COMPONENT_SCHEMA)
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await esp32_ble_tracker.register_ble_device(var, config)
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
if config[CONF_TANK_TYPE] == TANK_TYPE_CUSTOM:
# Support custom tank min/max
if CONF_CUSTOM_DISTANCE_EMPTY in config:
cg.add(var.set_tank_empty(config[CONF_CUSTOM_DISTANCE_EMPTY]))
else:
cg.add(var.set_tank_empty(CONF_SUPPORTED_TANKS_MAP[TANK_TYPE_CUSTOM][0]))
if CONF_CUSTOM_DISTANCE_FULL in config:
cg.add(var.set_tank_full(config[CONF_CUSTOM_DISTANCE_FULL]))
else:
cg.add(var.set_tank_full(CONF_SUPPORTED_TANKS_MAP[TANK_TYPE_CUSTOM][1]))
else:
# Set the Tank empty and full based on map - User is requesting standard tank
t = config[CONF_TANK_TYPE]
cg.add(var.set_tank_empty(CONF_SUPPORTED_TANKS_MAP[t][0]))
cg.add(var.set_tank_full(CONF_SUPPORTED_TANKS_MAP[t][1]))
if CONF_TEMPERATURE in config:
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(var.set_temperature(sens))
if CONF_LEVEL in config:
sens = await sensor.new_sensor(config[CONF_LEVEL])
cg.add(var.set_level(sens))
if CONF_DISTANCE in config:
sens = await sensor.new_sensor(config[CONF_DISTANCE])
cg.add(var.set_distance(sens))
if CONF_BATTERY_LEVEL in config:
sens = await sensor.new_sensor(config[CONF_BATTERY_LEVEL])
cg.add(var.set_battery_level(sens))

View File

@@ -0,0 +1 @@
"""Support for MPC-6886."""

View File

@@ -0,0 +1,153 @@
#include "mpu6886.h"
#include "esphome/core/log.h"
namespace esphome {
namespace mpu6886 {
static const char *const TAG = "mpu6886";
const uint8_t MPU6886_REGISTER_WHO_AM_I = 0x75;
const uint8_t MPU6886_REGISTER_POWER_MANAGEMENT_1 = 0x6B;
const uint8_t MPU6886_REGISTER_GYRO_CONFIG = 0x1B;
const uint8_t MPU6886_REGISTER_ACCEL_CONFIG = 0x1C;
const uint8_t MPU6886_REGISTER_ACCEL_XOUT_H = 0x3B;
const uint8_t MPU6886_CLOCK_SOURCE_X_GYRO = 0b001;
const uint8_t MPU6886_SCALE_2000_DPS = 0b11;
const uint8_t MPU6886_WHO_AM_I_IDENTIFIER = 0x19;
const float MPU6886_SCALE_DPS_PER_DIGIT_2000 = 0.060975f;
const uint8_t MPU6886_RANGE_2G = 0b00;
const float MPU6886_RANGE_PER_DIGIT_2G = 0.000061f;
const uint8_t MPU6886_BIT_SLEEP_ENABLED = 6;
const uint8_t MPU6886_BIT_TEMPERATURE_DISABLED = 3;
const float GRAVITY_EARTH = 9.80665f;
// See https://github.com/m5stack/M5-Schematic/blob/master/datasheet/MPU-6886-000193%2Bv1.1_GHIC.PDF.pdf
// p. 43
const float TEMPERATURE_SENSITIVITY = 326.8;
const float TEMPERATURE_OFFSET = 25.0;
void MPU6886Component::setup() {
ESP_LOGCONFIG(TAG, "Setting up MPU6886...");
uint8_t who_am_i;
if (!this->read_byte(MPU6886_REGISTER_WHO_AM_I, &who_am_i) || who_am_i != MPU6886_WHO_AM_I_IDENTIFIER) {
this->mark_failed();
return;
}
ESP_LOGV(TAG, " Setting up Power Management...");
// Setup power management
uint8_t power_management;
if (!this->read_byte(MPU6886_REGISTER_POWER_MANAGEMENT_1, &power_management)) {
this->mark_failed();
return;
}
ESP_LOGV(TAG, " Input power_management: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(power_management));
// Set clock source - X-Gyro
power_management &= 0b11111000;
power_management |= MPU6886_CLOCK_SOURCE_X_GYRO;
// Disable sleep
power_management &= ~(1 << MPU6886_BIT_SLEEP_ENABLED);
// Enable temperature
power_management &= ~(1 << MPU6886_BIT_TEMPERATURE_DISABLED);
ESP_LOGV(TAG, " Output power_management: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(power_management));
if (!this->write_byte(MPU6886_REGISTER_POWER_MANAGEMENT_1, power_management)) {
this->mark_failed();
return;
}
ESP_LOGV(TAG, " Setting up Gyroscope Config...");
// Set scale - 2000DPS
uint8_t gyro_config;
if (!this->read_byte(MPU6886_REGISTER_GYRO_CONFIG, &gyro_config)) {
this->mark_failed();
return;
}
ESP_LOGV(TAG, " Input gyroscope_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
gyro_config &= 0b11100111;
gyro_config |= MPU6886_SCALE_2000_DPS << 3;
ESP_LOGV(TAG, " Output gyro_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
if (!this->write_byte(MPU6886_REGISTER_GYRO_CONFIG, gyro_config)) {
this->mark_failed();
return;
}
ESP_LOGV(TAG, " Setting up Accelerometer Config...");
// Set range - 2G
uint8_t accel_config;
if (!this->read_byte(MPU6886_REGISTER_ACCEL_CONFIG, &accel_config)) {
this->mark_failed();
return;
}
ESP_LOGV(TAG, " Input accelerometer_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
accel_config &= 0b11100111;
accel_config |= (MPU6886_RANGE_2G << 3);
ESP_LOGV(TAG, " Output accel_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
if (!this->write_byte(MPU6886_REGISTER_GYRO_CONFIG, gyro_config)) {
this->mark_failed();
return;
}
}
void MPU6886Component::dump_config() {
ESP_LOGCONFIG(TAG, "MPU6886:");
LOG_I2C_DEVICE(this);
if (this->is_failed()) {
ESP_LOGE(TAG, "Communication with MPU6886 failed!");
}
LOG_UPDATE_INTERVAL(this);
LOG_SENSOR(" ", "Acceleration X", this->accel_x_sensor_);
LOG_SENSOR(" ", "Acceleration Y", this->accel_y_sensor_);
LOG_SENSOR(" ", "Acceleration Z", this->accel_z_sensor_);
LOG_SENSOR(" ", "Gyro X", this->gyro_x_sensor_);
LOG_SENSOR(" ", "Gyro Y", this->gyro_y_sensor_);
LOG_SENSOR(" ", "Gyro Z", this->gyro_z_sensor_);
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
}
void MPU6886Component::update() {
ESP_LOGV(TAG, " Updating MPU6886...");
uint16_t raw_data[7];
if (!this->read_bytes_16(MPU6886_REGISTER_ACCEL_XOUT_H, raw_data, 7)) {
this->status_set_warning();
return;
}
auto *data = reinterpret_cast<int16_t *>(raw_data);
float accel_x = data[0] * MPU6886_RANGE_PER_DIGIT_2G * GRAVITY_EARTH;
float accel_y = data[1] * MPU6886_RANGE_PER_DIGIT_2G * GRAVITY_EARTH;
float accel_z = data[2] * MPU6886_RANGE_PER_DIGIT_2G * GRAVITY_EARTH;
float temperature = data[3] / TEMPERATURE_SENSITIVITY + TEMPERATURE_OFFSET;
float gyro_x = data[4] * MPU6886_SCALE_DPS_PER_DIGIT_2000;
float gyro_y = data[5] * MPU6886_SCALE_DPS_PER_DIGIT_2000;
float gyro_z = data[6] * MPU6886_SCALE_DPS_PER_DIGIT_2000;
ESP_LOGD(TAG,
"Got accel={x=%.3f m/s², y=%.3f m/s², z=%.3f m/s²}, "
"gyro={x=%.3f °/s, y=%.3f °/s, z=%.3f °/s}, temp=%.3f°C",
accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z, temperature);
if (this->accel_x_sensor_ != nullptr)
this->accel_x_sensor_->publish_state(accel_x);
if (this->accel_y_sensor_ != nullptr)
this->accel_y_sensor_->publish_state(accel_y);
if (this->accel_z_sensor_ != nullptr)
this->accel_z_sensor_->publish_state(accel_z);
if (this->temperature_sensor_ != nullptr)
this->temperature_sensor_->publish_state(temperature);
if (this->gyro_x_sensor_ != nullptr)
this->gyro_x_sensor_->publish_state(gyro_x);
if (this->gyro_y_sensor_ != nullptr)
this->gyro_y_sensor_->publish_state(gyro_y);
if (this->gyro_z_sensor_ != nullptr)
this->gyro_z_sensor_->publish_state(gyro_z);
this->status_clear_warning();
}
float MPU6886Component::get_setup_priority() const { return setup_priority::DATA; }
} // namespace mpu6886
} // namespace esphome

View File

@@ -0,0 +1,39 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace mpu6886 {
class MPU6886Component : public PollingComponent, public i2c::I2CDevice {
public:
void setup() override;
void dump_config() override;
void update() override;
float get_setup_priority() const override;
void set_accel_x_sensor(sensor::Sensor *accel_x_sensor) { accel_x_sensor_ = accel_x_sensor; }
void set_accel_y_sensor(sensor::Sensor *accel_y_sensor) { accel_y_sensor_ = accel_y_sensor; }
void set_accel_z_sensor(sensor::Sensor *accel_z_sensor) { accel_z_sensor_ = accel_z_sensor; }
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
void set_gyro_x_sensor(sensor::Sensor *gyro_x_sensor) { gyro_x_sensor_ = gyro_x_sensor; }
void set_gyro_y_sensor(sensor::Sensor *gyro_y_sensor) { gyro_y_sensor_ = gyro_y_sensor; }
void set_gyro_z_sensor(sensor::Sensor *gyro_z_sensor) { gyro_z_sensor_ = gyro_z_sensor; }
protected:
sensor::Sensor *accel_x_sensor_{nullptr};
sensor::Sensor *accel_y_sensor_{nullptr};
sensor::Sensor *accel_z_sensor_{nullptr};
sensor::Sensor *temperature_sensor_{nullptr};
sensor::Sensor *gyro_x_sensor_{nullptr};
sensor::Sensor *gyro_y_sensor_{nullptr};
sensor::Sensor *gyro_z_sensor_{nullptr};
};
;
} // namespace mpu6886
} // namespace esphome

View File

@@ -0,0 +1,85 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor
from esphome.const import (
CONF_ID,
CONF_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE,
ICON_BRIEFCASE_DOWNLOAD,
STATE_CLASS_MEASUREMENT,
UNIT_METER_PER_SECOND_SQUARED,
ICON_SCREEN_ROTATION,
UNIT_DEGREE_PER_SECOND,
UNIT_CELSIUS,
)
CODEOWNERS = ["@fabaff"]
DEPENDENCIES = ["i2c"]
CONF_ACCEL_X = "accel_x"
CONF_ACCEL_Y = "accel_y"
CONF_ACCEL_Z = "accel_z"
CONF_GYRO_X = "gyro_x"
CONF_GYRO_Y = "gyro_y"
CONF_GYRO_Z = "gyro_z"
mpu6886_ns = cg.esphome_ns.namespace("mpu6886")
MPU6886Component = mpu6886_ns.class_(
"MPU6886Component", cg.PollingComponent, i2c.I2CDevice
)
accel_schema = sensor.sensor_schema(
unit_of_measurement=UNIT_METER_PER_SECOND_SQUARED,
icon=ICON_BRIEFCASE_DOWNLOAD,
accuracy_decimals=2,
state_class=STATE_CLASS_MEASUREMENT,
)
gyro_schema = sensor.sensor_schema(
unit_of_measurement=UNIT_DEGREE_PER_SECOND,
icon=ICON_SCREEN_ROTATION,
accuracy_decimals=2,
state_class=STATE_CLASS_MEASUREMENT,
)
temperature_schema = sensor.sensor_schema(
unit_of_measurement=UNIT_CELSIUS,
accuracy_decimals=1,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
)
CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(MPU6886Component),
cv.Optional(CONF_ACCEL_X): accel_schema,
cv.Optional(CONF_ACCEL_Y): accel_schema,
cv.Optional(CONF_ACCEL_Z): accel_schema,
cv.Optional(CONF_GYRO_X): gyro_schema,
cv.Optional(CONF_GYRO_Y): gyro_schema,
cv.Optional(CONF_GYRO_Z): gyro_schema,
cv.Optional(CONF_TEMPERATURE): temperature_schema,
}
)
.extend(cv.polling_component_schema("60s"))
.extend(i2c.i2c_device_schema(0x68))
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
for d in ["x", "y", "z"]:
accel_key = f"accel_{d}"
if accel_key in config:
sens = await sensor.new_sensor(config[accel_key])
cg.add(getattr(var, f"set_accel_{d}_sensor")(sens))
accel_key = f"gyro_{d}"
if accel_key in config:
sens = await sensor.new_sensor(config[accel_key])
cg.add(getattr(var, f"set_gyro_{d}_sensor")(sens))
if CONF_TEMPERATURE in config:
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(var.set_temperature_sensor(sens))

View File

@@ -1,5 +1,4 @@
#include "mqtt_client.h"
#define USE_MQTT
#ifdef USE_MQTT

View File

@@ -6,6 +6,47 @@ namespace pmsx003 {
static const char *const TAG = "pmsx003";
void PMSX003Component::set_pm_1_0_std_sensor(sensor::Sensor *pm_1_0_std_sensor) {
pm_1_0_std_sensor_ = pm_1_0_std_sensor;
}
void PMSX003Component::set_pm_2_5_std_sensor(sensor::Sensor *pm_2_5_std_sensor) {
pm_2_5_std_sensor_ = pm_2_5_std_sensor;
}
void PMSX003Component::set_pm_10_0_std_sensor(sensor::Sensor *pm_10_0_std_sensor) {
pm_10_0_std_sensor_ = pm_10_0_std_sensor;
}
void PMSX003Component::set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor) { pm_1_0_sensor_ = pm_1_0_sensor; }
void PMSX003Component::set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor) { pm_2_5_sensor_ = pm_2_5_sensor; }
void PMSX003Component::set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor) { pm_10_0_sensor_ = pm_10_0_sensor; }
void PMSX003Component::set_pm_particles_03um_sensor(sensor::Sensor *pm_particles_03um_sensor) {
pm_particles_03um_sensor_ = pm_particles_03um_sensor;
}
void PMSX003Component::set_pm_particles_05um_sensor(sensor::Sensor *pm_particles_05um_sensor) {
pm_particles_05um_sensor_ = pm_particles_05um_sensor;
}
void PMSX003Component::set_pm_particles_10um_sensor(sensor::Sensor *pm_particles_10um_sensor) {
pm_particles_10um_sensor_ = pm_particles_10um_sensor;
}
void PMSX003Component::set_pm_particles_25um_sensor(sensor::Sensor *pm_particles_25um_sensor) {
pm_particles_25um_sensor_ = pm_particles_25um_sensor;
}
void PMSX003Component::set_pm_particles_50um_sensor(sensor::Sensor *pm_particles_50um_sensor) {
pm_particles_50um_sensor_ = pm_particles_50um_sensor;
}
void PMSX003Component::set_pm_particles_100um_sensor(sensor::Sensor *pm_particles_100um_sensor) {
pm_particles_100um_sensor_ = pm_particles_100um_sensor;
}
void PMSX003Component::set_temperature_sensor(sensor::Sensor *temperature_sensor) {
temperature_sensor_ = temperature_sensor;
}
void PMSX003Component::set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
void PMSX003Component::set_formaldehyde_sensor(sensor::Sensor *formaldehyde_sensor) {
formaldehyde_sensor_ = formaldehyde_sensor;
}
void PMSX003Component::loop() {
const uint32_t now = millis();
if (now - this->last_transmission_ >= 500) {
@@ -122,12 +163,12 @@ void PMSX003Component::parse_data_() {
uint16_t pm_2_5_concentration = this->get_16_bit_uint_(12);
uint16_t pm_10_0_concentration = this->get_16_bit_uint_(14);
uint16_t pm_0_3um = this->get_16_bit_uint_(16);
uint16_t pm_0_5um = this->get_16_bit_uint_(18);
uint16_t pm_1_0um = this->get_16_bit_uint_(20);
uint16_t pm_2_5um = this->get_16_bit_uint_(22);
uint16_t pm_5_0um = this->get_16_bit_uint_(24);
uint16_t pm_10_0um = this->get_16_bit_uint_(26);
uint16_t pm_particles_03um = this->get_16_bit_uint_(16);
uint16_t pm_particles_05um = this->get_16_bit_uint_(18);
uint16_t pm_particles_10um = this->get_16_bit_uint_(20);
uint16_t pm_particles_25um = this->get_16_bit_uint_(22);
uint16_t pm_particles_50um = this->get_16_bit_uint_(24);
uint16_t pm_particles_100um = this->get_16_bit_uint_(26);
ESP_LOGD(TAG,
"Got PM1.0 Concentration: %u µg/m^3, PM2.5 Concentration %u µg/m^3, PM10.0 Concentration: %u µg/m^3",
@@ -147,18 +188,18 @@ void PMSX003Component::parse_data_() {
if (this->pm_10_0_sensor_ != nullptr)
this->pm_10_0_sensor_->publish_state(pm_10_0_concentration);
if (this->pm_0_3um_sensor_ != nullptr)
this->pm_0_3um_sensor_->publish_state(pm_0_3um);
if (this->pm_0_5um_sensor_ != nullptr)
this->pm_0_5um_sensor_->publish_state(pm_0_5um);
if (this->pm_1_0um_sensor_ != nullptr)
this->pm_1_0um_sensor_->publish_state(pm_1_0um);
if (this->pm_2_5um_sensor_ != nullptr)
this->pm_2_5um_sensor_->publish_state(pm_2_5um);
if (this->pm_5_0um_sensor_ != nullptr)
this->pm_5_0um_sensor_->publish_state(pm_5_0um);
if (this->pm_10_0um_sensor_ != nullptr)
this->pm_10_0um_sensor_->publish_state(pm_10_0um);
if (this->pm_particles_03um_sensor_ != nullptr)
this->pm_particles_03um_sensor_->publish_state(pm_particles_03um);
if (this->pm_particles_05um_sensor_ != nullptr)
this->pm_particles_05um_sensor_->publish_state(pm_particles_05um);
if (this->pm_particles_10um_sensor_ != nullptr)
this->pm_particles_10um_sensor_->publish_state(pm_particles_10um);
if (this->pm_particles_25um_sensor_ != nullptr)
this->pm_particles_25um_sensor_->publish_state(pm_particles_25um);
if (this->pm_particles_50um_sensor_ != nullptr)
this->pm_particles_50um_sensor_->publish_state(pm_particles_50um);
if (this->pm_particles_100um_sensor_ != nullptr)
this->pm_particles_100um_sensor_->publish_state(pm_particles_100um);
break;
}
case PMSX003_TYPE_5003T: {
@@ -192,12 +233,12 @@ void PMSX003Component::dump_config() {
LOG_SENSOR(" ", "PM2.5", this->pm_2_5_sensor_);
LOG_SENSOR(" ", "PM10.0", this->pm_10_0_sensor_);
LOG_SENSOR(" ", "PM0.3um", this->pm_0_3um_sensor_);
LOG_SENSOR(" ", "PM0.5um", this->pm_0_5um_sensor_);
LOG_SENSOR(" ", "PM1.0um", this->pm_1_0um_sensor_);
LOG_SENSOR(" ", "PM2.5um", this->pm_2_5um_sensor_);
LOG_SENSOR(" ", "PM5.0um", this->pm_5_0um_sensor_);
LOG_SENSOR(" ", "PM10.0um", this->pm_10_0um_sensor_);
LOG_SENSOR(" ", "PM0.3um", this->pm_particles_03um_sensor_);
LOG_SENSOR(" ", "PM0.5um", this->pm_particles_05um_sensor_);
LOG_SENSOR(" ", "PM1.0um", this->pm_particles_10um_sensor_);
LOG_SENSOR(" ", "PM2.5um", this->pm_particles_25um_sensor_);
LOG_SENSOR(" ", "PM5.0um", this->pm_particles_50um_sensor_);
LOG_SENSOR(" ", "PM10.0um", this->pm_particles_100um_sensor_);
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);

View File

@@ -14,13 +14,6 @@ enum PMSX003Type {
PMSX003_TYPE_5003S,
};
#define PMSX003_SENSOR(key) \
protected: \
sensor::Sensor *key##_; \
\
public: \
void set_##key##_sensor(sensor::Sensor *sensor) { this->key##_ = sensor; }
class PMSX003Component : public uart::UARTDevice, public Component {
public:
PMSX003Component() = default;
@@ -30,27 +23,24 @@ class PMSX003Component : public uart::UARTDevice, public Component {
void set_type(PMSX003Type type) { type_ = type; }
// "Standard Particle"
PMSX003_SENSOR(pm_1_0_std)
PMSX003_SENSOR(pm_2_5_std)
PMSX003_SENSOR(pm_10_0_std)
void set_pm_1_0_std_sensor(sensor::Sensor *pm_1_0_std_sensor);
void set_pm_2_5_std_sensor(sensor::Sensor *pm_2_5_std_sensor);
void set_pm_10_0_std_sensor(sensor::Sensor *pm_10_0_std_sensor);
// "Under Atmospheric Pressure"
PMSX003_SENSOR(pm_1_0)
PMSX003_SENSOR(pm_2_5)
PMSX003_SENSOR(pm_10_0)
void set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor);
void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor);
void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor);
// Particle counts by size
PMSX003_SENSOR(pm_0_3um)
PMSX003_SENSOR(pm_0_5um)
PMSX003_SENSOR(pm_1_0um)
PMSX003_SENSOR(pm_2_5um)
PMSX003_SENSOR(pm_5_0um)
PMSX003_SENSOR(pm_10_0um)
void set_pm_particles_03um_sensor(sensor::Sensor *pm_particles_03um_sensor);
void set_pm_particles_05um_sensor(sensor::Sensor *pm_particles_05um_sensor);
void set_pm_particles_10um_sensor(sensor::Sensor *pm_particles_10um_sensor);
void set_pm_particles_25um_sensor(sensor::Sensor *pm_particles_25um_sensor);
void set_pm_particles_50um_sensor(sensor::Sensor *pm_particles_50um_sensor);
void set_pm_particles_100um_sensor(sensor::Sensor *pm_particles_100um_sensor);
PMSX003_SENSOR(temperature)
PMSX003_SENSOR(humidity)
PMSX003_SENSOR(formaldehyde)
void set_temperature_sensor(sensor::Sensor *temperature_sensor);
void set_humidity_sensor(sensor::Sensor *humidity_sensor);
void set_formaldehyde_sensor(sensor::Sensor *formaldehyde_sensor);
protected:
optional<bool> check_byte_();
@@ -61,6 +51,28 @@ class PMSX003Component : public uart::UARTDevice, public Component {
uint8_t data_index_{0};
uint32_t last_transmission_{0};
PMSX003Type type_;
// "Standard Particle"
sensor::Sensor *pm_1_0_std_sensor_{nullptr};
sensor::Sensor *pm_2_5_std_sensor_{nullptr};
sensor::Sensor *pm_10_0_std_sensor_{nullptr};
// "Under Atmospheric Pressure"
sensor::Sensor *pm_1_0_sensor_{nullptr};
sensor::Sensor *pm_2_5_sensor_{nullptr};
sensor::Sensor *pm_10_0_sensor_{nullptr};
// Particle counts by size
sensor::Sensor *pm_particles_03um_sensor_{nullptr};
sensor::Sensor *pm_particles_05um_sensor_{nullptr};
sensor::Sensor *pm_particles_10um_sensor_{nullptr};
sensor::Sensor *pm_particles_25um_sensor_{nullptr};
sensor::Sensor *pm_particles_50um_sensor_{nullptr};
sensor::Sensor *pm_particles_100um_sensor_{nullptr};
sensor::Sensor *temperature_sensor_{nullptr};
sensor::Sensor *humidity_sensor_{nullptr};
sensor::Sensor *formaldehyde_sensor_{nullptr};
};
} // namespace pmsx003

View File

@@ -68,24 +68,6 @@ def validate_pmsx003_sensors(value):
return value
SENSORS = [
CONF_PM_1_0_STD,
CONF_PM_2_5_STD,
CONF_PM_10_0_STD,
CONF_PM_1_0,
CONF_PM_2_5,
CONF_PM_10_0,
CONF_PM_0_3UM,
CONF_PM_0_5UM,
CONF_PM_1_0UM,
CONF_PM_2_5UM,
CONF_PM_5_0UM,
CONF_PM_10_0UM,
CONF_TEMPERATURE,
CONF_HUMIDITY,
CONF_FORMALDEHYDE,
]
CONFIG_SCHEMA = (
cv.Schema(
{
@@ -189,7 +171,62 @@ async def to_code(config):
cg.add(var.set_type(config[CONF_TYPE]))
for key in SENSORS:
if key in config:
sens = await sensor.new_sensor(config[key])
cg.add(getattr(var, f"set_{key}_sensor")(sens))
if CONF_PM_1_0_STD in config:
sens = await sensor.new_sensor(config[CONF_PM_1_0_STD])
cg.add(var.set_pm_1_0_std_sensor(sens))
if CONF_PM_2_5_STD in config:
sens = await sensor.new_sensor(config[CONF_PM_2_5_STD])
cg.add(var.set_pm_2_5_std_sensor(sens))
if CONF_PM_10_0_STD in config:
sens = await sensor.new_sensor(config[CONF_PM_10_0_STD])
cg.add(var.set_pm_10_0_std_sensor(sens))
if CONF_PM_1_0 in config:
sens = await sensor.new_sensor(config[CONF_PM_1_0])
cg.add(var.set_pm_1_0_sensor(sens))
if CONF_PM_2_5 in config:
sens = await sensor.new_sensor(config[CONF_PM_2_5])
cg.add(var.set_pm_2_5_sensor(sens))
if CONF_PM_10_0 in config:
sens = await sensor.new_sensor(config[CONF_PM_10_0])
cg.add(var.set_pm_10_0_sensor(sens))
if CONF_PM_0_3UM in config:
sens = await sensor.new_sensor(config[CONF_PM_0_3UM])
cg.add(var.set_pm_particles_03um_sensor(sens))
if CONF_PM_0_5UM in config:
sens = await sensor.new_sensor(config[CONF_PM_0_5UM])
cg.add(var.set_pm_particles_05um_sensor(sens))
if CONF_PM_1_0UM in config:
sens = await sensor.new_sensor(config[CONF_PM_1_0UM])
cg.add(var.set_pm_particles_10um_sensor(sens))
if CONF_PM_2_5UM in config:
sens = await sensor.new_sensor(config[CONF_PM_2_5UM])
cg.add(var.set_pm_particles_25um_sensor(sens))
if CONF_PM_5_0UM in config:
sens = await sensor.new_sensor(config[CONF_PM_5_0UM])
cg.add(var.set_pm_particles_50um_sensor(sens))
if CONF_PM_10_0UM in config:
sens = await sensor.new_sensor(config[CONF_PM_10_0UM])
cg.add(var.set_pm_particles_100um_sensor(sens))
if CONF_TEMPERATURE in config:
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(var.set_temperature_sensor(sens))
if CONF_HUMIDITY in config:
sens = await sensor.new_sensor(config[CONF_HUMIDITY])
cg.add(var.set_humidity_sensor(sens))
if CONF_FORMALDEHYDE in config:
sens = await sensor.new_sensor(config[CONF_FORMALDEHYDE])
cg.add(var.set_formaldehyde_sensor(sens))

View File

@@ -12,18 +12,53 @@ void PulseMeterSensor::setup() {
this->pin_->attach_interrupt(PulseMeterSensor::gpio_intr, this, gpio::INTERRUPT_ANY_EDGE);
this->last_detected_edge_us_ = 0;
this->last_valid_edge_us_ = 0;
this->last_valid_low_edge_us_ = 0;
this->last_valid_high_edge_us_ = 0;
this->sensor_is_high_ = this->isr_pin_.digital_read();
}
void PulseMeterSensor::loop() {
const uint32_t now = micros();
// Check to see if we should filter this edge out
if (this->filter_mode_ == FILTER_EDGE) {
if ((this->last_detected_edge_us_ - this->last_valid_high_edge_us_) >= this->filter_us_) {
// Don't measure the first valid pulse (we need at least two pulses to measure the width)
if (this->last_valid_high_edge_us_ != 0) {
this->pulse_width_us_ = (this->last_detected_edge_us_ - this->last_valid_high_edge_us_);
}
this->total_pulses_++;
this->last_valid_high_edge_us_ = this->last_detected_edge_us_;
}
} else {
// Make sure the signal has been stable long enough
if ((now - this->last_detected_edge_us_) >= this->filter_us_) {
// Only consider HIGH pulses and "new" edges if sensor state is LOW
if (!this->sensor_is_high_ && this->isr_pin_.digital_read() &&
(this->last_detected_edge_us_ != this->last_valid_high_edge_us_)) {
// Don't measure the first valid pulse (we need at least two pulses to measure the width)
if (this->last_valid_high_edge_us_ != 0) {
this->pulse_width_us_ = (this->last_detected_edge_us_ - this->last_valid_high_edge_us_);
}
this->sensor_is_high_ = true;
this->total_pulses_++;
this->last_valid_high_edge_us_ = this->last_detected_edge_us_;
}
// Only consider LOW pulses and "new" edges if sensor state is HIGH
else if (this->sensor_is_high_ && !this->isr_pin_.digital_read() &&
(this->last_detected_edge_us_ != this->last_valid_low_edge_us_)) {
this->sensor_is_high_ = false;
this->last_valid_low_edge_us_ = this->last_detected_edge_us_;
}
}
}
// If we've exceeded our timeout interval without receiving any pulses, assume 0 pulses/min until
// we get at least two valid pulses.
const uint32_t time_since_valid_edge_us = now - this->last_valid_edge_us_;
if ((this->last_valid_edge_us_ != 0) && (time_since_valid_edge_us > this->timeout_us_)) {
const uint32_t time_since_valid_edge_us = now - this->last_valid_high_edge_us_;
if ((this->last_valid_high_edge_us_ != 0) && (time_since_valid_edge_us > this->timeout_us_) &&
(this->pulse_width_us_ != 0)) {
ESP_LOGD(TAG, "No pulse detected for %us, assuming 0 pulses/min", time_since_valid_edge_us / 1000000);
this->last_valid_edge_us_ = 0;
this->pulse_width_us_ = 0;
}
@@ -52,7 +87,11 @@ void PulseMeterSensor::set_total_pulses(uint32_t pulses) { this->total_pulses_ =
void PulseMeterSensor::dump_config() {
LOG_SENSOR("", "Pulse Meter", this);
LOG_PIN(" Pin: ", this->pin_);
ESP_LOGCONFIG(TAG, " Filtering pulses shorter than %u µs", this->filter_us_);
if (this->filter_mode_ == FILTER_EDGE) {
ESP_LOGCONFIG(TAG, " Filtering rising edges less than %u µs apart", this->filter_us_);
} else {
ESP_LOGCONFIG(TAG, " Filtering pulses shorter than %u µs", this->filter_us_);
}
ESP_LOGCONFIG(TAG, " Assuming 0 pulses/min after not receiving a pulse for %us", this->timeout_us_ / 1000000);
}
@@ -62,23 +101,14 @@ void IRAM_ATTR PulseMeterSensor::gpio_intr(PulseMeterSensor *sensor) {
// Get the current time before we do anything else so the measurements are consistent
const uint32_t now = micros();
// We only look at rising edges
if (!sensor->isr_pin_.digital_read()) {
return;
}
// Check to see if we should filter this edge out
if ((now - sensor->last_detected_edge_us_) >= sensor->filter_us_) {
// Don't measure the first valid pulse (we need at least two pulses to measure the width)
if (sensor->last_valid_edge_us_ != 0) {
sensor->pulse_width_us_ = (now - sensor->last_valid_edge_us_);
// We only look at rising edges in EDGE mode, and all edges in PULSE mode
if (sensor->filter_mode_ == FILTER_EDGE) {
if (sensor->isr_pin_.digital_read()) {
sensor->last_detected_edge_us_ = now;
}
sensor->total_pulses_++;
sensor->last_valid_edge_us_ = now;
} else {
sensor->last_detected_edge_us_ = now;
}
sensor->last_detected_edge_us_ = now;
}
} // namespace pulse_meter

View File

@@ -10,8 +10,14 @@ namespace pulse_meter {
class PulseMeterSensor : public sensor::Sensor, public Component {
public:
enum InternalFilterMode {
FILTER_EDGE = 0,
FILTER_PULSE,
};
void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
void set_filter_us(uint32_t filter) { this->filter_us_ = filter; }
void set_filter_mode(InternalFilterMode mode) { this->filter_mode_ = mode; }
void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; }
@@ -30,14 +36,17 @@ class PulseMeterSensor : public sensor::Sensor, public Component {
uint32_t filter_us_ = 0;
uint32_t timeout_us_ = 1000000UL * 60UL * 5UL;
sensor::Sensor *total_sensor_ = nullptr;
InternalFilterMode filter_mode_{FILTER_EDGE};
Deduplicator<uint32_t> pulse_width_dedupe_;
Deduplicator<uint32_t> total_dedupe_;
volatile uint32_t last_detected_edge_us_ = 0;
volatile uint32_t last_valid_edge_us_ = 0;
volatile uint32_t last_valid_low_edge_us_ = 0;
volatile uint32_t last_valid_high_edge_us_ = 0;
volatile uint32_t pulse_width_us_ = 0;
volatile uint32_t total_pulses_ = 0;
volatile bool sensor_is_high_ = false;
};
} // namespace pulse_meter

View File

@@ -5,6 +5,7 @@ from esphome.components import sensor
from esphome.const import (
CONF_ID,
CONF_INTERNAL_FILTER,
CONF_INTERNAL_FILTER_MODE,
CONF_PIN,
CONF_NUMBER,
CONF_TIMEOUT,
@@ -18,14 +19,21 @@ from esphome.const import (
)
from esphome.core import CORE
CODEOWNERS = ["@stevebaxter"]
CODEOWNERS = ["@stevebaxter", "@cstaahl"]
pulse_meter_ns = cg.esphome_ns.namespace("pulse_meter")
PulseMeterSensor = pulse_meter_ns.class_(
"PulseMeterSensor", sensor.Sensor, cg.Component
)
PulseMeterInternalFilterMode = PulseMeterSensor.enum("InternalFilterMode")
FILTER_MODES = {
"EDGE": PulseMeterInternalFilterMode.FILTER_EDGE,
"PULSE": PulseMeterInternalFilterMode.FILTER_PULSE,
}
SetTotalPulsesAction = pulse_meter_ns.class_("SetTotalPulsesAction", automation.Action)
@@ -66,6 +74,9 @@ CONFIG_SCHEMA = sensor.sensor_schema(
accuracy_decimals=0,
state_class=STATE_CLASS_TOTAL_INCREASING,
),
cv.Optional(CONF_INTERNAL_FILTER_MODE, default="EDGE"): cv.enum(
FILTER_MODES, upper=True
),
}
)
@@ -78,6 +89,7 @@ async def to_code(config):
cg.add(var.set_pin(pin))
cg.add(var.set_filter_us(config[CONF_INTERNAL_FILTER]))
cg.add(var.set_timeout_us(config[CONF_TIMEOUT]))
cg.add(var.set_filter_mode(config[CONF_INTERNAL_FILTER_MODE]))
if CONF_TOTAL in config:
sens = await sensor.new_sensor(config[CONF_TOTAL])

View File

@@ -27,6 +27,8 @@ from esphome.const import (
CONF_CARRIER_FREQUENCY,
CONF_RC_CODE_1,
CONF_RC_CODE_2,
CONF_MAGNITUDE,
CONF_WAND_ID,
CONF_LEVEL,
)
from esphome.core import coroutine
@@ -391,6 +393,54 @@ async def lg_action(var, config, args):
cg.add(var.set_nbits(template_))
# MagiQuest
(
MagiQuestData,
MagiQuestBinarySensor,
MagiQuestTrigger,
MagiQuestAction,
MagiQuestDumper,
) = declare_protocol("MagiQuest")
MAGIQUEST_SCHEMA = cv.Schema(
{
cv.Required(CONF_WAND_ID): cv.hex_uint32_t,
cv.Optional(CONF_MAGNITUDE, default=0xFFFF): cv.hex_uint16_t,
}
)
@register_binary_sensor("magiquest", MagiQuestBinarySensor, MAGIQUEST_SCHEMA)
def magiquest_binary_sensor(var, config):
cg.add(
var.set_data(
cg.StructInitializer(
MagiQuestData,
("magnitude", config[CONF_MAGNITUDE]),
("wand_id", config[CONF_WAND_ID]),
)
)
)
@register_trigger("magiquest", MagiQuestTrigger, MagiQuestData)
def magiquest_trigger(var, config):
pass
@register_dumper("magiquest", MagiQuestDumper)
def magiquest_dumper(var, config):
pass
@register_action("magiquest", MagiQuestAction, MAGIQUEST_SCHEMA)
async def magiquest_action(var, config, args):
template_ = await cg.templatable(config[CONF_WAND_ID], args, cg.uint32)
cg.add(var.set_wand_id(template_))
template_ = await cg.templatable(config[CONF_MAGNITUDE], args, cg.uint16)
cg.add(var.set_magnitude(template_))
# NEC
NECData, NECBinarySensor, NECTrigger, NECAction, NECDumper = declare_protocol("NEC")
NEC_SCHEMA = cv.Schema(

View File

@@ -0,0 +1,83 @@
#include "magiquest_protocol.h"
#include "esphome/core/log.h"
/* Based on protocol analysis from
* https://arduino-irremote.github.io/Arduino-IRremote/ir__MagiQuest_8cpp_source.html
*/
namespace esphome {
namespace remote_base {
static const char *const TAG = "remote.magiquest";
static const uint32_t MAGIQUEST_UNIT = 288; // us
static const uint32_t MAGIQUEST_ONE_MARK = 2 * MAGIQUEST_UNIT;
static const uint32_t MAGIQUEST_ONE_SPACE = 2 * MAGIQUEST_UNIT;
static const uint32_t MAGIQUEST_ZERO_MARK = MAGIQUEST_UNIT;
static const uint32_t MAGIQUEST_ZERO_SPACE = 3 * MAGIQUEST_UNIT;
void MagiQuestProtocol::encode(RemoteTransmitData *dst, const MagiQuestData &data) {
dst->reserve(101); // 2 start bits, 48 data bits, 1 stop bit
dst->set_carrier_frequency(38000);
// 2 start bits
dst->item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE);
dst->item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE);
for (uint32_t mask = 1 << 31; mask; mask >>= 1) {
if (data.wand_id & mask) {
dst->item(MAGIQUEST_ONE_MARK, MAGIQUEST_ONE_SPACE);
} else {
dst->item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE);
}
}
for (uint16_t mask = 1 << 15; mask; mask >>= 1) {
if (data.magnitude & mask) {
dst->item(MAGIQUEST_ONE_MARK, MAGIQUEST_ONE_SPACE);
} else {
dst->item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE);
}
}
dst->mark(MAGIQUEST_UNIT);
}
optional<MagiQuestData> MagiQuestProtocol::decode(RemoteReceiveData src) {
MagiQuestData data{
.magnitude = 0,
.wand_id = 0,
};
// Two start bits
if (!src.expect_item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE) ||
!src.expect_item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE)) {
return {};
}
for (uint32_t mask = 1 << 31; mask; mask >>= 1) {
if (src.expect_item(MAGIQUEST_ONE_MARK, MAGIQUEST_ONE_SPACE)) {
data.wand_id |= mask;
} else if (src.expect_item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE)) {
data.wand_id &= ~mask;
} else {
return {};
}
}
for (uint16_t mask = 1 << 15; mask; mask >>= 1) {
if (src.expect_item(MAGIQUEST_ONE_MARK, MAGIQUEST_ONE_SPACE)) {
data.magnitude |= mask;
} else if (src.expect_item(MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE)) {
data.magnitude &= ~mask;
} else {
return {};
}
}
src.expect_mark(MAGIQUEST_UNIT);
return data;
}
void MagiQuestProtocol::dump(const MagiQuestData &data) {
ESP_LOGD(TAG, "Received MagiQuest: wand_id=0x%08X, magnitude=0x%04X", data.wand_id, data.magnitude);
}
} // namespace remote_base
} // namespace esphome

View File

@@ -0,0 +1,50 @@
#pragma once
#include "remote_base.h"
/* Based on protocol analysis from
* https://arduino-irremote.github.io/Arduino-IRremote/ir__MagiQuest_8cpp_source.html
*/
namespace esphome {
namespace remote_base {
struct MagiQuestData {
uint16_t magnitude;
uint32_t wand_id;
bool operator==(const MagiQuestData &rhs) const {
// Treat 0xffff as a special, wildcard magnitude
// In testing, the wand never produces this value, and this allows us to match
// on just the wand_id if wanted.
if (rhs.wand_id != this->wand_id) {
return false;
}
return (this->wand_id == 0xffff || rhs.wand_id == 0xffff || this->wand_id == rhs.wand_id);
}
};
class MagiQuestProtocol : public RemoteProtocol<MagiQuestData> {
public:
void encode(RemoteTransmitData *dst, const MagiQuestData &data) override;
optional<MagiQuestData> decode(RemoteReceiveData src) override;
void dump(const MagiQuestData &data) override;
};
DECLARE_REMOTE_PROTOCOL(MagiQuest)
template<typename... Ts> class MagiQuestAction : public RemoteTransmitterActionBase<Ts...> {
public:
TEMPLATABLE_VALUE(uint16_t, magnitude)
TEMPLATABLE_VALUE(uint32_t, wand_id)
void encode(RemoteTransmitData *dst, Ts... x) override {
MagiQuestData data{};
data.magnitude = this->magnitude_.value(x...);
data.wand_id = this->wand_id_.value(x...);
MagiQuestProtocol().encode(dst, data);
}
};
} // namespace remote_base
} // namespace esphome

Some files were not shown because too many files have changed in this diff Show More