The traffic light node lets you store unsent messages while the light is “stopped”. Once it opens up it shoots out all the messages in the order they arrived (latest message last). How do I filter these so that I drop all but the latest message?
Figured out a solution.
Traffic light has store unsent set.
Goes into a join node set to manually create an array, I gave it a one second delay to collect the messages because in my case it doesn’t matter, and I couldn’t add a “complete” message or know the number of parts.
From the join node, a function to set the message payload to the data of the last array element
msg.payload = msg.payload[msg.payload.length-1]
return msg;
Purpose of this is to store the last temperature to run when we arrive back home.
Here’s a test flow if anyone wants to check it out further.
[{"id":"14ad51f0.4853be","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"971148dd.3381d8","type":"inject","z":"14ad51f0.4853be","name":"","topic":"","payload":"go","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":113,"y":61,"wires":[["53d4c145.2acfb"]]},{"id":"139fa80b.72aab8","type":"inject","z":"14ad51f0.4853be","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":117,"y":300,"wires":[["53d4c145.2acfb"]]},{"id":"53d4c145.2acfb","type":"traffic","z":"14ad51f0.4853be","name":"","property_allow":"payload","filter_allow":"go","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"stop","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":false,"differ":true,"x":456,"y":176,"wires":[["240c5db9.752492"]]},{"id":"71280a0a.432c64","type":"inject","z":"14ad51f0.4853be","name":"7pm Set Temp Kids Bed","topic":"","payload":"{\"data\":{\"entity_id\":\"climate.family_room\",\"temperature\":\"20\",\"operation_mode\":\"heat\"}}","payloadType":"json","repeat":"","crontab":"00 19 * * *","once":false,"onceDelay":0.1,"x":129,"y":130,"wires":[["53d4c145.2acfb"]]},{"id":"337e3b6d.77c704","type":"inject","z":"14ad51f0.4853be","name":"11:30pm Set Overnight Temp","topic":"","payload":"{\"data\":{\"entity_id\":\"climate.family_room\",\"temperature\":\"18\",\"operation_mode\":\"heat\"}}","payloadType":"json","repeat":"","crontab":"30 23 * * *","once":false,"onceDelay":0.1,"x":140,"y":169,"wires":[["53d4c145.2acfb"]]},{"id":"6fcb6305.86909c","type":"inject","z":"14ad51f0.4853be","name":"11am Winter Mid Peak","topic":"","payload":"{\"data\":{\"entity_id\":\"climate.family_room\",\"temperature\":\"18.5\",\"operation_mode\":\"heat\"}}","payloadType":"json","repeat":"","crontab":"01 11 * * 1,2,3,4,5","once":false,"onceDelay":0.1,"x":146,"y":212,"wires":[["53d4c145.2acfb"]]},{"id":"82e5a517.ca5b78","type":"debug","z":"14ad51f0.4853be","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":745,"y":257,"wires":[]},{"id":"240c5db9.752492","type":"join","z":"14ad51f0.4853be","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":488,"y":291,"wires":[["e81442d6.ec9a8"]]},{"id":"e81442d6.ec9a8","type":"function","z":"14ad51f0.4853be","name":"","func":"msg.payload = msg.payload[msg.payload.length-1]\n\nreturn msg;","outputs":1,"noerr":0,"x":614,"y":293,"wires":[["82e5a517.ca5b78","dc8c85d0.a09228"]]},{"id":"dc8c85d0.a09228","type":"api-call-service","z":"14ad51f0.4853be","name":"Set Temp","server":"37567a14.bdb636","service_domain":"climate","service":"set_temperature","data":"{\"entity_id\":\"climate.family_room\"}","render_data":false,"mergecontext":"","output_location":"","output_location_type":"none","x":751,"y":318,"wires":[[]]},{"id":"37567a14.bdb636","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]
2 Likes