• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


MQTT protocol for pilight
#1
Hello everybody,

MQTT is  a growing trend in the Home Automation.
I replace more and more 433Mhz devices against ESP8266/ESP32 because they have several advantages:

- Works over ethernet without send/receive/filter hardware or antennas.
- Much more reliable as 433Mhz devices.
- Provides status feedback time based or after processing.
- Supports stand alone functionality.
- Flashing of your own or customized firmware which is very usefull for adaptations.
- Same costs or even cheaper.

Currently I control these devices with a Python script that I start from pilight with arguments.
However I think a native MQTT functionality will be crutial for pilight in the future.

Please let me know if I can contribute some how.
 
Reply
#2
Would be great if you could write a hardware module and/or new protocols?
 
Reply
#3
Smile 
(01-05-2018, 11:41 PM)curlymo Wrote: Would be great if you could write a hardware module and/or new protocols?

Hello,

Sorry for the late reply.
I was totally busy today with the automation of my Garage Door/Light.
Of course with pilight Smile  .

I already provided here in the Forum the related Phython script that I use.
Actually I would assume that the implememtation in other Languages are not so different.
However if you give me more details about your development environment, I would try to provide a module that can send & receive MQTT messages.
 
Reply
#4
You can find pilight on github:
https://github.com/pilight/pilight

It's good to check the different (merged) PR's to see have modules are written.
 
Reply
#5
(01-05-2018, 08:35 PM)Chekov Wrote: Hello everybody,

MQTT is  a growing trend in the Home Automation.
I replace more and more 433Mhz devices against ESP8266/ESP32 because they have several advantages:

- Works over ethernet without send/receive/filter hardware or antennas.
- Much more reliable as 433Mhz devices.
- Provides status feedback time based or after processing.
- Supports stand alone functionality.
- Flashing of your own or customized firmware which is very usefull for adaptations.
- Same costs or even cheaper.

Currently I control these devices with a Python script that I start from pilight with arguments.
However I think a native MQTT functionality will be crutial for pilight in the future.

Please let me know if I can contribute some how.
 
Reply
#6
By the way, I am using some software based on the work of Oliver van Porten, the pilight2mqtt. It allows me to send messages to my Tasmota-Sonoff's and I wrote some specials to send mqtt messages back to pilight. The software is quite straight-forward but the features to implement are probably the challenge. I just forward every switch action from pilight to MQTT, where the pilight-device becomes part of the MQTT-topic that Tasmota understands and visa-versa. 

So e.g. a pilight generic switch MyLight change state to ON becomes MQTT-topic "cmnd/MyLight/power" with MQTT-payload "ON". And I use the Tasmota response to give the feedback from MQTT to pilight, again just using part of the MQTT-topic as pilight-device, "stat/MyLight/POWER" payload "ON". Handling the feedback is the first issue to solve because it would mean we need an intermediate state between ON-issued and ON-committed. I solve this to switch back to the previous state when the commit does not arrive within a reasonable time (few seconds) but this is indeed Q&D. Disregarding feedback is also an idea since the WIFI transport is in itself more reliable. 

Perhaps an idea to implement as such and let it grow according to further features proposed by the users.
 
Reply
#7
I have recently been working on an MQTT library for pilight, including a lua network library and actions.

At this point, I can publish topics to an MQTT broker (including qos0 and qos1) using rules e.g like this:

Code:
"IF testswitch.state == on OR testswitch.state == off THEN mqttpublish BROKER 'test.mosquitto.org' TOPIC 'pilight/switch/testswitch' MESSAGE 'testswitch.state' QOS 1"

In fact the library also provides functionality to subscribe to topics and receive messages (one by one), but it will require a rule  being triggered on interval, doing the subscribe and receiving the messages, and additional rules based on its results for every device to be controlled via MQTT. It works, but I am still working on it.

Now, however this works, imho it would be nice to have natively MQTT enabled devices in pilight.

One idea I have, is an mqtt_switch protocol (and maybe an mqtt_dimmer protocol) that sends and listens to an MQTT broker, instead of sending and listening to 433.92. When a device with that protocol changes state, it sends a message to the broker telling what the new state of the switch is. On the other hand, when an MQTT message is received for that switch, it can change its state.
That way Sonoff switches (with Tasmota firmware) for instance could be controlled directly from pilight, and manually switching the Sonoff device would be reflected in pilight too. The same can be achieved with the MQTT rules too, but I think that is less elegant, less efficient and requires at least two additional rules for each device to be controlled via MQTT.

An advantage of protocols compared with MQTT actions is that the actions have to create a socket and connect to the broker every time they are executed. A protocol wouldn't have that overhead, because it can create a socket once if it doesn't have one yet, connect once to the broker and stay connected (ofc with recovery if socket or connection might get lost).

A different approach could be a "deamon" that continiuously is listening to a broker and sends device updates for every (valid) MQTT message it receives. The topic then could tell which device is involved and the daemon can update the state (and or other properties) of that protocol. Aditionally the broker could listen to device updates being broadcasted and publish them back to the broker. This way any switch defined in the config could be controlled via MQTT.

However that would probably be a bit above my capabilities Unsure

For now, I will first improve the library and the actions.

@rorie, it will probably take a few weeks before the library and stuff ar stable enough. Would you be prepared to test it then? It requires recompilation, because the mtqq library is part of the pilight core, so it is not something you should do on your live system!
 
Reply
#8
Have you though of developing an hardware module instead of the protocol and action that is connected to the broker permanently? I can check my zwave hardware module and protocols proof-of-concept for inspiration. Those are however not yet ported to lua.
 
Reply
#9
No, I didn't and I dont quite understand. Communication with the broker works via a standard socket connection and a specific protocol, so there is no hardware specific hardware involved.
 
Reply
#10
Ofc, but your goal is perfect for a hardware module Smile As in simulating the MQTT as it is a hardware device.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  missing protocol of "date_and_time" in Wiki/Protocols fleisch 3 136 08-03-2019, 06:10 PM
Last Post: curlymo
Brick Protocol for FT0073 drobskind 5 2,932 07-25-2019, 10:44 PM
Last Post: fireball
  Oregon Protocol V2.1: THGR122NX jpoilux 208 65,616 07-04-2019, 02:14 PM
Last Post: Tueftler1983
  Brennenstuhl RCR CE1 1011 with QUIGG GT9000 Protocol scootermacro 1 185 06-27-2019, 06:20 PM
Last Post: scootermacro
  mumbi rcs-20gs protocol scootermacro 0 165 06-21-2019, 12:10 PM
Last Post: scootermacro
  How to introduce a new protocol folder? Phunkafizer 2 364 01-15-2019, 07:25 PM
Last Post: Phunkafizer
  rfcontroljs protocol implementation pisperate 0 208 01-13-2019, 11:07 AM
Last Post: pisperate
  getting started guide for implementing new protocol kaililleby 1 791 11-28-2017, 10:24 PM
Last Post: pilino1234
  Logilink EC0003 Protocol ehz 4 1,059 09-24-2017, 07:15 PM
Last Post: ehz
  Unkown protocol with Lidl Libra RC-710 HaselnuesseTo 0 980 09-11-2017, 08:30 PM
Last Post: HaselnuesseTo

Forum Jump:


Browsing: 1 Guest(s)