jcgoette / baby_buddy_homeassistant

This custom integration provides sensors for Baby Buddy API endpoints.
MIT License
59 stars 28 forks source link

Feedings total amount #58

Open mrmultifunk opened 2 years ago

mrmultifunk commented 2 years ago

Hello,

Thank you for this great integration!

Is it possible to extract the total feeding amount into a sensor directly from the Babybuddy API?

jcgoette commented 2 years ago

Do you mean the total amount per day? 24 hour period? Something else?

mrmultifunk commented 2 years ago

I should have been more precise. I was thinking the total amount in a 24-hour period.

jcgoette commented 2 years ago

Have you looked at the Statistics platform? Specifically, the total attribute?

mrmultifunk commented 2 years ago

Thanks for getting back to this. Yes, i am using the statistics platform now to get the totals. The challenge with this solution, is if changes are made in the Baby Buddy database, eg. if i enter a feeding in the past. I generally try to avoid this, but sometimes it is necessary.

As far as i can see, it does not look like the totals are a part of the Baby Buddy API, so maybe it is better to create a request in the Baby Buddy repo?

jcgoette commented 2 years ago

Gotcha, makes sense.

We could query API with specific lookback. Docs say date, so we just need to check if it would accept a datetime.

mrmultifunk commented 2 years ago

That would be great! I guess this would be the same with other totals (diapers, sleep etc.?)

mrmultifunk commented 2 years ago

I made some progress on this. If i call the feedings endpoint, it returns all the feedings recorded. I'm then using node red to filter this and create a sensor for the total amount and the number of bottles consumed.

Here is the flow: [{"id":"7be2b9f2d4976dbd","type":"http request","z":"35c0e2ebaea0e359","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1410,"y":180,"wires":[["c06039fdbb1ffe0d"]]},{"id":"4e1076f69e2f3ead","type":"function","z":"35c0e2ebaea0e359","name":"API call","func":"var today = new Date();\nvar date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();\nvar url = \"http://192.168.0.242:8800/api/feedings/?child=2&end_min=\"+date;\n\nmsg.headers = {}\nmsg.method = \"GET\"\nmsg.url = url \nmsg.headers['Authorization'] = 'Token replace_with_your_token';\n\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Date for API call: \"+date });\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1240,"y":180,"wires":[["7be2b9f2d4976dbd"]]},{"id":"c06039fdbb1ffe0d","type":"function","z":"35c0e2ebaea0e359","name":"Create sum from returned array","func":"var flasker = msg.payload.count;\nconst arr = msg.payload.results;\n\nconst sum = arr.reduce((accumulator, object) => {\n return accumulator + object.amount;\n}, 0);\n\nconsole.log(sum); \n\nmsg.total = sum;\nmsg.flasker = flasker;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Amount: \"+sum+\" mL\"+\", in \"+flasker+\" bottles.\" });\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1630,"y":180,"wires":[["64c86aadc96ce1f1","39d7d19af7f0a062"]]},{"id":"fb277876f28efae3","type":"ha-entity","z":"35c0e2ebaea0e359","name":"","server":"xxxxxxxxxx","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"marie_mme_total"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:baby-bottle"},{"property":"unit_of_measurement","value":"mL"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"total","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":2010,"y":180,"wires":[[]]},{"id":"64c86aadc96ce1f1","type":"rbe","z":"35c0e2ebaea0e359","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"total","topi":"topic","x":1850,"y":180,"wires":[["fb277876f28efae3"]]},{"id":"b9d1d93a5614f4cd","type":"ha-entity","z":"35c0e2ebaea0e359","name":"","server":"xxxxxxxxxx","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"marie_mme_antal_flasker"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:baby-bottle"},{"property":"unit_of_measurement","value":"flasker"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"flasker","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":2010,"y":240,"wires":[[]]},{"id":"39d7d19af7f0a062","type":"rbe","z":"35c0e2ebaea0e359","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"flasker","topi":"topic","x":1850,"y":240,"wires":[["b9d1d93a5614f4cd"]]}]

image

tango2590 commented 1 year ago

I wanted to take a moment to add what I've done here for others as well. This is based on what @mrmultifunk posted April 11th (thanks for that!) and updated to use the datetime format. I expanded the functionality to call additional information available in the API, including total pumping amounts (for supply/demand comparison) and wet/solid/total diaper counts. I plan on expanding this as our newborn gets older to call all the Tummy Time entries and calculate daily/weekly Tummy Time durations. We use a lovelace dashboard for most of our data entry which goes through NodeRed, and certain entries will trigger their respective API call sequence, as well as a midnight call to reset data for graphing purposes.

Screen Shot 2023-01-21 at 13 56 06
[{"id":"327ce73244816247","type":"group","z":"b063717f88e1c168","name":"API Calls for Additional Information","style":{"fill":"#ffdf7f","label":true,"label-position":"n","color":"#000000"},"nodes":["ca3baeedc6a34760","f8452d0462df8199","7be2b9f2d4976dbd","4e1076f69e2f3ead","c06039fdbb1ffe0d","42a6e81ca48b8aeb","262367fd8898c30a","8785ea8ec2bf9240","f57b732b6695a10e","34d7bb9cf4d76dd5","d205f3956bef0c57","4340917e5a1efbf4","bbc8f1516475a288","a0b9b966fa6fa789","79f3958a682681e7","a4fc60979263f5ad","77d638dd77557c46","31bf681540ac1e66","280540aa3eaed7c9","3ac998e90fe326d1","9dbd6aa4424a3629","a9eddc05ee43c4f7","6d42974c424ae334","1142e4b31e96f203","2545752378ad9369","6601e9ec4c7223fe","b9461331b029511c","bb2408de26d98c4f","beb9dddb4d2fb42f","001e87ed538d72c2","90f2732419094ec2"],"x":1934,"y":839,"w":1032,"h":542},{"id":"ca3baeedc6a34760","type":"inject","z":"b063717f88e1c168","g":"327ce73244816247","name":"Midnight Reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 00 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2060,"y":880,"wires":[["f8452d0462df8199"]]},{"id":"f8452d0462df8199","type":"link out","z":"b063717f88e1c168","g":"327ce73244816247","name":"link out 32","mode":"link","links":["beb9dddb4d2fb42f","001e87ed538d72c2","90f2732419094ec2"],"x":2175,"y":880,"wires":[]},{"id":"7be2b9f2d4976dbd","type":"http request","z":"b063717f88e1c168","g":"327ce73244816247","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":2350,"y":980,"wires":[["c06039fdbb1ffe0d"]]},{"id":"4e1076f69e2f3ead","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"API call","func":"var today = new Date();\nvar date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();\nvar url = \"http://10.0.1.25:8888/api/feedings/?end_min=\" + date + \"T00:00:00\";\n\nmsg.headers = {}\nmsg.method = \"GET\"\nmsg.url = url \nmsg.headers['Authorization'] = 'Token 07cad935ec79e68b7011a671a39a4f3094f99cd4';\n\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Date for API call: \" + date });\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2180,"y":980,"wires":[["7be2b9f2d4976dbd"]]},{"id":"c06039fdbb1ffe0d","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"Create sum from returned array","func":"var flasker = msg.payload.count;\nconst arr = msg.payload.results;\n\nconst sum = arr.reduce((accumulator, object) => {\n    return accumulator + object.amount;\n}, 0);\n\nconsole.log(sum);  \n\nmsg.total = sum;\nmsg.flasker = flasker;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Amount: \"+sum+\" mL\"+\", in \"+flasker+\" bottles.\" });\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2570,"y":980,"wires":[["42a6e81ca48b8aeb"]]},{"id":"42a6e81ca48b8aeb","type":"ha-sensor","z":"b063717f88e1c168","g":"327ce73244816247","name":"Daily Feeding Total","entityConfig":"2a1726fec0915452","version":0,"state":"total","stateType":"msg","attributes":[{"property":"Daily Bottles","value":"flasker","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":2830,"y":980,"wires":[[]]},{"id":"262367fd8898c30a","type":"http request","z":"b063717f88e1c168","g":"327ce73244816247","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":2350,"y":1100,"wires":[["f57b732b6695a10e"]]},{"id":"8785ea8ec2bf9240","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"API call","func":"var today = new Date();\nvar date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();\nvar url = \"http://10.0.1.25:8888/api/pumping/?date_min=\" + date + \"T00:00:00\";\n\nmsg.headers = {}\nmsg.method = \"GET\"\nmsg.url = url \nmsg.headers['Authorization'] = 'Token 07cad935ec79e68b7011a671a39a4f3094f99cd4';\n\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Date for API call: \" + date });\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2180,"y":1100,"wires":[["262367fd8898c30a"]]},{"id":"f57b732b6695a10e","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"Create sum from returned array","func":"var flasker = msg.payload.count;\nconst arr = msg.payload.results;\n\nconst sum = arr.reduce((accumulator, object) => {\n    return accumulator + object.amount;\n}, 0);\n\nconsole.log(sum);  \n\nmsg.total = sum;\nmsg.flasker = flasker;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Amount: \"+sum+\" mL\"+\". Pumped \"+flasker+\" times.\" });\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2570,"y":1100,"wires":[["34d7bb9cf4d76dd5"]]},{"id":"34d7bb9cf4d76dd5","type":"ha-sensor","z":"b063717f88e1c168","g":"327ce73244816247","name":"Daily Pumping Total","entityConfig":"9b93c096f3eba640","version":0,"state":"total","stateType":"msg","attributes":[{"property":"Times Pumped","value":"flasker","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":2840,"y":1100,"wires":[[]]},{"id":"d205f3956bef0c57","type":"comment","z":"b063717f88e1c168","g":"327ce73244816247","name":"Feedings","info":"","x":2020,"y":940,"wires":[]},{"id":"4340917e5a1efbf4","type":"comment","z":"b063717f88e1c168","g":"327ce73244816247","name":"Pumpings","info":"","x":2020,"y":1060,"wires":[]},{"id":"bbc8f1516475a288","type":"http request","z":"b063717f88e1c168","g":"327ce73244816247","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":2350,"y":1220,"wires":[["79f3958a682681e7"]]},{"id":"a0b9b966fa6fa789","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"API call","func":"var today = new Date();\nvar date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();\nvar url = \"http://10.0.1.25:8888/api/changes/?date_min=\" + date + \"T00:00:00\";\n\nmsg.headers = {}\nmsg.method = \"GET\"\nmsg.url = url \nmsg.headers['Authorization'] = 'Token 07cad935ec79e68b7011a671a39a4f3094f99cd4';\n\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Date for API call: \" + date });\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2180,"y":1220,"wires":[["bbc8f1516475a288"]]},{"id":"79f3958a682681e7","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"Create sum from returned array","func":"var count = msg.payload.count;\nconst arr = msg.payload.results;\n\nconsole.log(count);  \n\nmsg.total = count;\nmsg.count = count;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Changes: \"+count});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2570,"y":1220,"wires":[["a4fc60979263f5ad"]]},{"id":"a4fc60979263f5ad","type":"ha-sensor","z":"b063717f88e1c168","g":"327ce73244816247","name":"Daily Changes Total","entityConfig":"f712f51a98dffcac","version":0,"state":"total","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":2840,"y":1220,"wires":[[]]},{"id":"77d638dd77557c46","type":"comment","z":"b063717f88e1c168","g":"327ce73244816247","name":"Changes","info":"","x":2020,"y":1180,"wires":[]},{"id":"31bf681540ac1e66","type":"server-state-changed","z":"b063717f88e1c168","g":"327ce73244816247","name":"Feedings","server":"efbeb294.51685","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.baby_tengowski_last_feeding","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":2020,"y":980,"wires":[["4e1076f69e2f3ead"]]},{"id":"280540aa3eaed7c9","type":"server-state-changed","z":"b063717f88e1c168","g":"327ce73244816247","name":"Changes","server":"efbeb294.51685","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.baby_tengowski_last_change","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":2020,"y":1280,"wires":[["a0b9b966fa6fa789","a9eddc05ee43c4f7","2545752378ad9369"]]},{"id":"3ac998e90fe326d1","type":"server-state-changed","z":"b063717f88e1c168","g":"327ce73244816247","name":"Pumpings","server":"efbeb294.51685","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.baby_tengowski_last_pumping","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":2020,"y":1100,"wires":[["8785ea8ec2bf9240"]]},{"id":"9dbd6aa4424a3629","type":"http request","z":"b063717f88e1c168","g":"327ce73244816247","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":2350,"y":1280,"wires":[["6d42974c424ae334"]]},{"id":"a9eddc05ee43c4f7","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"API call","func":"var today = new Date();\nvar date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();\nvar url = \"http://10.0.1.25:8888/api/changes/?date_min=\" + date + \"T00:00:00\" + \"&wet=True\";\n\nmsg.headers = {}\nmsg.method = \"GET\"\nmsg.url = url \nmsg.headers['Authorization'] = 'Token 07cad935ec79e68b7011a671a39a4f3094f99cd4';\n\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Date for API call: \" + date });\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2180,"y":1280,"wires":[["9dbd6aa4424a3629"]]},{"id":"6d42974c424ae334","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"Create sum from returned array","func":"var count = msg.payload.count;\nconst arr = msg.payload.results;\n\nconsole.log(count);  \n\nmsg.total = count;\nmsg.count = count;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Changes: \"+count});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2570,"y":1280,"wires":[["b9461331b029511c"]]},{"id":"1142e4b31e96f203","type":"http request","z":"b063717f88e1c168","g":"327ce73244816247","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":2350,"y":1340,"wires":[["6601e9ec4c7223fe"]]},{"id":"2545752378ad9369","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"API call","func":"var today = new Date();\nvar date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();\nvar url = \"http://10.0.1.25:8888/api/changes/?date_min=\" + date + \"T00:00:00\" + \"&solid=True\";\n\nmsg.headers = {}\nmsg.method = \"GET\"\nmsg.url = url \nmsg.headers['Authorization'] = 'Token 07cad935ec79e68b7011a671a39a4f3094f99cd4';\n\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Date for API call: \" + date });\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2180,"y":1340,"wires":[["1142e4b31e96f203"]]},{"id":"6601e9ec4c7223fe","type":"function","z":"b063717f88e1c168","g":"327ce73244816247","name":"Create sum from returned array","func":"var count = msg.payload.count;\nconst arr = msg.payload.results;\n\nconsole.log(count);  \n\nmsg.total = count;\nmsg.count = count;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Changes: \"+count});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2570,"y":1340,"wires":[["bb2408de26d98c4f"]]},{"id":"b9461331b029511c","type":"ha-sensor","z":"b063717f88e1c168","g":"327ce73244816247","name":"Daily Wet Diapers","entityConfig":"8995f25bc509b7d9","version":0,"state":"total","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":2830,"y":1280,"wires":[[]]},{"id":"bb2408de26d98c4f","type":"ha-sensor","z":"b063717f88e1c168","g":"327ce73244816247","name":"Daily Solid Diapers","entityConfig":"5b0f1e35b743284b","version":0,"state":"total","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":2830,"y":1340,"wires":[[]]},{"id":"beb9dddb4d2fb42f","type":"link in","z":"b063717f88e1c168","g":"327ce73244816247","name":"link in 22","links":["f8452d0462df8199"],"x":2095,"y":940,"wires":[["4e1076f69e2f3ead"]]},{"id":"001e87ed538d72c2","type":"link in","z":"b063717f88e1c168","g":"327ce73244816247","name":"link in 23","links":["f8452d0462df8199"],"x":2095,"y":1060,"wires":[["8785ea8ec2bf9240"]]},{"id":"90f2732419094ec2","type":"link in","z":"b063717f88e1c168","g":"327ce73244816247","name":"link in 24","links":["f8452d0462df8199"],"x":2075,"y":1280,"wires":[["a0b9b966fa6fa789","a9eddc05ee43c4f7","2545752378ad9369"]]},{"id":"2a1726fec0915452","type":"ha-entity-config","server":"efbeb294.51685","deviceConfig":"","name":"Total Daily Feeding Amount","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Total Daily Feeding Amount"},{"property":"icon","value":"mdi:baby-bottle-outline"},{"property":"entity_category","value":""},{"property":"device_class","value":"volume"},{"property":"unit_of_measurement","value":"mL"},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"9b93c096f3eba640","type":"ha-entity-config","server":"efbeb294.51685","deviceConfig":"","name":"Total Daily Pumping Amount","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Total Daily Pumping Amount"},{"property":"icon","value":"mdi:mother-nurse"},{"property":"entity_category","value":""},{"property":"device_class","value":"volume"},{"property":"unit_of_measurement","value":"mL"},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"f712f51a98dffcac","type":"ha-entity-config","server":"efbeb294.51685","deviceConfig":"","name":"Total Daily Changes","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Total Daily Changes"},{"property":"icon","value":"mdi:emoticon-poop"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"efbeb294.51685","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"8995f25bc509b7d9","type":"ha-entity-config","server":"efbeb294.51685","deviceConfig":"","name":"Daily Wet Diapers","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Wet Diapers Today"},{"property":"icon","value":"mdi:emoticon-poop"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"5b0f1e35b743284b","type":"ha-entity-config","server":"efbeb294.51685","deviceConfig":"","name":"Daily Solid Diapers","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Solid Diapers Today"},{"property":"icon","value":"mdi:emoticon-poop"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false}]
kmanan commented 1 year ago

I made some progress on this. If i call the feedings endpoint, it returns all the feedings recorded. I'm then using node red to filter this and create a sensor for the total amount and the number of bottles consumed.

Here is the flow: [{"id":"7be2b9f2d4976dbd","type":"http request","z":"35c0e2ebaea0e359","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1410,"y":180,"wires":[["c06039fdbb1ffe0d"]]},{"id":"4e1076f69e2f3ead","type":"function","z":"35c0e2ebaea0e359","name":"API call","func":"var today = new Date();\nvar date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();\nvar url = \"http://192.168.0.242:8800/api/feedings/?child=2&end_min=\"+date;\n\nmsg.headers = {}\nmsg.method = \"GET\"\nmsg.url = url \nmsg.headers['Authorization'] = 'Token replace_with_your_token';\n\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Date for API call: \"+date });\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1240,"y":180,"wires":[["7be2b9f2d4976dbd"]]},{"id":"c06039fdbb1ffe0d","type":"function","z":"35c0e2ebaea0e359","name":"Create sum from returned array","func":"var flasker = msg.payload.count;\nconst arr = msg.payload.results;\n\nconst sum = arr.reduce((accumulator, object) => {\n return accumulator + object.amount;\n}, 0);\n\nconsole.log(sum); \n\nmsg.total = sum;\nmsg.flasker = flasker;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"Amount: \"+sum+\" mL\"+\", in \"+flasker+\" bottles.\" });\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1630,"y":180,"wires":[["64c86aadc96ce1f1","39d7d19af7f0a062"]]},{"id":"fb277876f28efae3","type":"ha-entity","z":"35c0e2ebaea0e359","name":"","server":"xxxxxxxxxx","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"marie_mme_total"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:baby-bottle"},{"property":"unit_of_measurement","value":"mL"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"total","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":2010,"y":180,"wires":[[]]},{"id":"64c86aadc96ce1f1","type":"rbe","z":"35c0e2ebaea0e359","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"total","topi":"topic","x":1850,"y":180,"wires":[["fb277876f28efae3"]]},{"id":"b9d1d93a5614f4cd","type":"ha-entity","z":"35c0e2ebaea0e359","name":"","server":"xxxxxxxxxx","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"marie_mme_antal_flasker"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:baby-bottle"},{"property":"unit_of_measurement","value":"flasker"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"flasker","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":2010,"y":240,"wires":[[]]},{"id":"39d7d19af7f0a062","type":"rbe","z":"35c0e2ebaea0e359","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"flasker","topi":"topic","x":1850,"y":240,"wires":[["b9d1d93a5614f4cd"]]}]

image

hey, this looks like exactly what I am looking for. Very new to Node Red coding. Mind helping me with a few questions:

  1. What do i enter for this -- "server":"xxxxxxxxxx"
  2. What does the stuff /?child=2&end_min=\ mean? Is this custom to your setup? What do I replace it with?
  3. Same question as above for sensor","config":[{"property":"name","value":"marie_mme_total"}
  4. Same as 3 for wires":[["64c86aadc96ce1f1","39d7d19af7f0a062"]]},{"id":"fb277876f28efae3"

Thanks!

cloudbr34k84 commented 1 year ago

just found this and want the same. Are ppl using the Node-red solution?

cloudbr34k84 commented 1 year ago

Thanks for getting back to this. Yes, i am using the statistics platform now to get the totals. The challenge with this solution, is if changes are made in the Baby Buddy database, eg. if i enter a feeding in the past. I generally try to avoid this, but sometimes it is necessary.

As far as i can see, it does not look like the totals are a part of the Baby Buddy API, so maybe it is better to create a request in the Baby Buddy repo?

do you mind sharing your Statistic code??