Hi, I am trying to activate a relay when temperature from OpenWeatherMap reaches a certain value.
Using an inject node the relay is successfully activated but when when topic and payload are sent from functions it does not work.
[{"id":"91f0be81.5623b","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a2bb2063.08297","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"e91fd94e.c36028","type":"aedes broker","z":"91f0be81.5623b","name":"","mqtt_port":1883,"mqtt_ws_port":"","cert":"","key":"","certname":"","keyname":"","dburl":"","usetls":false,"x":290,"y":60,"wires":[[]]},{"id":"6b9ea794.f10898","type":"debug","z":"91f0be81.5623b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":180,"wires":[]},{"id":"a28d3841.b18418","type":"mqtt in","z":"91f0be81.5623b","name":"","topic":"/Relay-001/status","qos":"2","datatype":"utf8","broker":"a2bb2063.08297","x":280,"y":200,"wires":[["6b9ea794.f10898"]]},{"id":"31e2f7ae.48c418","type":"mqtt out","z":"91f0be81.5623b","name":"","topic":"","qos":"","retain":"","broker":"a2bb2063.08297","x":730,"y":340,"wires":[]},{"id":"c08946df.27d148","type":"inject","z":"91f0be81.5623b","name":"Relay-001 CLOSE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"/Relay-001/command","payload":"CLOSE","payloadType":"str","x":310,"y":280,"wires":[["31e2f7ae.48c418"]]},{"id":"8059b0f5.2a1ed","type":"inject","z":"91f0be81.5623b","name":"Relay-001 OPEN","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"/Relay-001/command","payload":"OPEN","payloadType":"str","x":300,"y":340,"wires":[["31e2f7ae.48c418"]]},{"id":"7311fecb.3e02c","type":"inject","z":"91f0be81.5623b","name":"Relay-002 CLOSE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"/Relay-002/command","payload":"CLOSE","payloadType":"str","x":310,"y":400,"wires":[["31e2f7ae.48c418"]]},{"id":"d9f0a21c.539ba","type":"inject","z":"91f0be81.5623b","name":"Relay-002 OPEN","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"/Relay-002/command","payload":"OPEN","payloadType":"str","x":300,"y":460,"wires":[["31e2f7ae.48c418"]]},{"id":"c748b9e.7be8548","type":"mqtt in","z":"91f0be81.5623b","name":"","topic":"/Relay-002/status","qos":"2","datatype":"utf8","broker":"a2bb2063.08297","x":280,"y":140,"wires":[["6b9ea794.f10898"]]},{"id":"f72f398b.a52058","type":"openweathermap in","z":"91f0be81.5623b","name":"","wtype":"current","lon":"-42.821046","lat":"-22.894858","city":"","country":"","language":"en","x":300,"y":520,"wires":[["39a6954e.a4ec7a"]]},{"id":"39a6954e.a4ec7a","type":"function","z":"91f0be81.5623b","name":"","func":"\nvar msg1 = { payload:\"CLOSE\",topic:\"/Relay-001/command\"};\nvar msg2 = { payload:\"OPEN\", topic:\"/Relay-001/command\"};\n\nif(msg.payload.tempc>15){return msg1} else {return msg2}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":520,"wires":[["31e2f7ae.48c418","f7c82d07.8d1b7"]]},{"id":"f7c82d07.8d1b7","type":"debug","z":"91f0be81.5623b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":520,"wires":[]}]
When injected I have a status indicator that is activated by the remote relay that indicated relay ON or OFF. When injected the remote devices responds with ON or OFF but completely fail when it is the function who sends the command.
Assistance welcome.
Thanks
Paulo