Domoticz MQTT: read works, but cannot control relay

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Domoticz MQTT: read works, but cannot control relay

#1 Post by tuxmartin » 21 Sep 2017, 09:57

Hi, I'm testing ESP Easy Mega v2.0.0-dev11 with Domoticz V3.8153 on Sonoff Basic.

I have 1xDS18B20 and 1xHHT22 - works great.

But I have problem with two relays.

If I control relay through http://10.123.1.188/control?cmd=GPIO,12,1 it works. There is output:

Code: Select all

{
"log": "GPIO 12 Set to 1",
"plugin": 1,
"pin": 12,
"mode": "output",
"state": 1
}
and at Domoticz I see that relay was enabled.

But if I turn on(or off) relay at Domoticz web, esp easy do nothing. There is mqtt message from domoticz:

Code: Select all

$ mosquitto_sub -v -h 10.123.1.18 -p 1883 -t '#'
domoticz/out {
   "Battery" : 255,
   "RSSI" : 12,
   "description" : "",
   "dtype" : "Light/Switch",
   "id" : "00014052",
   "idx" : 2,
   "name" : "Sonoff_1_internal_relay",
   "nvalue" : 1,
   "stype" : "Switch",
   "svalue1" : "0",
   "switchType" : "On/Off",
   "unit" : 1
}
esp easy ignore it :-(

I tried Sonoff-Tasmota firmware and relay works. But Tasmota firmware has little functionality.

If I use on/off action url in Domoticz, it works. But I do not want it - it is not possible to use DHCP.

How can I fix it?
Attachments
domoticz.png
domoticz.png (111.93 KiB) Viewed 20399 times
easyesp_sonoff_relay.png
easyesp_sonoff_relay.png (78.29 KiB) Viewed 20401 times
Last edited by tuxmartin on 21 Sep 2017, 10:04, edited 1 time in total.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#2 Post by grovkillen » 21 Sep 2017, 10:02

ESP Easy doesn't parse the JSON message that you send. It only understand direct commands. I suggest you tell Domoticz to send

topic

Code: Select all

<MQTT subscribe template>/cmd 
payload (message) turn OFF

Code: Select all

GPIO,12,0
payload (message) turn ON

Code: Select all

GPIO,12,1
https://www.letscontrolit.com/wiki/inde ... _Reference
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#3 Post by tuxmartin » 21 Sep 2017, 10:22

Thanks for reply. But I can't find <MQTT subscribe template>

I found this image in tutorial: https://www.projetsdiy.fr/wp-content/up ... -delay.png
But I can't find these page in my espeasy.

In Domoticz there is not possible to send only GPIO,12,1 to device (or I don't know how do it).
grovkillen wrote: 21 Sep 2017, 10:02 ESP Easy doesn't parse the JSON message that you send.
Is it planned for any new version?
Is possible to vote for this function on some github issue? Or send money to developers for this features.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#4 Post by grovkillen » 21 Sep 2017, 10:50

tuxmartin wrote: 21 Sep 2017, 10:22 Thanks for reply. But I can't find <MQTT subscribe template>
...
You find that in the Controller settings. But default that would equal to your "device name". I.e. DeviceName/cmd
tuxmartin wrote: 21 Sep 2017, 10:22
grovkillen wrote: 21 Sep 2017, 10:02 ESP Easy doesn't parse the JSON message that you send.
Is it planned for any new version?
Is possible to vote for this function on some github issue? Or send money to developers for this features.
No not planned but you could suggest it on GitHub. Regarding donations, this is not possible in a easy way no.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#5 Post by tuxmartin » 21 Sep 2017, 12:20

I set Controller Subscribe: sonoff/%sysname%/cmd in esp easy. Esp easy name is "modul1".

Code: Select all

$ mosquitto_pub -h 10.123.1.18 -t sonoff/modul1/cmd -m "GPIO,12,0"
$ mosquitto_pub -h 10.123.1.18 -t sonoff/modul1/cmd -m "GPIO,12,1"
Nothing happens :-(

What I do bad?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#6 Post by grovkillen » 21 Sep 2017, 12:33

tuxmartin wrote: 21 Sep 2017, 12:20 I set Controller Subscribe: sonoff/%sysname%/cmd in esp easy. Esp easy name is "modul1".

Code: Select all

$ mosquitto_pub -h 10.123.1.18 -t sonoff/modul1/cmd -m "GPIO,12,0"
$ mosquitto_pub -h 10.123.1.18 -t sonoff/modul1/cmd -m "GPIO,12,1"
Nothing happens :-(

What I do bad?

Code: Select all

/sonoff/modul1/cmd "GPIO,12,0"
/sonoff/modul1/cmd "GPIO,12,1"
Forward slash is missing in the published topic. I suggest you remove them from the subscription topic in the settings (which is the standard way) or add them in the published topic from Domoticz.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#7 Post by tuxmartin » 21 Sep 2017, 12:45

Still not working :-(
Attachments
x.png
x.png (55.38 KiB) Viewed 20381 times

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#8 Post by grovkillen » 21 Sep 2017, 12:50

Doesn't any command work at all? Reboot for example?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#9 Post by tuxmartin » 21 Sep 2017, 13:00

http command works: http://10.123.1.188/control?cmd=GPIO,12,1

I have problem only with MQTT: mosquitto_pub -h 10.123.1.18 -t /sonoff/modul1/cmd -m "GPIO,12,1"

Yes, I rebooted esp8266 (sonoff) about ten times - using software and unplug/plug 230V AC.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#10 Post by grovkillen » 21 Sep 2017, 13:42

I mean other COMMANDS not only the GPIO command. (Reboot is a command, just as an example).
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#11 Post by tuxmartin » 21 Sep 2017, 14:34

I tried it. No command is working:
espeasy_mqtt_test.png
espeasy_mqtt_test.png (92.7 KiB) Viewed 23174 times
I have in espeasy:

Code: Select all

Unit Name: modul1
Unit Number: 7
In dhcp log name is "modul1_7":

Code: Select all

Sep 21 14:25:41 baru dhcpd: DHCPDISCOVER from 5c:cf:7f:e9:c5:89 via br0
Sep 21 14:25:42 baru dhcpd: DHCPOFFER on 10.123.1.188 to 5c:cf:7f:e9:c5:89 (modul1_7) via br0
Sep 21 14:25:42 baru dhcpd: DHCPREQUEST for 10.123.1.188 (10.123.1.1) from 5c:cf:7f:e9:c5:89 (modul1_7) via br0
Sep 21 14:25:42 baru dhcpd: DHCPACK on 10.123.1.188 to 5c:cf:7f:e9:c5:89 via br0
I tried "Controller Subscribe: #" and publish to /sonoff/modul1_7/cmd - not work.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#12 Post by grovkillen » 21 Sep 2017, 15:22

Code: Select all

/sonoff/modul1_7/#
Try that in the Controller setting.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#13 Post by tuxmartin » 21 Sep 2017, 15:34

No, it not works :-(

Can you please try it? I will open mqtt port and espeasy web port on my firewall.

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#14 Post by tuxmartin » 21 Sep 2017, 15:49

I tried to add device "MQTT Import":
mqtt_import.png
mqtt_import.png (58.77 KiB) Viewed 23165 times
If I send mosquitto_pub -h 10.123.1.18 -t /sonoff/modul1/GPIO12 -m "1" value to defined topic, espeasy show it:
mqtt_import2.png
mqtt_import2.png (53.87 KiB) Viewed 23165 times

If I uderstand it, now can I use variable [mqtt import#GPIO12].

But is not possible to set [mqtt import#GPIO12] to relay:
easyesp_sonoff_relay.png
easyesp_sonoff_relay.png (78.29 KiB) Viewed 23165 times
I created rule (found on forum):

Code: Select all

on [mqtt import#GPIO12] do
  if [mqtt import#GPIO12] = 1
    gpio12,1
  else
    gpio12,0
  endif
endon
rule not working.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#15 Post by grovkillen » 21 Sep 2017, 16:55

Spaces in devices is not recommended. Change that and use this rule:

Code: Select all

on mqtt_import#GPIO12 do
  if [mqtt_import#GPIO12] = 1
    gpio12,1
  else
    gpio12,0
  endif
endon
And please use the wiki... https://www.letscontrolit.com/wiki/index.php/ESPEasy
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#16 Post by tuxmartin » 21 Sep 2017, 17:07

Still not working :-(

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#17 Post by grovkillen » 21 Sep 2017, 18:29

But the "mqtt_import" variable "GPIO12" change when you send the commands? Have you looked in the log?

EDIT: I see now that the syntax is screwed up!

Code: Select all

on mqtt_import#GPIO12 do
  if [mqtt_import#GPIO12] = 1
    gpio,12,1
  else
    gpio,12,0
  endif
endon
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#18 Post by tuxmartin » 21 Sep 2017, 19:22

There is log:

Code: Select all

131505 : SYS : -44.00
131506 : EVENT: wifi_rssi#wifi_rssi=-42.01
138648 : IMPT : [mqtt_import#GPIO12] : 0.00
138648 : EVENT: mqtt_import#GPIO12=0.00
142098 : IMPT : [mqtt_import#GPIO12] : 1.00
142098 : EVENT: mqtt_import#GPIO12=1.00
With your rules:

Code: Select all

on mqtt_import#GPIO12 do
  if [mqtt_import#GPIO12] = 1
    gpio,12,1
  else
    gpio,12,0
  endif
endon
it works! Thank you!

I still would like do it less complicated, but I'm happy that it works.

---------------

Can I use relay name "internal_relay" in rule?
Something like:

Code: Select all

if [mqtt_import#GPIO12] = 1
    internal_relay = 1
?
easyesp_sonoff_relay.png
easyesp_sonoff_relay.png (78.29 KiB) Viewed 23144 times

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#19 Post by grovkillen » 21 Sep 2017, 21:49

Yes you should be able to do this without the rule and MQTT Import using the command and send it to the topic esp_unit/cmd.

It must be some typo on your side (the subscription should be the default).
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Domoticz MQTT: read works, but cannot control relay

#20 Post by vader » 21 Sep 2017, 23:13

Guys, that is exact the same problem I postet here:
viewtopic.php?f=18&t=3407

The problem is in ESP Easy not processing defined rules after an incoming MQTT command. Only god knows why the devs had this not seen yet. You can only make this working with the plug-in 29. See here:
https://www.letscontrolit.com/wiki/inde ... lperDevice

That are so few lines of code to copy from P29 into the right place of Controller.ino (I assume at the end of part ("Handle incoming MQTT messages"). There should be something like:
......
rulesProcessing(RuleEvent);

I have it working now, but unfortunately my programming skills are not enough to be sure all is right.... :cry:

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: Domoticz MQTT: read works, but cannot control relay

#21 Post by papperone » 22 Sep 2017, 07:01

Not sure I understand, in my setup I send commands to ESPEasy nodes from NodeRed via MQTT publish generating an event (topic="%sysname%/cmd" payload="event,EVENTNAME") and it works as in the rules I've connected events to "gpio,x,0/1" commands; I'm avail for testign but I'd like to understand what you mean when you state "not processing rules after incoming MQTT" as in my case it seems to work.
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Domoticz MQTT: read works, but cannot control relay

#22 Post by vader » 22 Sep 2017, 08:53

papperone wrote: 22 Sep 2017, 07:01 Not sure I understand, in my setup I send commands to ESPEasy nodes from NodeRed via MQTT publish generating an event (topic="%sysname%/cmd" payload="event,EVENTNAME") and it works as in the rules I've connected events to "gpio,x,0/1" commands; I'm avail for testign but I'd like to understand what you mean when you state "not processing rules after incoming MQTT" as in my case it seems to work.
You are sending an "EVENT" command directly to process a rule! Make a JSON payload with "IDX" informations, like Domoticz do, and nothing will happen to GPIOx...

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#23 Post by grovkillen » 22 Sep 2017, 10:11

ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: Domoticz MQTT: read works, but cannot control relay

#24 Post by papperone » 22 Sep 2017, 11:31

vader wrote: 22 Sep 2017, 08:53
papperone wrote: 22 Sep 2017, 07:01 Not sure I understand, in my setup I send commands to ESPEasy nodes from NodeRed via MQTT publish generating an event (topic="%sysname%/cmd" payload="event,EVENTNAME") and it works as in the rules I've connected events to "gpio,x,0/1" commands; I'm avail for testign but I'd like to understand what you mean when you state "not processing rules after incoming MQTT" as in my case it seems to work.
You are sending an "EVENT" command directly to process a rule! Make a JSON payload with "IDX" informations, like Domoticz do, and nothing will happen to GPIOx...
ok so this is purely Domoticz related issues, clear; I thought it was a more generic problem!
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

ArJay60
New user
Posts: 1
Joined: 05 Oct 2017, 21:08

Re: Domoticz MQTT: read works, but cannot control relay

#25 Post by ArJay60 » 05 Oct 2017, 21:19

It seems that the later versions of Domoticz have a change in the MQTT message. The item Description is added and ESPEasy is not handling this well.
I am using ESPeasy build 142.

MQTT message with older version of Domoticz:
{
"Battery" : 255,
"RSSI" : 12,
"dtype" : "Light/Switch",
"id" : "0001408A",
"idx" : 58,
"name" : "HK Schemer Acht",
"nvalue" : 1,
"stype" : "Switch",
"svalue1" : "0",
"switchType" : "On/Off",
"unit" : 1
}
MQTT message with newer version of Domoticz:
{
"Battery" : 255,
"RSSI" : 12,
"description" : "", <------ removing this line from the message to ESPeasy solves the problem.
"dtype" : "Light/Switch",
"id" : "0001408A",
"idx" : 58,
"name" : "HK Schemer Acht",
"nvalue" : 1,
"stype" : "Switch",
"svalue1" : "0",
"switchType" : "On/Off",
"unit" : 1
}

Can someone of the developers make MQTT within ESPeasy less sensitive for these changes in MQTT messages. This so that we can upgrade to newer version of Domoticz and still use MQTT.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#26 Post by grovkillen » 05 Oct 2017, 21:29

Maybe the use for a JSON parser library would be possible? That means some development though.

https://github.com/bblanchon/ArduinoJson
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#27 Post by tuxmartin » 05 Oct 2017, 23:58

ArJay60 wrote: 05 Oct 2017, 21:19 It seems that the later versions of Domoticz have a change in the MQTT message. The item Description is added and ESPEasy is not handling this well.
I am using ESPeasy build 142.
Please create new github issue for it: https://github.com/letscontrolit/ESPEasy/issues

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: Domoticz MQTT: read works, but cannot control relay

#28 Post by LisaM » 06 Oct 2017, 09:13

uPyEasy will have a full 2-way interface available, without the need for a mqtt import plugin... ;)
I have build an HTTP & MQTT 2-way interface for Domoticz as an example, it consist out of 3 files: one python file (domoticz.py) which has two classes (http and mqtt) sitting in the protocols dir and two html templates for both protocols (domoticz_http.html and domoticz_mqtt.html). The templates are being used in the creation of a controller (changing protocol will mean changing UI). It's total size is just 490KB, so still plenty of room left...

Will do you no good at the moment, but it's coming!

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#29 Post by grovkillen » 06 Oct 2017, 09:20

Ah, uPyEasy sounds like a good way forward. Keep up the good work Lisa!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Martinus

Re: Domoticz MQTT: read works, but cannot control relay

#30 Post by Martinus » 08 Oct 2017, 13:24

Domoticz MQTT support is limited, but it has always worked using the Domoticz helper device. So setup a task with this device and configure the IDX value from the switch in Domoticz.
https://www.letscontrolit.com/wiki/inde ... lperDevice

Also make sure you use the libraries from our github site and just not take them from anywere... The default library buffer size is not large enough to process the larger Domoticz messages.

Martinus

Re: Domoticz MQTT: read works, but cannot control relay

#31 Post by Martinus » 08 Oct 2017, 13:29

grovkillen wrote: 21 Sep 2017, 10:02ESP Easy doesn't parse the JSON message that you send. It only understand direct commands.
This is incorrect. Just look at the code within the Domoticz MQTT plugin:

Code: Select all

    case CPLUGIN_PROTOCOL_RECV:
      {
        StaticJsonBuffer<512> jsonBuffer;
        JsonObject& root = jsonBuffer.parseObject(event->String2.c_str());

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Domoticz MQTT: read works, but cannot control relay

#32 Post by grovkillen » 08 Oct 2017, 17:21

Martinus wrote: 08 Oct 2017, 13:29
grovkillen wrote: 21 Sep 2017, 10:02ESP Easy doesn't parse the JSON message that you send. It only understand direct commands.
This is incorrect. Just look at the code within the Domoticz MQTT plugin:

Code: Select all

    case CPLUGIN_PROTOCOL_RECV:
      {
        StaticJsonBuffer<512> jsonBuffer;
        JsonObject& root = jsonBuffer.parseObject(event->String2.c_str());
Sorry for the disinformation. :oops:
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Domoticz MQTT: read works, but cannot control relay

#33 Post by vader » 08 Oct 2017, 17:37

Come on guys, will you tell me that this little piece of code from Output.ino (P029) does not fit into the Controller.ino (or _C002 ??) to make the extra plug-in unnecessary?

// We need the index of the controller we are: 0-CONTROLLER_MAX
byte controllerNr = 0;
for (byte i=0; i < CONTROLLER_MAX; i++)
{
// if (Settings.Protocol == CPLUGIN_ID_002) { controllerNr = i; } -> error: 'CPLUGIN_ID_002' was not declared in this scope
if (Settings.Protocol == 2) { controllerNr = i; }
}

string += F("<TR><TD>IDX:<TD>");
String id = F("TDID"); //="taskdeviceid"
id += controllerNr + 1;
addNumericBox(string, id, Settings.TaskDeviceID[controllerNr][event->TaskIndex], 0, 9999);

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#34 Post by tuxmartin » 08 Oct 2017, 23:53

ArJay60 wrote: 05 Oct 2017, 21:19 It seems that the later versions of Domoticz have a change in the MQTT message. The item Description is added and ESPEasy is not handling this well.
I am using ESPeasy build 142.
"description" : "", <------ removing this line from the message to ESPeasy solves the problem.
"dtype" : "Light/Switch",
I tried to publish only idx, nvalue and svalue:

Code: Select all

$ mosquitto_pub -h 10.123.1.18 -t domoticz/out -m '{"idx": 2, "nvalue": 1, "svalue1": "1"}'
still not working :-(

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Domoticz MQTT: read works, but cannot control relay

#35 Post by vader » 09 Oct 2017, 09:35

Not without the use of the "Domoticz Helper (P29)"

tuxmartin
Normal user
Posts: 34
Joined: 10 Sep 2017, 13:07

Re: Domoticz MQTT: read works, but cannot control relay

#36 Post by tuxmartin » 09 Oct 2017, 11:36

This works for me:
Set Controller Subscribe: domoticz/fix in ESP easy.

Run python_mqtt_fix.py:

Code: Select all

import paho.mqtt.client as mqtt
import json

def on_message(client, userdata, message):
    msg_data = str(message.payload.decode("utf-8"))

    if message.topic == "domoticz/out":
        try:
            json_dout = json.loads(msg_data)
            json_dout.pop('description', None) # remove 'description'
            mqttc.publish("domoticz/fix", json.dumps(json_dout))
        except Exception as e:
            print(e)

mqttc = mqtt.Client("domoticz_mqtt_proxy")
mqttc.on_message = on_message
mqttc.connect("10.123.1.18", 1883, 60)
mqttc.subscribe("domoticz/out", 0)
mqttc.loop_forever()
This script remove "description":

Code: Select all

$ mosquitto_sub -v -h 10.123.1.18 -p 1883 -t '#'

domoticz/out {
   "Battery" : 255,
   "RSSI" : 12,
   "description" : "230V relay",
   "dtype" : "Light/Switch",
   "id" : "00014052",
   "idx" : 2,
   "name" : "Sonoff_1_relay1_230V",
   "nvalue" : 1,
   "stype" : "Switch",
   "svalue1" : "0",
   "switchType" : "On/Off",
   "unit" : 1
}

domoticz/fix {"idx": 2, "nvalue": 1, "Battery": 255, "dtype": "Light/Switch", "svalue1": "0", "unit": 1, "switchType": "On/Off", "RSSI": 12, "id": "00014052", "stype": "Switch", "name": "Sonoff_1_relay1_230V"}
Now it works :-/

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: Domoticz MQTT: read works, but cannot control relay

#37 Post by vader » 10 Oct 2017, 12:59

Can't beleive that this should work. :?: I see in your 1st post, that you are sending the command twice! Over MQTT and over HTTP from Domoticz. Empty the "ON Action" fields (to be sure only sending over MQTT!) and look if it still works and the GPIO state change. I would bet, that it doesn't....

Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests