Add support for multiple light bars/remotes (#3), bump to version 0.2

This commit is contained in:
Erik Borowski
2024-12-01 02:47:01 +01:00
parent a0b246aae1
commit 8901d409ca
12 changed files with 658 additions and 243 deletions

View File

@ -19,6 +19,7 @@ This project would not have been possible without the work of these amazing peop
- The light bar is represented as a `light` entity
- The remote is represented as a `sensor` entity
- Actions taken on the remote also trigger `device_automation`s. This allows you to trigger automations in Home Assistant based on actions taken on the remote
- Use multiple light bars or remotes with ease! Each one can be controlled/monitored individually and will also have separate entities in Home Assistant.
## Requirements
@ -54,14 +55,14 @@ Connect the nRF24 module to the ESP32 as follows. At least these pins work for m
- [RF24](https://nrf24.github.io/RF24/) by TMRh20, _Version 1.4.10_
5. Select your serial port and board. Upload the sketch to your ESP32.
6. Inspect the serial monitor (115200 baud). If everything is set up correctly, the ESP32 should connect to your WiFi and MQTT broker.
7. At this point, you probably don't know the serial of your remote. Just press/turn the remote and you should see the serial in the serial monitor. (E.g. `[Radio] Ignoring package with not matching serial: 0x7B7E12`) Copy it and paste it into the `config.h` file.
7. At this point, you probably don't know the serial of your remote. Just press/turn the remote and you should see the serial in the serial monitor. (E.g. `[Radio] Ignoring package with not matching serial: 0x7B7E12`) Copy it and paste it into the `config.h` file in the "Remotes" section.
8. Upload the sketch again.
9. If your Home Assistant has the MQTT integration set up, the light bar should be discovered automatically.
10. Enjoy controlling your light bar via MQTT!
### 3. Pairing Light bar and ESP32 (optional)
If you opt to use different values for `INCOMING_SERIAL` and `OUTGOING_SERIAL` in the `config.h` file, you need to pair the light bar with the ESP32. To do this, power-cycle the light bar and within 10 seconds either press the "Pair" button in Home Assistant or send a message to the pair topic (see below). The light bar should blink a few times if the pairing was successful.
If you opt to use different values for the serial and remote in the `config.h` file, you need to pair the light bar with the ESP32. To do this, power-cycle the light bar and within 10 seconds either press the "Pair" button in Home Assistant or send a message to the pair topic (see below). The light bar should blink a few times if the pairing was successful.
## Usage
@ -76,9 +77,11 @@ All MQTT topics are prefixed with a root topic. You can set this root topic in t
...
```
In order to be able to control multiple light bars or remotes, each one has their own sub-topics, starting with the chosen serial (all lower case).
#### Light Bar
To control the light bar, you can send messages to the following topic: `<MQTT_ROOT_TOPIC>/l2m_<MAC of your ESP32>/lightbar/command` e.g. `lightbar2mqtt/l2m_1234567890AB/lightbar/command`. The payload should be a JSON object with the following keys:
To control the light bar, you can send messages to the following topic: `<MQTT_ROOT_TOPIC>/l2m_<MAC of your ESP32>/0x<Serial of the light bar>/command` e.g. `lightbar2mqtt/l2m_1234567890AB/0xabcdef/command`. The payload should be a JSON object with the following keys:
- `state`: `"ON"` or `"OFF"`
- `brightness`: `0` (off) to `15` (full brightness)
@ -96,7 +99,7 @@ Example:
#### Remote
The remote sends its state to the following topic: `<MQTT_ROOT_TOPIC>/l2m_<MAC of your ESP32>/remote/state` e.g. `lightbar2mqtt/l2m_1234567890AB/remote/state`. The payload is a plain string with one the following values:
The remote sends its state to the following topic: `<MQTT_ROOT_TOPIC>/l2m_<MAC of your ESP32>/0x<Serial of the remote>/state` e.g. `lightbar2mqtt/l2m_1234567890AB/0x123456/state`. The payload is a plain string with one the following values:
- `press`
- `turn_clockwise`
@ -107,7 +110,7 @@ The remote sends its state to the following topic: `<MQTT_ROOT_TOPIC>/l2m_<MAC o
#### Pairing
To pair the light bar with the ESP32, send a message to the following topic: `<MQTT_ROOT_TOPIC>/l2m_<MAC of your ESP32>/pair` e.g. `lightbar2mqtt/l2m_1234567890AB/pair`. The payload can be anything, it will be ignored.
To pair the light bar with the ESP32, send a message to the following topic: `<MQTT_ROOT_TOPIC>/l2m_<MAC of your ESP32>/0x<Serial of the light bar>/pair` e.g. `lightbar2mqtt/l2m_1234567890AB/0xabcdef/pair`. The payload can be anything, it will be ignored.
Please note that the light bar needs to be power-cycled within 10 seconds _before_ sending the pairing message.
@ -117,21 +120,21 @@ The ESP32 sends its availability to the following topic: `<MQTT_ROOT_TOPIC>/l2m_
### Home Assistant
If your Home Assistant has the MQTT integration set up, the light bar should be discovered automatically.
If your Home Assistant has the MQTT integration set up, the light bar(s) and remote(s) should be discovered automatically.
Additionally, the above mentioned events from the remote are also available as `device_automation` triggers. You can use these triggers to create automations in Home Assistant based on the actions taken on the remote. To do so, create a new automation in Home Assistant and select "Device" as the trigger type. Select the light bar entity and the desired trigger, e.g. `"press" action`.
Additionally, the above mentioned events from the remote are also available as `device_automation` triggers. You can use these triggers to create automations in Home Assistant based on the actions taken on the remote. To do so, create a new automation in Home Assistant and select "Device" as the trigger type. Select the corresponding remote entity and the desired trigger, e.g. `"press" action`.
### Known Issues / Limitations
- The light bar does not send its state to the ESP32. This means that if you change the state of the light bar via the controller, the ESP32 will not know about it. This is a limitation of the protocol used by the light bar.
- There is no way of knowing whether the light bar is currently on or off. Therefore this project assumes that the light bar is on when the ESP32 starts. If you turn off the light bar (e.g. via the remote), this might lead to an inverted state in Home Assistant. Just turn the device on in Home Assistant and power-cycle the light bar to fix this.
- Sometimes actions taken on the remote are not recognized by the ESP32. When building automations in Home Assistant, don't rely on the remote events to be 100% accurate. Normally, the second or third try should work.
- Sometimes actions taken on the remote are not recognized by the ESP32. When building automations in Home Assistant, don't rely on the remote events to be 100% accurate. Normally, the second or third try should work. It is therefore also recommended to decouple the light bar and original remote, as otherwise some actions on the remote might change the state of the light bar but not trigger anything in Home Assistant.
## Contributing
If you find a bug or have an idea for a new feature, feel free to open an issue or create a pull request. I'm happy to see this project grow and improve!
I've designed the code to be easily™ extendable. For example, it should be relatively easy to add support for multiple light bars or multiple remotes.
I've designed the code to be easily™ extendable. ~~For example, it should be relatively easy to add support for multiple light bars or multiple remotes.~~
## License