hi, i need to listen to mqtt message from 5 different devices:
stat/tasmota_156/#
stat/tasmota_157/#
stat/tasmota_160/#
stat/tasmota_161/#
stat/tasmota_162/#
on listening to this i want to filter messages like this, example: stat/tasmota_156/POWER2 OFF
(where topic=stat/tasmota_156/POWER2 ; payload=OFF)
or another example: stat/tasmota_156/POWER2 OFF
here the output from a debug node set as complete message:
{"topic":"stat/tasmota_156/POWER9","payload":"ON","qos":0,"retain":false,"_msgid":"74a010a.335a3f"}
the variables are:
POWERX where x can be from 1 to 18
pyaload that can be OFF or ON
then i have to build an otput message like this for example:
domoticz/in {"idx":177,"nvalue":1,"svalue":"","Battery":100,"RSSI":6}
where the topic is= domoticz/in
and payload is= {"idx":177,"nvalue":1,"svalue":"","Battery":100,"RSSI":6}
here the variables are:
(idx value) = 177
(nvalue) = 1 nvalue must be aligned with OFF or ON => 1=ON 0=OFF idx will be associated to POWERX.
Here there is not a conresponding between X and idx, i mean POWER3 is not idx=3 but idx is a value that i will choose depens on listened topic(in this example topic is stat/tasmota_156/POWER2) and powerX of that topic. and it will be always the same for this topic and this power
i do not succeed on finding a best way to make this working, can someone help me?
thanks!
PRATICAL EXAMPLES
I try to clarify making examples:
example1:
topic1 to listen: stat/tasmota_156/#
so i'll receive: stat/tasmota_156/POWER7 ON
topic received=> stat/tasmota_156/POWER7
payload received=>ON
variable to be manipulate 7(=power) and ON
it should be transformed in => idx=xxx (xxx = value that i want to chose and will be always asociated to power7 and topic stat/tasmota_156/#) nvalue=1 (ON=1)
so message output will be: {"idx":xxx,"nvalue":1,"svalue":"","Battery":100,"RSSI":6}
example2:
topic2 to listen: stat/tasmota_157/#
so i'll receive: stat/tasmota_157/POWER7 ON
topic received=> stat/tasmota_156/POWER7
payload received=>ON
variable to be manipulate 7(=power) and *ON
it should be transformed in => idx=yyy* (yyy = value that i want to chose and will be always asociated to power7 and topic stat/tasmota_157/#) nvalue=1 (ON=1)
so message output will be: {"idx":yyy,"nvalue":1,"svalue":"","Battery":100,"RSSI":6}
example3:
topic2 to listen: stat/tasmota_157/#
so i'll receive: stat/tasmota_157/POWER13 OFF
topic received=> stat/tasmota_157/POWER13
payload received=>OFF
variable to be manipulate 13(=power) and OFF
it should be transformed in=> idx=zzz (zzz = a value that i want to chose and will be always asociated to power13* and topic stat/tasmota_157/#) nvalue=0 (0=OFF)
so message output will be: {"idx":zzz,"nvalue":0,"svalue":"","Battery":100,"RSSI":6}
example4:
topic3 to listen: stat/tasmota_160/#
so i'll receive: stat/tasmota_160/POWER13 OFF
topic received=> stat/tasmota_160/POWER13
payload received=>OFF
it should be transformed in=> idx=kkk (kkk = a value that i want to chose and will be always asociated to power13 and topic stat/tasmota_160/#) nvalue=0 (0=OFF)
so message output will be: {"idx":kkk,"nvalue":0,"svalue":"","Battery":100,"RSSI":6}
Basically you are only interested in the xxx and nvalue. Where do the battery and rssi come from, as they are not coming from the tasmota devices and therefore cannot be populated.
If you know the xxx,zzz etc values, you need to build some map to match against.
Example function:
t = msg.topic
p = msg.payload
idx = {
"stat/tasmota_160/POWER13":245,
"stat/tasmota_157/POWER13":129,
"stat/tasmota_157/POWER7":492
}
idxout = idx[t]
state = (p==="ON") ? 1:0
return {idx:idxout,nvalue:state}
hi, thanks so mych!!! that's fantastic!!
i tested and play a bit, it's working very good.
you are right, I'm only interested in the xxx and nvalue.
battery and rssi come from as they are and not coming from the tasmota devices and not needs be populated.
the line above {..... } is the payload
the topic to publish is: domoticz/in
so i modify your function to create msg.payload and msg.topic
can you please if i follow in the right way? thanks again!
i tested it and it works, but maybe could i wrote the function in a more "efficent" way? just to learn something, if you can, please check it
now i implemented the part two: i wont to comunicate also in opposite direction from domoticz to tasmota.
i think to do this in this way.
domoticz publish all comands in topic=domoticz/out and send the payload like:
i have the freedom to fill the description field with whatever i want, so i think to write inside: PCFtopic=esp_156_tasmota\npower=1
where \n is the separator
the topic is esp_156_tasmota
the power to trigger is = power1
and the status is nvalue = 1
also here the other parameters are fixed and not menaged.
so nodered have to catch this topic and create the output mqtt like: cmnd/esp_156_tasmota/power1 1
topic=cmnd/esp_156_tasmota/power1
payload= 1
i used a switch to filter messagge that are contain PCF, so in this case i skip unwanted message of sensors and so on...
and i wrote a function to substitue words of description and build the output command.
it works, but i think that just because you wrote the great solution of mapping topics of tasmota and idx, my solution is a workaround because i have to wrote inside every idx of domoticz the conresponded topic and power of tasmota....but i have already inside your nodered function!!!
can i skip this repetition?
maybe using a common table and pointing to this table when message start to domoticz and also when message start from tasmota
what do you think?
i attach my flow, so you can see what i do.
i also put inside some injections so have some examples.
of course if it is feasible to use only one table inside nodered, the description field of domoticz will be empty.
here my tested flow:
[{"id":"75af6cea.260c04","type":"tab","label":"luci tasmota PCF con funzione","disabled":false,"info":""},{"id":"9ccd1a18.3c2a68","type":"function","z":"75af6cea.260c04","name":"function2","func":"\n// split the description into two parts\nvar parts = msg.payload.description.split('\\n');\n\n\n// make the topic part after the equal sign of the first part\nvar topic_middle = parts[0].split(\"=\")[1];// con [1]prendo solo il primo carattere\n\n//topic_end = prendo solo la <X> di power=X\nvar topic_end = parts[1].split(\"=\")[1]\n//node.warn(topic_end); //per avere informazioni sulla var topic_end nel debug\n\n//build message topic adding cmnd/<topic>/sensor29\nmsg.topic = \"cmnd/\" + topic_middle + \"/power\" + topic_end\n\n\n// rebuild the payload and append the nvalue\nmsg.payload = msg.payload.nvalue;\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":240,"wires":[["6e0f0714.4a80c8","dd20b413.c58378","3dc3bf97.828fc","93026d6e.fe728"]]},{"id":"6e0f0714.4a80c8","type":"debug","z":"75af6cea.260c04","name":"domot_payl","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":180,"wires":[]},{"id":"dd20b413.c58378","type":"debug","z":"75af6cea.260c04","name":"domot_topic","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":650,"y":140,"wires":[]},{"id":"e9febe24.caebd8","type":"inject","z":"75af6cea.260c04","name":"ON topic=esp_156_tasmota\\npower=1","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"PCFtopic=esp_156_tasmota\\npower=1\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":177,\"name\":\"mcp_luce1\",\"nvalue\":1,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":140,"wires":[["7a9e0ce1.bbb744"]]},{"id":"2182df07.5e00d8","type":"inject","z":"75af6cea.260c04","name":"OFF topic=esp_156_tasmota\\npower=1","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"PCFtopic=esp_156_tasmota\\npower=1\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":177,\"name\":\"mcp_luce3\",\"nvalue\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":100,"wires":[["7a9e0ce1.bbb744"]]},{"id":"2f680bb8.7e10ec","type":"comment","z":"75af6cea.260c04","name":"","info":" with this function i have as output example:\n\nDESCRIZIONE IN DOMOTICZ: \ntopic=esp_156_tasmota\npower=1\n\nmsg.topic = `cmnd/esp_156_tasmota/power1`\nand\nmsg.payload = `1` oppure 0\n\n\n\n","x":440,"y":200,"wires":[]},{"id":"23f8e24f.0d2b6e","type":"mqtt in","z":"75af6cea.260c04","name":"","topic":"domoticz/out","qos":"2","datatype":"json","broker":"f0a64cae.6413e","x":90,"y":220,"wires":[["7a9e0ce1.bbb744"]]},{"id":"8cb7db72.a169b","type":"mqtt out","z":"75af6cea.260c04","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":1270,"y":480,"wires":[]},{"id":"3dc3bf97.828fc","type":"mqtt out","z":"75af6cea.260c04","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":630,"y":240,"wires":[]},{"id":"7a9e0ce1.bbb744","type":"switch","z":"75af6cea.260c04","name":"","property":"payload.description","propertyType":"msg","rules":[{"t":"cont","v":"PCF","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":260,"wires":[["9ccd1a18.3c2a68"],[]]},{"id":"119be279.b68856","type":"mqtt in","z":"75af6cea.260c04","name":"","topic":"stat/tasmota_156/#","qos":"2","datatype":"auto","broker":"f0a64cae.6413e","x":110,"y":440,"wires":[["16dd5437.7ad2f4"]]},{"id":"7d27e65a.b7068","type":"debug","z":"75af6cea.260c04","name":"TASM_topic","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":490,"y":440,"wires":[]},{"id":"16dd5437.7ad2f4","type":"function","z":"75af6cea.260c04","name":"","func":"t = msg.topic\np = msg.payload\n\nidx = {\n \"stat/tasmota_156/POWER2\":178,\n \"stat/tasmota_156/POWER1\":177,\n \"stat/tasmota_156/POWER9\":179,\n \"stat/esp_157_tasmota/POWER1\":108\n }\n \n\nidxout = idx[t]\nstate = (p===\"ON\") ? 1:0\n\npayload = {idx:idxout,nvalue:state,\"svalue\":\"\",\"Battery\":100,\"RSSI\":6} \n\nmsg.payload = payload ;\nmsg.topic = \"domoticz/in\";\nreturn msg;","outputs":1,"noerr":0,"x":355,"y":460,"wires":[["7d27e65a.b7068","5a4eb383.38ce7c","607fe357.0bdee4","ed1a2aab.5d0af8"]],"l":false},{"id":"3c4eed83.26d942","type":"inject","z":"75af6cea.260c04","name":"","topic":"stat/tasmota_156/POWER9","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":500,"wires":[["16dd5437.7ad2f4"]]},{"id":"d9b25158.4aea68","type":"inject","z":"75af6cea.260c04","name":"","topic":"stat/tasmota_159/POWER13","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":540,"wires":[["16dd5437.7ad2f4"]]},{"id":"5a4eb383.38ce7c","type":"debug","z":"75af6cea.260c04","name":"TASM_payl","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":510,"y":480,"wires":[]},{"id":"607fe357.0bdee4","type":"mqtt out","z":"75af6cea.260c04","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":670,"y":460,"wires":[]},{"id":"cef10dba.a102f","type":"inject","z":"75af6cea.260c04","name":"","topic":"stat/tasmota_156/POWER9","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":580,"wires":[["16dd5437.7ad2f4"]]},{"id":"ed1a2aab.5d0af8","type":"debug","z":"75af6cea.260c04","name":"TASM_COMPLETE","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":400,"wires":[]},{"id":"93026d6e.fe728","type":"debug","z":"75af6cea.260c04","name":"domot_COMPLETE","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":100,"wires":[]},{"id":"95d95fc4.0aca98","type":"mqtt in","z":"75af6cea.260c04","name":"","topic":"stat/esp_157_tasmota/#","qos":"2","datatype":"auto","broker":"f0a64cae.6413e","x":130,"y":400,"wires":[["16dd5437.7ad2f4"]]},{"id":"f0a64cae.6413e","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.105","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
hey no no, glad that you make this! thanks so mutch!
....anyway i edited three time the post to try to put the flow in this way but i do not succeed on that.
maybe because i did in this way: Like this
could be that the issue? (using theree of backaccent but on same line without space? )
There is 1 inject node with a single function node, this is where you define the variable, every time you deploy or restart node-red the variable will be automatically set.
In the other function nodes I use idx = global.get('idx') and the object will be available in the function node.
sorry but this not work...maybe because i explained it not well
the firts part: comunication start from tasmota:
i receive topic = stat/tasmota_156/POWER2
payload = 1 or 0
i need to convert in:
topic = domoticz/in
payload = {"idx":xxx,"nvalue":value,"svalue":"","Battery":100,"RSSI":6}
where xxx will take from global table and value (nvalue) is the payload of tasmota (1 or 0)
so in the example the payload will be: {"idx":178,"nvalue":1,"svalue":"","Battery":100,"RSSI":6}
in your function only the idx was setted, and not the nvalue and also the topic.
i succeed on modify it and make it working.
please have a look if i made it not a proper way
second part: comunication start from domoticz:
i receive topic = domoticz/out
payload = {"Battery":255,"RSSI":12,"description":"PCFtopic=esp_156_tasmota\npower=1","dtype":"Light/Switch","hwid":"6","id":"000140FE","idx":178,"name":"pcf_luce1","nvalue":1,"stype":"Switch","svalue1":"0","switchType":"On/Off","unit":1}
i need to extract: idx178 and nvalue1
inside the second function you build the topic:
topic = stat/tasmota_156/POWER9
but not the payload that shuld be 0 or 1 (taking from nvalue)
you correctly link the stat/tasmota_156/POWER9 to idx 178
but is missing the payload 1 linked to nvalue
i do not succeed on implement it.
there is also another issue, that' my guilty, becaouse for sure i do not explain well: domoticz is publishing many diferent topics on domoticz/out
so i have first of all filter only the idx that's are inside table, if it's possible
so i think that a switch node is required, correct?
otherwise, if it's not possible to filter messages using idx wrote inside global table, we can do in another way, i can write something inside description field, that a switch node can detect: if metch something i will recognize and start to manipulate, if i do not receve nothing that's matching it's because the message is not for a light, so i have not to menage it.
so first thing is filtering messages on domoticz/out that are inside the table, if it's possible otherwise i will use to filter something that i will write inside description field.
here my flow.
i make working the first part: starting from tasmota
but not understand how to make working the second part: start from domoticz
inside the flow i set the examples injection.
is it correct how i wrote the exit topic and exit payload for first part: starting from tasmota?
is working but maybe not well written
[{"id":"4e2e8cc.ec21b74","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"45a0f5b.311d50c","type":"inject","z":"4e2e8cc.ec21b74","name":"get idx - inject topic","topic":"stat/tasmota_156/POWER2 ON","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":60,"wires":[["5c9061e1.9f8dc"]]},{"id":"ef249892.d542a","type":"inject","z":"4e2e8cc.ec21b74","name":"get topic - inject idx","topic":"","payload":"179","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":280,"wires":[["a5f5ecef.233508"]]},{"id":"5c9061e1.9f8dc","type":"function","z":"4e2e8cc.ec21b74","name":"","func":"p = msg.payload\nidx = global.get(\"idx\")\ni = msg.topic\n\nidxout = idx[i]\nstate = (p===\"ON\") ? 1:0\n\npayload = {\"idx\":idxout,\"nvalue\":state,\"svalue\":\"\",\"Battery\":100,\"RSSI\":6} \n\nmsg.payload = payload ;\nmsg.topic = \"domoticz/in\";\nreturn msg;\n","outputs":1,"noerr":0,"x":415,"y":140,"wires":[["157fab48.d48595","f5751c8d.95776","5c300e44.81c328","7f93020d.61db64"]],"l":false},{"id":"a5f5ecef.233508","type":"function","z":"4e2e8cc.ec21b74","name":"","func":"\nidx = global.get(\"idx\")\ni = msg.payload\n\nlet topic = Object.keys(idx).find(k=>idx[k]===i);\n\n\n\nreturn {topic:topic}","outputs":1,"noerr":0,"x":415,"y":280,"wires":[["fe603ca2.845cb8","4325376c.fc4268","65deb4ed.b97afc","7f93020d.61db64"]],"l":false},{"id":"97668794.f66ec8","type":"inject","z":"4e2e8cc.ec21b74","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":395,"y":80,"wires":[["37abdcf.31d2424"]],"l":false},{"id":"e8a62bf7.ce9c7","type":"comment","z":"4e2e8cc.ec21b74","name":"Set global idx variable","info":"","x":440,"y":40,"wires":[]},{"id":"37abdcf.31d2424","type":"function","z":"4e2e8cc.ec21b74","name":"","func":"idx = {\n \"stat/tasmota_156/POWER2\":178,\n \"stat/tasmota_156/POWER1\":177,\n \"stat/tasmota_156/POWER9\":179,\n \"stat/esp_157_tasmota/POWER1\":108\n }\n \n \nglobal.set(\"idx\",idx)\n\nreturn null","outputs":1,"noerr":0,"x":495,"y":80,"wires":[[]],"l":false},{"id":"157fab48.d48595","type":"debug","z":"4e2e8cc.ec21b74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":240,"wires":[]},{"id":"fe603ca2.845cb8","type":"debug","z":"4e2e8cc.ec21b74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":300,"wires":[]},{"id":"4325376c.fc4268","type":"debug","z":"4e2e8cc.ec21b74","name":"domoticz_topic","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":640,"y":340,"wires":[]},{"id":"65deb4ed.b97afc","type":"debug","z":"4e2e8cc.ec21b74","name":"domoticz_payl","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":640,"y":380,"wires":[]},{"id":"5c300e44.81c328","type":"debug","z":"4e2e8cc.ec21b74","name":"TASM_payl","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":200,"wires":[]},{"id":"7f93020d.61db64","type":"mqtt out","z":"4e2e8cc.ec21b74","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":610,"y":160,"wires":[]},{"id":"f5751c8d.95776","type":"debug","z":"4e2e8cc.ec21b74","name":"TASM_topic","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":630,"y":120,"wires":[]},{"id":"e93eeeae.187b98","type":"inject","z":"4e2e8cc.ec21b74","name":"fake commands not to considerate","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=tasmota_blind2\\nblind=3\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FB\",\"idx\":171,\"name\":\"tamp_tasmota_3\",\"nvalue\":2,\"stype\":\"Switch\",\"svalue1\":\"85\",\"switchType\":\"Blinds Percentage Inverted\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":380,"wires":[["a5f5ecef.233508"]]},{"id":"3805870.b79467a","type":"inject","z":"4e2e8cc.ec21b74","name":"fake commands not to considerate","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Light/Switch\",\"id\":\"000140F9\",\"idx\":169,\"name\":\"fake_tasmota_2\",\"nvalue\":2,\"stype\":\"Switch\",\"svalue1\":\"38\",\"switchType\":\"Blinds Percentage Inverted\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":420,"wires":[["a5f5ecef.233508"]]},{"id":"dc3b694f.e4732","type":"inject","z":"4e2e8cc.ec21b74","name":"fake commands not to considerate, idx=48 is not inside table","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":48,\"name\":\"mcp_luce1\",\"nvalue\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":520,"wires":[["a5f5ecef.233508"]]},{"id":"9688cf09.1908f","type":"comment","z":"4e2e8cc.ec21b74","name":"from domoticz, fake commands coming from other devices","info":"","x":210,"y":340,"wires":[]},{"id":"d3d8c4ce.efb8f","type":"comment","z":"4e2e8cc.ec21b74","name":"i light command but not to considerate because idx is not inside the table","info":"","x":260,"y":480,"wires":[]},{"id":"912c33ba.18446","type":"comment","z":"4e2e8cc.ec21b74","name":"commands to considerate because idx is inside table","info":"","x":200,"y":600,"wires":[]},{"id":"62012d90.744be4","type":"inject","z":"4e2e8cc.ec21b74","name":"commands to considerate, idx=177 is inside table","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"PCFtopic=esp_156_tasmota\\npower=1\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":178,\"name\":\"pcf_luce1\",\"nvalue\":1,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":640,"wires":[["a5f5ecef.233508"]]},{"id":"8369ebd5.fddb48","type":"comment","z":"4e2e8cc.ec21b74","name":"start from tasmota","info":"","x":110,"y":20,"wires":[]},{"id":"16c5304a.c91958","type":"comment","z":"4e2e8cc.ec21b74","name":"start from domoticz","info":"","x":90,"y":240,"wires":[]},{"id":"9e930edc.295d1","type":"inject","z":"4e2e8cc.ec21b74","name":"","topic":"stat/tasmota_156/POWER9","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":100,"wires":[["5c9061e1.9f8dc"]]},{"id":"f72763b0.10a7b","type":"inject","z":"4e2e8cc.ec21b74","name":"","topic":"stat/tasmota_159/POWER13","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":140,"wires":[["5c9061e1.9f8dc"]]},{"id":"fd208c3d.f1316","type":"inject","z":"4e2e8cc.ec21b74","name":"","topic":"stat/tasmota_156/POWER9","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":180,"wires":[["5c9061e1.9f8dc"]]},{"id":"f0a64cae.6413e","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.105","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
sorry, but i do not succeed on that.
i try to implement this way:
start from tasmota:
i will put all sniff mqtt topics like:
stat/<topic_name>/#
and the firtst one function
but it not works because i see this message in domoticz logs:
it should be: domoticz/in {"idx":179,"nvalue":1,"svalue":"","Battery":100,"RSSI":6}
it semans that is not publishing the topic and also the payload is partial
try to use only the flow with two functions, because i understand that:
from domoticz it go hrough the first function node, output tasmota topic plus value, second function node, transforms it back to the domoticz idx value.
so i put there the sniff of tasmota: (/stat/.... )
and the sniff for domoticz/out
and at the end of functions the publish commands:
but in this case nothing is working from both side and i receive these errors contiuosly:
i understand why i recevie double message with idx 0
because when the commands statrt from domoticz tasmota trigger the device and replay with commands:
01:00:20 MQT: stat/tasmota_156/RESULT = {"POWER9":"ON"}
01:00:20 MQT: stat/tasmota_156/POWER9 = ON
so the second one is recongnized by your function in node-red, but the first one i think that is generating this:
{"svalue":"","Battery":100,"RSSI":6}
is it possible to filter the RESULT command of tasmota?
01:00:20 MQT: stat/tasmota_156/RESULT = {"POWER9":"ON"}
Instead of immediately connecting everything to mqtt, start with debug nodes only.
Check the inputs with inject nodes and directly a debug node and then check the outputs.
Perhaps the 2 function nodes confuses you, I used it to consolidate the flow and was hoping on your initiative to adapt it. Did you read up on working with messages ?
I have made it simpler. The point was that you receive ONOFF from tasmota and I assumed 01, so I have modified that for you.
If this does not work for you answer all these questions:
What is the input from domoticz/out, what is the output to tasmota, what is the input from tasmota, what is the output to domoticz/in ?
hi, thanks so much for that!
but belive me, i tried so much...without suceed
anyway i tested your flow, it woks partially, and partially i solved, below my flow and explanations and answer at your questions
input from domoticz to nodered -> topic=domoticz/out
here the firts problem: domoticz is sended out many mqtt commands periodically, for every idx inside (so temperature sensor, light, thermostat, .....whatever)
so without filtering it create a mess
i solved using a switch, where i check if inside description there is written "PCF"
if yes it's a message to manipulate for tasmota light, othewise we skip.
it could be a solution having a control inside one function: if idx sended out from domoticz metch the table we manipulate otherwise not.
i try but not succeed so i used a switch node and write inside description PCF to filter.
the output from domoticz to tasmota
in your function you send stat/<esp_topic_name>/POWER
is not correct. stat/ is for receving, to command ee need to use cmnd/<esp_topic_name>/POWERx 1 or 0
i change the function to manipulate the table and substitute stat/ with cmnd/
( /stat inside the table is correct because is used to listen. see next answer reply
/cmnd is used to comand)
so to command:
topic = cmnd/tasmota_156/POWER9
payload = 1 or 0
variables in bold
input from tasmota
in this case we have stat/<<esp_topic_name>/POWER ON or OFF
also here unfortunatly i see that tasmota when triggered reply with two different stat/
stat/tasmota_156/RESULT {"POWER9":"ON"}
stat/tasmota_156/POWER9 ON
we are intereste only on second one: stat/tasmota_156/POWER9 ON
topic = stat/tasmota_156/POWER9
payload = ON
variables = tasmota_159 and 9 and ON (or OFF)
also here i solved using a switch node that filtering if inside topic there is POWER
on first topic there is RESULT so i skip (in first command,that we not interested, POWER is inside payload)
output to domoticz/in
node-red should send to domoticz:
topic= domoticz/in
payload= {"idx":179,"nvalue":1,"svalue":"","Battery":100,"RSSI":6}
where the variables are only idx and nvalue (1 or 0)
so your flow works correctly in terms of send / receive topic and payload.
but i add the parts described above to make it working. there is a way more robust to do this? expecially filtering from domoticz.
finally I find a bug that send to domoticz/in an empty message when see idx 0
so i insert inside the function from tasmota to domoticz an if statement
maybe it can be avoided in some way?
another issue, that one is completly not solved, because not understand why, is this one:
only when i started the command from domoticz to tasmota, the command is send two times:
as you can see in the logs below.
i al so see that for example startwith light off -> press on-> i see the icon on domoticz blink and then goes to on
same issue if i switch off from domoticz -> icon blink one time then goes to off
To be honest, I am not really following you, there is a lot of text.
What is the input from domoticz/out, what is the output to tasmota, what is the input from tasmota, what is the output to domoticz/in ?
I meant, debug messages.
Did you click the link I posted above, how to work with messages ? That wil answer a lot of your questions, also watch the video playlist in that link.
ok, i was try to explain as much as possible what i find, and how i solve. did you look at my flow where i implement some solutions?
anyway the anser at these question are the 4 point list above.
here the messages: 1) input from domoticz/out {"topic":"domoticz/out","payload":{"Battery":255,"RSSI":12,"description":"PCFtopic=tasmota_156\npower=9","dtype":"Light/Switch","hwid":"6","id":"00014103","idx":179,"name":"tasmota_PCF_9","nvalue":0,"stype":"Switch","svalue1":"0","switchType":"On/Off","unit":1},"qos":0,"retain":false,"_msgid":"d2510b38.3966b8"}
but as i wrote there are many other mqtt published by domoticz in domotic/out
so we need to filter, i used inside flow posted on message above a switch node.
if message contain "PCF" i will manipulate otherwise not.
question, is possible to eliminate the switch node and using global table?
if idx number is matching the idx insert inisde global table we process otherwise we do not nothing.
2) output for tasmota {"topic":"cmnd/tasmota_156/POWER9","payload":"1","qos":0,"retain":false,"_msgid":"26fd3a8f.53a836"}
here we need to use cmnd/
and i modify your function to manipulate the global table and substitute stat/ with cmnd/
as explainde above, i see that tasmota send out every tme two different messages. We are intereste only on message with POWER inside topic.
the message with RESULT we are not intereste; that's reason why i use a node switch to filter messages from tasmota that contain power inside topic
at point 1) (when i start the command from domoticz, so domoticz/out)
i find also an issue that i'm not able to solve and not understand why is happening
every time i see a double commands.
if i click on icon swithc on, i see that icon become on, immediatly off, immediatly on again.
if it's on and i press off: it go immediatly to off, then immediatly on, finally off.
i posted the logs.
oh yes, thanks i read that article some days ago when i started with this flow, then read again and watch video...it helps a lot, still lacking something at me, but al least more clear thanks to your flow and forum reading in general searching for solutions
pleas have a look at my flow if you have time so you can understand what i did and maybe correct what i did not in a proper way.
thanks again