andrethomas / TasmotaClient

TasmotaSlave Library and interface examples
13 stars 9 forks source link

Forward mqtt payload to slave #4

Open 1ch1o opened 4 years ago

1ch1o commented 4 years ago

Hey, first of all thank you for making TasmotaSlave.

I succesfully have changed TasmotaSlave for my C project on an nrf52840. I can now autoconnect (via the code on nrf) and then control BLE-devices with the tasmota console and SlaveSend x. My goal is now to make an autoconfiguration json for homeassistant everytime the chip connects to a known ble device to control the ble-devices via mqtt. I am able to generate and send the json with SendCommand . But after that I need something that forwards recieved mqtt payloads to the uart/ tasmota slave.

Could you add a feature that does that? I think it would be the same as SlaveSend but you forward the recieved mqtt payloads. Something like a CMND_SLAVE_SEND_MQTT in the ProcessCommand.

For example:

~~MQTT-Client sends\ to topic: tasmota_esp/cmnd/mqtt or tasmota_esp/cmnd/slave\ payload: ble_device/cmnd/led ON~~

Tasmota forwards to Slave: ble_device/cmnd/led ON

~~Maybe a problem with the second space.\ But I also could use a payload like: ble_device/cmnd/led_ON,\ send it via uart and then split the string at _ on the TasmotaSlave.~~

Is this easy/possible to implement as I am not into the code of Tasmota and just used your library.

Would be very helpful. Thank you for your response.

1ch1o commented 4 years ago

Witnessed a problem with my suggestion of the forwarding with the underscore. HomeAssistant will only work with simple payloads like "ON" or "OFF". So I think it would be necessary to do something like:\ From slave to parent-device "subscribe topic x"\ And when the parent-device is recieving a payload y on the subscribed topic x:\ From parent-device to Slave: "on topic x, recieved payload y"

I think in this way it is easier for the future to implement slaves that can send to mqtt-topics and also are able to subscribe to mqtt-topics via the parent-device.

andrethomas commented 4 years ago

Hi

An interesting use case for this one but it would require some form of mqtt bridge to be implemented on the Tasmota side so I'll need to find a more generic way of doing this as opposed to one specific use case or implementation.

It may be possible to handle what you need using rules on the Tasmota side... another option would be to do the automations on something a little more programmable than home assistant... node-red comes to mind.

In either event, I'll keep this idea in the back of my mind where all things usually originate from.

1ch1o commented 4 years ago

Thank you for your response.

Sounds good to me, I think I will wait for the moment until you come up with an idea and an update on this topic.\ Until then I will use my current implementation to read sensors as this direction works and also have a look at rules of tasmota.