Gestion d'un télérupteur avec Domoticz, ESP8266 et Node red

Vos échanges, bricolages, idées et questions concernant l'ESP8266, les NodeMCU,Weemos, et consort
Répondre
yoyo73
Messages : 1
Enregistré le : 17 juil. 2019, 18:56

Gestion d'un télérupteur avec Domoticz, ESP8266 et Node red

Message par yoyo73 » 17 juil. 2019, 19:12

Bonjour,
Après de très nombreux essais je flanche.
Je veux commander via domoticz des télérupteurs. Pour cela j'ai créé une carte pour piloter le télérupteur et pour renvoyer une info de son état (fermé ou ouvert, afin d'avoir une réelle concordance quand celui-ci et commandé manuellement par un interrupteur dans la pièce).
J'ai trouvé des solutions avec un interrupteur virtuel dans Domoticz mais cela ne me plais pas : je veux uniquement un interrupteur qui permet la commande et qui indique le réel état de celui-ci.
Dans Domoticz j'ai créé un flow qui fonctionne bien (uniquement partie commande) tant que je ne connecte pas la sortie finale vers les requêtes HTTP qui commande la carte ESP8266 (ON ou OFF, visualisé dans une fenêtre de debug). Dès que je connecte les sorties vers les requêtes j'obtiens : ON pendant 5s, OFF pendant quelques ms, et à nouveau un autre cycle ON/OFF qui ne devrait pas exister. Cela pose un réel problème pour la commande d'un télérupteur.
Je soupçonne un retour par le Node HTTP Request, mais je n'en suis pas sur.

Voici le code sous Node Red :

Code : Tout sélectionner

[{"id":"2e9feabf.612206","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3398ca84.d82026","type":"mqtt in","z":"2e9feabf.612206","name":"","topic":"domoticz/out","qos":"0","datatype":"json","broker":"b1b4d14c.c0d0f","x":70,"y":40,"wires":[["5fd3ed95.ab0e8c","678acca4.7e20b4"]]},{"id":"dff85a.d4b157a8","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.nvalue","targetType":"msg","x":640,"y":660,"wires":[]},{"id":"5fd3ed95.ab0e8c","type":"json","z":"2e9feabf.612206","name":"","property":"payload.idx","action":"","pretty":false,"x":250,"y":80,"wires":[["9a16bf51.2fb02","bc23fe75.9c8a98","6a66e605.e99d3"]]},{"id":"6a66e605.e99d3","type":"switch","z":"2e9feabf.612206","name":"Republish switch","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"18","vt":"str"},{"t":"eq","v":"23","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":60,"wires":[["dff85a.d4b157a8","965c13b1.91f278"],["4b7289ad.1cf0b8"]]},{"id":"70de68de.89737","type":"function","z":"2e9feabf.612206","name":"Last action","func":"// If it does exist make it the inverse of what it was or else initialise it to false\n// (context variables persist between calls to the function)\nif (flow.get('TLR1')=== undefined){\n    if (msg.payload.nvalue == 2) {\n    //context.TLR1 = \"ON\";\n    flow.set('TLR1',\"OFF\")\n    }\n    else {\n    //{context.TLR1 = \"OFF\"}\n    flow.set('TLR1',\"ON\")}\n    // set the payload to the level and return\n    //msg.payload = context.TLR1;\n}\nmsg.payload = flow.get('TLR1') // +\" initialisation\"\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":80,"wires":[["78c3fa34.eee694"]]},{"id":"4b7289ad.1cf0b8","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.nvalue","targetType":"msg","x":580,"y":720,"wires":[]},{"id":"678acca4.7e20b4","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":250,"y":40,"wires":[]},{"id":"78c3fa34.eee694","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":890,"y":80,"wires":[]},{"id":"d007c53.89ad4b8","type":"trigger","z":"2e9feabf.612206","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":700,"y":280,"wires":[["277e32d3.95251e","9f98fe09.88331"]]},{"id":"965c13b1.91f278","type":"function","z":"2e9feabf.612206","name":"Cde TLR 1","func":"//var topic = msg.payload.retain;\n//if (topic == \"false\"){\n//    msg.payload = \"reponse\";\n//    return msg;\n//    \n//}\n//else\n//{\n    \n// If it does exist make it the inverse of what it was or else initialise it to false\n// (context variables persist between calls to the function)\nif (flow.get('TLR1')=== undefined){\n    if (msg.payload.nvalue == 2) {\n    flow.set('TLR1',\"OFF\")\n    }\n    else {\n    flow.set('TLR1',\"ON\")}\n}\n\nif ((msg.payload.nvalue == 2) && (flow.get(\"TLR1\") == \"OFF\")) {\n    msg.payload = \"1\"; // Ex commande 1 // nvalue == 2\n    flow.set('TLR1',\"ON\");\n    return msg;\n}\nif ((msg.payload.nvalue === 0) && (flow.get('TLR1') == \"ON\")) {\n    msg.payload = \"0\"; // Ex commande 2 // nvalue == 0\n    flow.set('TLR1',\"OFF\");\n    return msg;\n}\n//}","outputs":1,"noerr":0,"x":680,"y":140,"wires":[["d007c53.89ad4b8","17a4b5a4.27006a"]]},{"id":"9f98fe09.88331","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":880,"y":200,"wires":[]},{"id":"277e32d3.95251e","type":"switch","z":"2e9feabf.612206","name":"Msg 1 ou 0","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":870,"y":280,"wires":[["e5166600.130e08","7e89b924.1cfea"],["4a4f633e.a2bdcc","47791918.e6bb98"],[]]},{"id":"7e89b924.1cfea","type":"http request","z":"2e9feabf.612206","name":"HTTP Post ON","method":"GET","ret":"txt","paytoqs":false,"url":"192.168.1.51/control?cmd=GPIO,14,1","tls":"","proxy":"","authType":"basic","x":1160,"y":240,"wires":[["c9d2f6b.c4b4988"]]},{"id":"47791918.e6bb98","type":"http request","z":"2e9feabf.612206","name":"HTTP Post Off","method":"GET","ret":"txt","paytoqs":false,"url":"192.168.1.51/control?cmd=GPIO,14,0","tls":"","proxy":"","authType":"basic","x":1200,"y":300,"wires":[[]]},{"id":"17a4b5a4.27006a","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":880,"y":160,"wires":[]},{"id":"e5166600.130e08","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1220,"y":140,"wires":[]},{"id":"4a4f633e.a2bdcc","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1180,"y":360,"wires":[]},{"id":"c9d2f6b.c4b4988","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1060,"y":440,"wires":[]},{"id":"9a16bf51.2fb02","type":"debug","z":"2e9feabf.612206","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":240,"y":260,"wires":[]},{"id":"bc23fe75.9c8a98","type":"function","z":"2e9feabf.612206","name":"Filtrage Msg","func":"var topic=msg.payload.retain;\nif (topic===false){\n    msg.payload = \"reponse\";\n    return msg;\n    \n}\nelse\n{\n    msg.payload = \"demande\";\n    return msg;\n}\n","outputs":1,"noerr":0,"x":380,"y":400,"wires":[["4862243b.3f9154"]]},{"id":"4862243b.3f9154","type":"debug","z":"2e9feabf.612206","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":400,"y":500,"wires":[]},{"id":"b1b4d14c.c0d0f","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]
SVP aidez moi...

Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Neutrino
Messages : 1275
Enregistré le : 10 juil. 2015, 15:42
Localisation : Challans (85)
Contact :

Re: Gestion d'un télérupteur avec Domoticz, ESP8266 et Node red

Message par Neutrino » 17 juil. 2019, 23:22

Je pense que c'est le retour d'état qui relance le tout.
Le mieux est l'ennemie du bien.
Je passerai par un virtuel et éventuellement, je le cacherai : https://easydomoticz.com/cacher-un-widg ... -domoticz/

Peux-tu en dire plus sur ta carte ?
Ma maison à plein d'IP ! :mrgreen:

Répondre