I have some sensors that are set up to send their data via MQTT to NR in JSON format. When they detect, they appear similar to:
I want to send an email notification when the battery drops below the warn threshold. Basically, when a battery is new, it reports as battery_ok=1. When it gets below whatever Acurite determines warning level, it switches to battery_ok=0. I can detect this with a falling edge node easily by using a change node to break the battery_ok value out, but then I don't have the rest of the message intact. The other nodes in the triggers (e.g., deadband) seem to allow selection of the property desired (e.g., msg.payload.battery_ok).
The reason I would like to keep it, is so I could do smarter things with the notification. For the weather station, I only have 1. However, I have an array of Acurite tower sensors and it would be much cleaner and more maintainable to be notified for each sensor with a single rather than 1 flow hard coded for each sensor.
[{"id":"a2a32d63.97ea78","type":"mqtt in","z":"6f1f8b48.e80634","name":"Acurite-5n1","topic":"rtl_433/Acurite-5n1/2825/#","qos":"2","datatype":"json","broker":"b2400571.717f88","x":110,"y":60,"wires":[["504cb7c9.699908"]]},{"id":"504cb7c9.699908","type":"switch","z":"6f1f8b48.e80634","name":"filter by seq","property":"payload.sequence_num","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"gte","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":60,"wires":[["5d50bf19.7e3568"],[]]},{"id":"5d50bf19.7e3568","type":"switch","z":"6f1f8b48.e80634","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"payload.battery_ok","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":60,"wires":[["f0953c6c.be9a4"]]},{"id":"6a3e9be9.3568dc","type":"falling-edge","z":"6f1f8b48.e80634","name":"<0.5","threshold":"0.5","x":610,"y":60,"wires":[["87989dc2.6dc8e8"]]},{"id":"87989dc2.6dc8e8","type":"deduplicate","z":"6f1f8b48.e80634","name":"","keyproperty":"","registryclass":"","expiry":"86400","x":790,"y":60,"wires":[["8099434.fedd5c"],[]]},{"id":"8099434.fedd5c","type":"change","z":"6f1f8b48.e80634","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Weather station battery low","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Acurite weather station battery has dropped below 100%. Replace at soonest convenience.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":60,"wires":[[]]},{"id":"f0953c6c.be9a4","type":"change","z":"6f1f8b48.e80634","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload.battery_ok","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":120,"wires":[["6a3e9be9.3568dc"]]},{"id":"b2400571.717f88","type":"mqtt-broker","name":"RPi3","broker":"192.168.0.200","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Perhaps I can set msg.payload to the battery_ok value and retain the remainder of the JSON packet? I don't know how to do that and my quick attempt did not succeed. It replaced the entire msg.payload with the single value of battery_ok.
[{"id":"204b24ae.b9f4d4","type":"inject","z":"6f1f8b48.e80634","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test","payload":"{\"time\":\"2022-07-10 22:30:51\",\"model\":\"Acurite-5n1\",\"message_type\":49,\"id\":2825,\"channel\":\"A\",\"sequence_num\":0,\"battery_ok\":0,\"wind_avg_km_h\":0,\"wind_dir_deg\":157.5,\"rain_in\":110.47,\"mic\":\"CHECKSUM\"}","payloadType":"json","x":110,"y":180,"wires":[["c4cb371b.bea128","bc595a98.21cd28"]]},{"id":"c4cb371b.bea128","type":"debug","z":"6f1f8b48.e80634","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":300,"y":160,"wires":[]},{"id":"bc595a98.21cd28","type":"switch","z":"6f1f8b48.e80634","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"battery_ok","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":270,"y":200,"wires":[["6ab9ea8e.4ef3fc","ca7c3e7b.5b7098"]]},{"id":"6ab9ea8e.4ef3fc","type":"change","z":"6f1f8b48.e80634","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battery_ok","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":260,"wires":[["726e8d54.ddcf4c","8cfb1949.5cf4e8"]]},{"id":"726e8d54.ddcf4c","type":"falling-edge","z":"6f1f8b48.e80634","name":"<0.5","threshold":"0.5","x":530,"y":280,"wires":[[]]},{"id":"8cfb1949.5cf4e8","type":"debug","z":"6f1f8b48.e80634","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":240,"wires":[]},{"id":"ca7c3e7b.5b7098","type":"debug","z":"6f1f8b48.e80634","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":430,"y":200,"wires":[]}]