Can this be improved - flow to broadcast, via Google Assistant, which bins need to go out

Hi all,
TL;DR at the bottom, as I’ve waffled on a lot.

I’ve spent a few days putting this together and have to admit I’m quite proud that I’ve been able to figure it out - I’m still very much learning Node Red. Is it over engineered, yes! I couldn’t think of another way to achieve my goal, which was to have our Google Home devices announce the bins that need to go out the night before they’re due to be emptied.

As we have three bins and glass recycling boxes, all of which get emptied on differing schedules and, depending on bank holidays, even different days it can get a bit frustrating to have to constantly check multiple calendar cards, provided by the council, to make sure the right one(s) have gone out.

Thanks to @bruxy70’s brilliant Garbage Collection addon, coupled with @amaximuscustom Lovelace card for it, I was able to ingest all of these calendars, including the random date changes, in to Hass.io and clearly display what needs to go out and when. Brilliant! But, my missus doesn’t use Hass.io or the companion apps (nor have I been able to form an argument to have a tablet setup just to display it…yet), things just need to work for her and as long as they do and make her life easier, I can continue to spend time and money on smart home stuff and automation.

A Redditor suggested @Apipa169’s Assistant Relay for Hassio addon, in a random thread, and it got me thinking about having Hass.io, via Node Red, announce which bins to take out the night before.

I use Excel heavily for most things and struggle to get out of the mindset of how I’d achieve things using that for everything else and so started off solving this problem (that probably no one else has) there. The first step was to work out all of the bin
combinations that we could face, 15 in case anyone is wondering, and then assigning a number value to them.

image

Why start at 100? Just to make sure that I didn’t run in to issues really. I also later realised that I needed to account for the bins that weren’t going out in the sum, i.e. 103 as each bin that isn’t going out is assigned a value of 1, which as I’ve typed this out I realise now probably isn’t actually required… Hindsight, hey? Well that gives me something to tweak in v2 :joy:.

Taking this concept in to Node Red was relatively straight forward, the most difficult bit was how to sum all of the outputs together, thankfully some Googling introduced me to the join node.

I didn’t want one massive flow or that the whole thing ran in one process, so opted to have this initial flow run at 6am each day and output the result to a text file, using the file node.

Then at 7:30pm daily the second part of the flow kicks off and reads the file before decoding it and vocalising the result through our Google Home devices.

From the testing I’ve done, it seems to work as designed and I’m really happy with it. The real world testing begins tonight, sadly it’s only a single bin tomorrow but as long as it fires and says the right bin I’ll be pleased.

Full flow export can be found here.

TL;DR over engineered a flow to solve a problem, that only I probably have, but I’m a Node Red n00b and quite proud of it. Can it be improved?

Thanks. :slight_smile:

1 Like

Check out this video: https://youtu.be/E-_Sh1vkCTw?t=263
It creates sort of “for loop” in node red. So you do not have to repeat the same thing for each sensor.
Also, there is a video about Nextion displays, your wife might be ok with that…

1 Like

If your flow works for you that’s all that matters in the end. I did notice that your current state node for grass bin you have the incorrect entity id.

Here’s another possible way to do it, assuming you have the friendly name field set for each sensor.

[{"id":"8fe1eba4.29d0c8","type":"inject","z":"c7f9bb60.4afc48","name":"Run flow at 7:30pm daily","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"30 19 * * *","once":false,"onceDelay":0.1,"x":158,"y":1408,"wires":[["71f32df2.b1ef44"]]},{"id":"9c7fe94.0075b18","type":"function","z":"c7f9bb60.4afc48","name":"","func":"function humanizedList(list) {\n    let str = \"\";\n    const len = list.length;\n    for (let i = 0; i < len; i++) {\n        if(len === 1) {\n        } else if (i === len - 1) {\n            if(len > 2) str += \",\";\n            str += \" and \";\n        } else if (i !== 0) {\n            str += \", \";\n        }\n    \n        str += list[i].attributes.friendly_name;\n    }\n    return str;\n}\n\nconst message = `Don't forget to put ${msg.payload.length === 4 ? `all the bins and the Glass box` : humanizedList(msg.payload)} out tonight.`;\nmsg.payload = message;\n\nreturn msg;","outputs":1,"noerr":0,"x":498,"y":1408,"wires":[["8c357def.547b1"]]},{"id":"71f32df2.b1ef44","type":"ha-get-entities","z":"c7f9bb60.4afc48","name":"","rules":[{"property":"entity_id","logic":"includes","value":"sensor.black_bin,sensor.recycling_bin,sensor.grass_bin,sensor.glass_box","valueType":"str"},{"property":"state","logic":"is","value":"1","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":358,"y":1408,"wires":[["9c7fe94.0075b18"]]},{"id":"ab635f5.b556ba","type":"http request","z":"c7f9bb60.4afc48","name":"post","method":"POST","ret":"obj","paytoqs":false,"url":"http://10.0.0.2:3000/assistant","tls":"","persist":false,"proxy":"","authType":"","x":866,"y":1408,"wires":[[]]},{"id":"8c357def.547b1","type":"function","z":"c7f9bb60.4afc48","name":"set payload and headers","func":"msg.payload = {\n    \"name\": \"hassio\",\n    \"command\": msg.payload,\n    \"broadcast\": true\n};\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nreturn msg;","outputs":1,"noerr":0,"x":686,"y":1408,"wires":[["ab635f5.b556ba"]]}]
1 Like

Sorry for the late reply, I wanted to read up on Friendly Names first and make sure I had things setup right, along with testing it on the right day of the week when the bins are due. I’m honestly blown away that you were able to take the big jumbled mess of a flow that I came up with and condense it down to this, that works far better and is a lot more efficient. Thanks so much, I feel like I’ve learnt loads just from this!

Oh and good catch with the grass bin, lazy copying and pasting and didn’t spot that.