Like this URL query:
Code: Select all
/json.htm?type=devices&rid=237
Moderators: leecollings, remb0
Code: Select all
/json.htm?type=devices&rid=237
I think this would imply the implementation of the MQTT 'retain' option. As soon as a device subscribes to a topic, the broker sends the last message again.mvdbro wrote:When my ESP8266 boots up, i would like to update it's local status on some devices. Is it possible to request Domoticz through MQTT to send out the device status for a given idx?
yes, already thought before that it might be useful to have the retain flag set by Domoticz by default. Afaik there are no downsides to this.SweetPants wrote:I think this would imply the implementation of the MQTT 'retain' option. As soon as a device subscribes to a topic, the broker sends the last message again.mvdbro wrote:When my ESP8266 boots up, i would like to update it's local status on some devices. Is it possible to request Domoticz through MQTT to send out the device status for a given idx?
This is really usefull. Thanks for the quick development!gizmocuz wrote:Okey new command (#2562)
Request Device Info
{"command": "getdeviceinfo", "idx": 2450 }
This is right, to have retain be usefull you need separate topics per devicegizmocuz wrote:but you will only receive the last message (of one device)
yep, and making all pretty complex... leaving it like it is nowsweetpants01 wrote:This is right, to have retain be usefull you need separate topics per devicegizmocuz wrote:but you will only receive the last message (of one device)
Ha, that's nice.. it's working like a charmmaxtrash wrote:making a node-red version to create devices didn't turnout to be too complicated. I have some ideas to improve on this, stay tuned
Fixed my problem using below node-red flow to generate new topic based on dtype + idx and switch on retain when sending to the brokergizmocuz wrote:yep, and making all pretty complex... leaving it like it is nowsweetpants01 wrote:This is right, to have retain be usefull you need separate topics per devicegizmocuz wrote:but you will only receive the last message (of one device)
Code: Select all
[{"id":"86f0c28c.790f4","type":"mqtt-broker","broker":"192.168.24.250","port":"1883","clientid":""},{"id":"cdb79ec2.d268e","type":"mqtt in","name":"Domoticz Events","topic":"domoticz/out","broker":"86f0c28c.790f4","x":110.53848266601562,"y":42.69232940673828,"z":"33dd3d28.a2ce22","wires":[["d7f0bfbd.a8a99"]]},{"id":"d7f0bfbd.a8a99","type":"function","name":"Convert JSON to Topic","func":"var msgIn = JSON.parse(msg.payload);\n\nvar msg = {};\n\n// Temp + Humidity -> Temp_Humidity\n// \nvar dtype = msgIn.dtype.replace(/\\s\\+\\s/,'_');\nvar idx = msgIn.idx;\n\nmsg.topic = \"domoticz/device/\" + dtype + \"/\" + idx;\nmsg.payload = msgIn;\n\nreturn msg;","outputs":1,"valid":true,"x":293.9229736328125,"y":127.84617614746094,"z":"33dd3d28.a2ce22","wires":[["5eb6c125.d34238"]]},{"id":"5eb6c125.d34238","type":"mqtt out","name":"Domoticz Out","topic":"","qos":"0","retain":"true","broker":"86f0c28c.790f4","x":485.76922607421875,"y":42.538475036621094,"z":"33dd3d28.a2ce22","wires":[]}]
Code: Select all
[{"id":"66a92c76.9956d4","type":"mqtt-broker","broker":"homeauto.vpn.glasgownet.com","port":"1883","clientid":""},{"id":"b8f4e8e2.470b18","type":"function","name":"Average temp","func":"numdevices = 7;\n\ntotal = parseFloat(context.global.masterbedtemp) + \nparseFloat(context.global.guestbedtemp) + \nparseFloat(context.global.geeklofttemp) + \nparseFloat(context.global.kitchentemp) +\nparseFloat(context.global.studytemp) +\nparseFloat(context.global.livingroomtemp) +\nparseFloat(context.global.bottomhallwaytemp);\n\nconsole.log(total)\nmsg.payload = (total / numdevices).toFixed(2);\n//msg.payload = msg.payload + 0.5;\n\nreturn msg;","outputs":1,"valid":true,"x":977,"y":124,"z":"d5caab33.2a3558","wires":[["ec3d1fae.13c2e","b75445a3.48abb8"]]},{"id":"ec3d1fae.13c2e","type":"debug","name":"Temperature","active":true,"console":"false","complete":"false","x":1254,"y":116,"z":"d5caab33.2a3558","wires":[]},{"id":"a1ae61bd.5e51a","type":"inject","name":"Repeat","topic":"","payload":"","payloadType":"none","repeat":"300","crontab":"","once":true,"x":561,"y":71,"z":"d5caab33.2a3558","wires":[["b8f4e8e2.470b18"]]},{"id":"a4bce105.5b432","type":"mqtt out","name":"House Average Temperature Domoticz","topic":"domoticz/in","qos":"","retain":"","broker":"66a92c76.9956d4","x":1417,"y":194,"z":"d5caab33.2a3558","wires":[]},{"id":"b75445a3.48abb8","type":"function","name":"JSONify","func":"msg.payload = '{\"idx\":46, \"nvalue\": 0, \"svalue\":\"' + msg.payload + ';0;0\"}';\n\nreturn msg;","outputs":1,"valid":true,"x":1163,"y":196,"z":"d5caab33.2a3558","wires":[["a4bce105.5b432"]]},{"id":"a2d8a9ac.5d2758","type":"mqtt in","name":"Domoticz out","topic":"domoticz/out","broker":"66a92c76.9956d4","x":548,"y":244,"z":"d5caab33.2a3558","wires":[["39558984.c6aa76"]]},{"id":"39558984.c6aa76","type":"function","name":"Select payloads","func":"msg.parameters = JSON.parse(msg.payload);\n//console.log(msg.parameters);\nmsg.topic = \"debug output\";\nmsg.payload = msg.parameters.svalue1;\n\nif ( msg.parameters.idx == 35) {\n context.global.kitchentemp = msg.parameters.svalue1;\n}\n\nif ( msg.parameters.idx == 116) {\n context.global.masterbedtemp = msg.parameters.svalue1;\n}\n\nif ( msg.parameters.idx == 117) {\n context.global.geeklofttemp = msg.parameters.svalue1;\n}\n\nif ( msg.parameters.idx == 122) {\n context.global.guestbedtemp = msg.parameters.svalue1;\n}\n\nif ( msg.parameters.idx == 132) {\n context.global.livingroomtemp = msg.parameters.svalue1;\n}\n\nif ( msg.parameters.idx == 133) {\n context.global.livingroomtemp = msg.parameters.svalue1;\n}\n\nif ( msg.parameters.idx == 134) {\n context.global.bottomhallwaytemp = msg.parameters.svalue1;\n}\n\nreturn msg;","outputs":"2","valid":true,"x":763,"y":172,"z":"d5caab33.2a3558","wires":[["b8f4e8e2.470b18"],["d5306da.f2acf9"]]},{"id":"d5306da.f2acf9","type":"function","name":"Average humidity","func":"numdevices = 6;\n\ntotal = parseFloat(context.global.masterbedhum) + \nparseFloat(context.global.guestbedhum) + \nparseFloat(context.global.geeklofthum) + \nparseFloat(context.global.studyhum) +\nparseFloat(context.global.livingroomhum) +\nparseFloat(context.global.bottomhallwayhum);\n\nmsg.payload = (total / numdevices).toFixed(2);\n//msg.payload = msg.payload + 0.5;\n\nreturn msg;","outputs":1,"valid":true,"x":976,"y":258,"z":"d5caab33.2a3558","wires":[[]]}]
Code: Select all
if(isNaN(total))
{
console.log("returning null");
//dataStr='NAN';
return null;
}
not sure I completely get it but you have a board with an ESP8266 which understands MQTT using some python? If so you could adjust the python to accept messages in the JSON format as sent by Domoticz. And your python scripts should subscribe to the correct domoticz MQTT topic (/Domoticz/out)parrotface wrote:I can receive a MQTT message in a python script each time a switch/contact is made on ESP8266.
I now need the python script to display the state of this switch/contact in a dummy domoticz sensor in the dashboard.
I don't know where to start, I can use a python script to publish a message and switch a light on via the ESP8266 OK, but I now need to know the switch status in return.
Thanks
Users browsing this forum: No registered users and 0 guests