letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.29k stars 2.22k forks source link

switch light: domoticz mqtt integration #3544

Open megamarco833 opened 3 years ago

megamarco833 commented 3 years ago

hi, i was with espeasy build ESP_Easy_mega-20200204_normal_ESP8266_4M1M.bin on nodemcu the system has this generic setup:

scope: switch on/off the light using wall switch and use domoticz as well to control the status of the light and switch on/off also the light from domoticz.

i create a script in domoticz that when i turn off/on the idx=96 send an mqtt message: if ON it send => dz2esp_kitchen 1 if OFF it send => dz2esp_kitchen 0

inside espeasy i create a "dummy Generic - MQTT Import" named as "sniff" like this: immagine immagine

then i set up a rule:

On System#Boot do    //When the ESP boots, do relay to OFF just to be sure
  gpio,13,1 //kitchen
  gpio,14,1 //bathroom
endon

on wall_kitchen_1#Switch do
      Publish domoticz/in,'{"command": "switchlight", "idx": 96, "switchcmd": "Toggle" }' // id of kitchenLight
endon

on wall_kitchen_2#Switch do
      Publish domoticz/in,'{"command": "switchlight", "idx": 96, "switchcmd": "Toggle" }'
endon

on sniff#kitchen=1 do gpio,13,0 
on sniff#kitchen=0 do gpio,13,1 
endon

so when i turn idx=96 ON domoticz send: dz2esp_kitchen 1 espeasy rule will set GPIO13 0 (inverted relay) and relay will trigger ON

if i use push button (wall switch) rule will recognize the status change and send to domoticz: Publish domoticz/in,'{"command": "switchlight", "idx": 96, "switchcmd": "Toggle" }' // id of kitchenLight

of course this is a workaround beacuse mqtt for switch and domoticz doesn't talk properly (i should use domoticz help task, but it will require a task for every relay and it do not manage inverted relay) but this configuration as workaround was working till now.

Now i have upgraded my esp with latest espeasy firmware, but this configuration is not anymore working! ;( i see that with new firmware i receive a "ping-pong" message between domoticz and espeasy and relay is continuosy triggering on and off...and i see that domoticz is contiusoly sending the message dz2esp_kitchen 1 and dz2esp_kitchen 0 because espeasy recognize an wall_kitchen EVENT as status change (but i do not use the wall switch i just click on domoticz idx) and espeasy send the message `Publish domoticz/in,'{"command": "switchlight", "idx": 96, "switchcmd": "Toggle" }' it will create this ping-pong message and the realy continue to loop on/off

Again this not happened with ESP_Easy_mega-20200204_normal_ESP8266_4M1M.bin i revert back and is working again. so my two question are: 1) why this happen on new firmware and not in previous ? 2) is not possibile to solve this situation and make working talking between switches on espeasy and domoticz with mqtt?

the scenario is simple: n°1 relay for light on GPIO 13 (1=off 0=on) n°2 wall switches as push button to control the relay n°1 domoticz dummy device idx=96 to control the relay and see the status of relay (if on or off)

how to have it with mqtt and avoid to use "domoticz mqtt help task"?

espeasy should recognize message public on topic: domoticz/out with message OFF: { "Battery" : 255, "LevelNames" : "Off|Level1|Level2|Level3", "RSSI" : 12, "SelectorStyle" : "0", "description" : "", "dtype" : "Light/Switch", "hwid" : "6", "id" : "000140B0", "idx" : 96, "name" : "kitchen", "nvalue" : 0, "stype" : "Selector Switch", "svalue1" : "0", "switchType" : "On/Off", "unit" : 1 }

message ON: { "Battery" : 255, "LevelNames" : "Off|Level1|Level2|Level3", "RSSI" : 12, "SelectorStyle" : "0", "description" : "", "dtype" : "Light/Switch", "hwid" : "6", "id" : "000140B0", "idx" : 96, "name" : "kitchen", "nvalue" : 1, "stype" : "Selector Switch", "svalue1" : "0", "switchType" : "On/Off", "unit" : 1 }

(look at idx, nvalue)

and accordingly trigger relay (GPIO13)

if you can implement this on firmware espeasy, if i trigger a push buton i can simple rule like this:

on wall_kitchen_1#Switch do
      Publish domoticz/in,'{"command": "switchlight", "idx": 96, "switchcmd": "Toggle" }' // id of kitchenLight
endon

this will trigger idx of domoticz and domoticz will send the mqtt command on topic domoticz/out espeasy will receive it and will trigger accordingly the realy. what do you think? is it possible to implement / fix? thanks

TD-er commented 3 years ago

You can check the 'send boot state' option, which should send the state at boot to the controller, if I'm not mistaken.

megamarco833 commented 3 years ago

I try to set the box "send boot state" in relay task at node_A but issue still be present.

megamarco833 commented 3 years ago

ciao @TD-er when you have time could you check why at reboot we have this change status? and when you have time could you read my last post? ( => why if node_B trigger domoticz (and it works, domoticz change it's status) why espeasy on node_A not react.)