Install MQTT on domoticz
Create Switch with name like sonoffxxxx
Flash Sonoff with this Firmware : https://github.com/arendst/Sonoff-MQTT-OTA-Arduino/wiki
Install Node-red import this flow and configure MQTT and HTTP param.
[{"id":"45c4b609.64faa8","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":""},{"id":"c6a098df.f03518","type":"mqtt out","z":"f00b4ed5.9459c","name":"","topic":"","qos":"","retain":"","broker":"45c4b609.64faa8","x":316.8957977294922,"y":494.8889102935791,"wires":[]},{"id":"ad9093c3.d1c0a","type":"inject","z":"f00b4ed5.9459c","name":"sonoff6820 On","topic":"/cmnd/sonoff6820/power","payload":"On","payloadType":"str","repeat":"","crontab":"","once":false,"x":139.95480346679688,"y":472.43023681640625,"wires":[["c6a098df.f03518"]]},{"id":"55b820dd.e5706","type":"inject","z":"f00b4ed5.9459c","name":"sonoff6820 Off","topic":"/cmnd/sonoff6820/power","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"x":138.77072143554688,"y":516.5170230865479,"wires":[["c6a098df.f03518"]]},{"id":"133fe04b.24481","type":"comment","z":"f00b4ed5.9459c","name":"Instructions","info":"In this example manage Sonoff and domoticz \nintegration. \nYou need change MQTT Param and ADD the Domoticz\nSetting in HTTP Query.\n\nthe Sonoff use topic sonoffXXXX\n\n","x":100.09768676757812,"y":161.14443969726562,"wires":[]},{"id":"7e9db070.0bebb","type":"mqtt in","z":"f00b4ed5.9459c","name":"","topic":"domoticz/out","broker":"45c4b609.64faa8","x":101.92705535888672,"y":346.23565673828125,"wires":[["ceded70d.cb36d8"]]},{"id":"308d2076.a82b6","type":"http request","z":"f00b4ed5.9459c","name":"GetCurrentStatusAndIDX","method":"GET","ret":"txt","url":"http://<DomoticzIP>:<DomoticzPORT>/json.htm?type=devices&filter=light&used=true&order=Name","x":403.5576820373535,"y":250.68019199371338,"wires":[["da03f3d2.80ad4"]]},{"id":"da03f3d2.80ad4","type":"function","z":"f00b4ed5.9459c","name":"FindIDXfromName","func":"var msg2 = {};\n//var idx = {};\nmsg2.payload=msg.payload;\nmsg2.stat=msg.stat;\nmsg2.topic=msg.topic.substring(5, 15);\ntabresult = JSON.parse(msg.payload);\nfor (var i = 0; i < tabresult.result.length; i++) {\n HardwareName = tabresult.result.HardwareName;\n if(HardwareName==msg2.topic) {\n idx=tabresult.result.idx;\n readstat=tabresult.result.Status;\n msg2.HardwareName=HardwareName;\n break;\n }\n}\nmsg2.idx=idx;\nmsg2.readstat=readstat;\nreturn msg2;","outputs":1,"noerr":0,"x":625.0219497680664,"y":247.761568069458,"wires":[["88238b29.53c8e8"]]},{"id":"3330a161.d3b55e","type":"mqtt out","z":"f00b4ed5.9459c","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"45c4b609.64faa8","x":1161.5311737060547,"y":243.6196002960205,"wires":[]},{"id":"a28fd468.33bc98","type":"function","z":"f00b4ed5.9459c","name":"PrepDomoticzCmd","func":"msg2 = {};\npayload = {};\nmsg2.payload=payload;\nmsg2.payload.command = \"switchlight\";\nmsg2.payload.idx=Number(msg.idx);\nmsg2.payload.switchcmd=msg.stat;\nmsg2.payload.level=100;\nmsg2.topic=\"\";\nreturn msg2;","outputs":1,"noerr":0,"x":978.5312347412109,"y":243.3695993423462,"wires":[["3330a161.d3b55e"]]},{"id":"1f0754e4.0fcfeb","type":"mqtt in","z":"f00b4ed5.9459c","name":"","topic":"stat/#","broker":"45c4b609.64faa8","x":83.7812385559082,"y":251.36963272094727,"wires":[["449aa9ef.1ce8a8"]]},{"id":"449aa9ef.1ce8a8","type":"function","z":"f00b4ed5.9459c","name":"Savetopic","func":"var msg2 = {};\nmsg2.payload=msg.payload;\nmsg2.stat=msg.payload;\nmsg2.topic=msg.topic;\nreturn msg2;","outputs":1,"noerr":0,"x":216.28125,"y":252.1195993423462,"wires":[["308d2076.a82b6"]]},{"id":"88238b29.53c8e8","type":"switch","z":"f00b4ed5.9459c","name":"OnlyIfdiff","property":"readstat","propertyType":"msg","rules":[{"t":"eq","v":"stat","vt":"msg"},{"t":"neq","v":"stat","vt":"msg"}],"checkall":"false","outputs":2,"x":794.2812271118164,"y":246.86961460113525,"wires":[[],["a28fd468.33bc98"]]},{"id":"ceded70d.cb36d8","type":"json","z":"f00b4ed5.9459c","name":"","x":277.42879486083984,"y":345.31903076171875,"wires":[["e94b3fc6.47d61"]]},{"id":"294f21c6.8b619e","type":"mqtt out","z":"f00b4ed5.9459c","name":"sonoff#","topic":"","qos":"","retain":"","broker":"45c4b609.64faa8","x":853.5022983551025,"y":344.2947521209717,"wires":[]},{"id":"6985286d.0c65f8","type":"function","z":"f00b4ed5.9459c","name":"PrepSonoffCmd","func":"var msg2 = {};\nmsg2.topic='/cmnd/'+msg.payload.name+'/power'\nif (msg.payload.nvalue===0) {\n msg2.payload=\"Off\";\n}\nif (msg.payload.nvalue===1) {\n msg2.payload=\"On\";\n}\nreturn msg2;","outputs":1,"noerr":0,"x":632.4286270141602,"y":344.0690441131592,"wires":[["af741127.fcac5","294f21c6.8b619e"]]},{"id":"af741127.fcac5","type":"debug","z":"f00b4ed5.9459c","name":"","active":false,"console":"false","complete":"true","x":848.6787490844727,"y":396.56902980804443,"wires":[]},{"id":"e94b3fc6.47d61","type":"switch","z":"f00b4ed5.9459c","name":"is Sonoff","property":"payload.name","propertyType":"msg","rules":[{"t":"cont","v":"sonoff","vt":"str"},{"t":"else"}],"checkall":"true","outputs":2,"x":434.85070037841797,"y":344.52056884765625,"wires":[["6985286d.0c65f8"],[]]},{"id":"43bfe216.c3d53c","type":"comment","z":"f00b4ed5.9459c","name":"Get Sonoff Stat and Update Domoticz","info":"","x":181.8958282470703,"y":210.88888549804688,"wires":[]},{"id":"3c15dac3.78d136","type":"comment","z":"f00b4ed5.9459c","name":"use Domoticz MQTT out to update Sonoff","info":"","x":194.8958282470703,"y":303.8888854980469,"wires":[]},{"id":"5dbabd90.4a1514","type":"comment","z":"f00b4ed5.9459c","name":"For testing","info":"","x":92.89582824707031,"y":424.8888854980469,"wires":[]}]
To securize use MQTT password !
Cheers !
Sonoff MQTT integration
Moderator: leecollings
-
- Posts: 11
- Joined: Monday 12 October 2015 10:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.2563
- Contact:
Re: Sonoff MQTT integration
Hi, great solution!
I have one question: where i should configure MQTT and HTTP param?
Best Regards
M.
I have one question: where i should configure MQTT and HTTP param?
Best Regards
M.
-
- Posts: 4
- Joined: Wednesday 10 August 2016 8:12
- Target OS: Windows
- Domoticz version:
- Location: South Australia
- Contact:
Re: Sonoff MQTT integration
Hi there,
I'm a little confused what needs to be changed to make this work?
In the domoticz virtual switch, what http commands do you set for ON and OFF?
Thanks
I'm a little confused what needs to be changed to make this work?
In the domoticz virtual switch, what http commands do you set for ON and OFF?
Thanks
Software: Win2012R2, Domoticz, Mosquitto, Koenkk Zigbee2MQTT, Broadlink Python Plugin.
Hardware:CurrentCost128 3x IAMs, 5x Temperature sensor Wemos D1 Mini with 'ESPEasy', Zigbee via CC2531, ArduinoMega RFLink Gateway, Broadlink RM Mini3
Hardware:CurrentCost128 3x IAMs, 5x Temperature sensor Wemos D1 Mini with 'ESPEasy', Zigbee via CC2531, ArduinoMega RFLink Gateway, Broadlink RM Mini3
-
- Posts: 4
- Joined: Wednesday 21 December 2016 9:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Sonoff MQTT integration
hi there, got the arendst sonoff firmware to work with Domoticz.
This is what I did:
- added MQTT client gateway in Domoticz Hardware (for some reason not all values are loaded in the dropdown box sometimes, so you might have to refresh the hardware page)
- in user_config.h: edit the STA_SSID1 + STA_PASS1 for your wifi settings. +
- uploaded the arendst sketch to the ESP chip through an Arduino Uno. (see his wiki + make sure to put the esp in flash mode with the button down on startup)
Also, i checked the ESP settings via http in the configuration tab and entered them again + reboot.
So now my christmas lights shine bright as soon as i open the front door
This is what I did:
- added MQTT client gateway in Domoticz Hardware (for some reason not all values are loaded in the dropdown box sometimes, so you might have to refresh the hardware page)
- in user_config.h: edit the STA_SSID1 + STA_PASS1 for your wifi settings. +
Code: Select all
#define MQTT_HOST "192.168.xxx.yyy" // [MqttHost] your domoticz ip here
#define MQTT_PORT 1883 // [MqttPort] MQTT port (10123 on CloudMQTT)
#define MQTT_USER "" // [MqttUser] Optional user
#define MQTT_PASS "" // [MqttPassword] Optional password
Also, i checked the ESP settings via http in the configuration tab and entered them again + reboot.
So now my christmas lights shine bright as soon as i open the front door
-
- Posts: 4
- Joined: Saturday 24 December 2016 18:03
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Sonoff MQTT integration
Any idea on how to get the son off telemetry data into Domoticz, like Temperature & Humidity?
Thanks for any ideas!
Thanks for any ideas!
-
- Posts: 9
- Joined: Thursday 07 April 2016 16:40
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Sonoff MQTT integration
Hello, can someone help me with this please?
I successfully flashed a Sonoff (with https://github.com/arendst/Sonoff-MQTT- ... uino/wiki/), and it is connected to my Wifi and MQTT server (just local install of Mosquitto not running Node-Red as I don't see why it would be needed in this case)... but it only works if I use the sonoff (webserver or button) to activate the switch.
No matter what I try I can't get the Sonoff to be controlled by Domoticz.
Eg.
I'm monitoring Domoticz/out and /in, I can see the messages being sent by the Sonoff and Domoticz... but the Sonoff never changes state even though Domoticz is publishing in /out the sonoff never reacts.
But if I toggle on the Sonoff I see the messages in /out and /in, and Domoticz updates the state as well (obviously).
I'm stumped.
Out from Domoticz:
In from MQTT (only when executed by the sonoff):
Obviously the nvalue state changes depending on the state of the switch (Sonoff or Domoticz)
EDIT: Never mind... Forgot to increase the MQTT_MAX_PACKET_SIZE to 400 as stated here: https://github.com/arendst/Sonoff-MQTT- ... erequisite
After doing that it works perfectly!
I successfully flashed a Sonoff (with https://github.com/arendst/Sonoff-MQTT- ... uino/wiki/), and it is connected to my Wifi and MQTT server (just local install of Mosquitto not running Node-Red as I don't see why it would be needed in this case)... but it only works if I use the sonoff (webserver or button) to activate the switch.
No matter what I try I can't get the Sonoff to be controlled by Domoticz.
Eg.
I'm monitoring Domoticz/out and /in, I can see the messages being sent by the Sonoff and Domoticz... but the Sonoff never changes state even though Domoticz is publishing in /out the sonoff never reacts.
But if I toggle on the Sonoff I see the messages in /out and /in, and Domoticz updates the state as well (obviously).
I'm stumped.
Out from Domoticz:
Code: Select all
{
"Battery" : 255,
"RSSI" : 12,
"description" : "",
"dtype" : "Light/Switch",
"id" : "000140A8",
"idx" : 88,
"name" : "Kitchen Cab LED 2",
"nvalue" : 0,
"stype" : "Switch",
"svalue1" : "0",
"switchType" : "On/Off",
"unit" : 1
}
Code: Select all
{"idx":88, "nvalue":0, "svalue":""}
EDIT: Never mind... Forgot to increase the MQTT_MAX_PACKET_SIZE to 400 as stated here: https://github.com/arendst/Sonoff-MQTT- ... erequisite
After doing that it works perfectly!
-
- Posts: 1
- Joined: Monday 31 July 2017 12:29
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Sonoff MQTT integration
Hi, I have alternated the program to suit my need, but I have a question. How about if I use the dimmer or temp+hum sensor, what are commands then at >>msg2.payload.command = "switchlight";<< and >>msg2.payload.switchcmd=msg.stat;<<?
Who is online
Users browsing this forum: No registered users and 1 guest