Last updated on August 31, 2024
With life recently getting a little more complicated, I found myself either forgetting to or double-feeding my 9 year old Aussie Doodle. After running into this issue a few times, I sat down to implement a solution. The pantry where the dog food is located has an RGB light. So what I wanted to implement was a notification via the light to say that he’s been fed.
Requirements
- The light turns green when the dog is fed
- The light should stay on for an hour and then turn off
- An audible alert if accidentally feeding the dog a second time
- Reset the logic at noon and midnight
Hardware
I have a few extra Aqara door/window sensors, so this was a great use for it. These sensors are Zigbee-based and have a battery that lasts for a year or two. I mounted the sensor inside the lid of the food container and the magnet is on the lip of the container.
Challenges
Since the container we have has an attached lid, the lid will close after you first reach in to get the food to place it in the food bowl. So, the logic has to allow a grace period where you can reopen the container to put the scoop back in the container without thinking this is a second feeding. Additionally, I found that upon reboot of Node-Red, the system was in an unknown state. So I added a null state to the switch node to handle this case.
The Flow
The flow is started by the opening of the window sensor and then uses a switch node to divert the logic based on the number of times the sensor has been triggered. A flow variable keeps track of the count and is reset twice a day.
JSON code for import into Node-RED
1 |
[{"id":"5a858d2c83f69c95","type":"trigger-state","z":"57e41637.80bd48","name":"Food Container Opened","server":"c75798f0.9eb148","version":4,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.milo_food_container","entityIdType":"exact","debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"},{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":190,"y":5910,"wires":[["9862acc7968f8114"],[]]},{"id":"a45217da75a0269e","type":"counter","z":"57e41637.80bd48","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":1,"x":1000,"y":5900,"wires":[["deb26a478e745c63","ea3ddcc1eacfd334"]]},{"id":"48d6139dd09f67f0","type":"inject","z":"57e41637.80bd48","name":"reset 12AM","props":[{"p":"reset","v":"true","vt":"bool"}],"repeat":"","crontab":"00 00 * * *","once":false,"onceDelay":0.1,"topic":"","x":750,"y":5950,"wires":[["7cf817948ff0623b"]]},{"id":"5d4bd2cec2f1363c","type":"api-call-service","z":"57e41637.80bd48","name":"Already fed announcement!","server":"c75798f0.9eb148","version":5,"debugenabled":false,"domain":"tts","service":"google_translate_say","areaId":[],"deviceId":[],"entityId":["media_player.kitchen_display"],"data":"{\"message\":\"Milo's alread fed!\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":1090,"y":6080,"wires":[[]]},{"id":"121e43bcbd97fbaa","type":"api-call-service","z":"57e41637.80bd48","name":"Volume to 50%","server":"c75798f0.9eb148","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.kitchen_display"],"data":"{\"volume_level\":0.5}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":6080,"wires":[["5d4bd2cec2f1363c"]]},{"id":"5916f53d755b7b18","type":"inject","z":"57e41637.80bd48","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1400,"y":6070,"wires":[["5d4bd2cec2f1363c"]]},{"id":"1a19f1e3a7054d18","type":"trigger","z":"57e41637.80bd48","name":"15s","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"15","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":710,"y":5900,"wires":[["a45217da75a0269e"]]},{"id":"deb26a478e745c63","type":"change","z":"57e41637.80bd48","name":"set flow var","rules":[{"t":"set","p":"milo_container_open_count","pt":"flow","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":5900,"wires":[[]]},{"id":"9862acc7968f8114","type":"switch","z":"57e41637.80bd48","name":"count check","property":"milo_container_open_count","propertyType":"flow","rules":[{"t":"null"},{"t":"eq","v":"0","vt":"num"},{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":480,"y":5910,"wires":[["1a19f1e3a7054d18"],["1a19f1e3a7054d18"],["121e43bcbd97fbaa"]]},{"id":"5aba942fbee6d4e3","type":"change","z":"57e41637.80bd48","name":"reset flow var","rules":[{"t":"set","p":"milo_container_open_count","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":5970,"wires":[[]]},{"id":"ed1ad7d25218e3f4","type":"inject","z":"57e41637.80bd48","name":"reset 12PM","props":[{"p":"reset","v":"true","vt":"bool"}],"repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"topic":"","x":750,"y":5990,"wires":[["7cf817948ff0623b"]]},{"id":"ea3ddcc1eacfd334","type":"switch","z":"57e41637.80bd48","name":"1?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1180,"y":5970,"wires":[["f338a34d3532dc1e"]]},{"id":"f338a34d3532dc1e","type":"trigger","z":"57e41637.80bd48","name":"","op1":"ON","op2":"OFF","op1type":"str","op2type":"str","duration":"60","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":1330,"y":5970,"wires":[["5486a4f925238463"],["0e2e23206a911cac"]]},{"id":"5486a4f925238463","type":"api-call-service","z":"57e41637.80bd48","name":"Light ON","server":"c75798f0.9eb148","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.microwave_light"],"data":"{\t \"brightness_pct\":\"50\",\t \"rgb_color\":[0,255,0],\t \"transition\": \"1\"\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1510,"y":5950,"wires":[[]]},{"id":"0e2e23206a911cac","type":"api-call-service","z":"57e41637.80bd48","name":"Light OFF","server":"c75798f0.9eb148","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.microwave_light"],"data":"{\t \"brightness_pct\":\"0\",\t \"rgb_color\":[0,255,0],\t \"transition\": \"1\"\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1510,"y":6000,"wires":[[]]},{"id":"7cf817948ff0623b","type":"junction","z":"57e41637.80bd48","x":850,"y":5970,"wires":[["a45217da75a0269e","5aba942fbee6d4e3","0e2e23206a911cac"]]},{"id":"c75798f0.9eb148","type":"server","name":"Home Assistant Synology","version":5,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|ON|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":true,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}] |
Be First to Comment