Minimun temperature the last 21 days

Hi Everyone,

I’m beginning on Node-Red and Home Assitant too.

For doing a spring garden prep notification, I’m looking to get the minimum temperature for the last 21 days. I got the temperature inside Node-Red from Dark Sky, but I didn’t find the way to recode the value with historical.

Thanks in advance for any help!

Hello, you might take a look to influxdb which fit perfectly those kind of usecases.
Just like HA recorder in sqlite, HA can store all sensor values in influxdb. Then you will be able to request data for a time frame and apply function on resultset like max, min, avg…
Once you have your request well formed look at a way to get it in node red(existing connector, custom script?).
Hassio container exists and comes with a nice tutorial from @frenck that would help you to start quickly with it.

2 Likes

First result on google with influxdb + node red :

1 Like

Thanks, @olijouve for your reply!
I have InfluxDB installed for Grafana, so I got my value there.

So I extracted the value of the temperature from InfuxDB, this data comes with time information.
I removed the time information but I’m having a hard time to convert the multiple objects to an array. I suppose it’s what’s need the calculator node.

Any subjection?

Thanks

msg.payload = msg.payload.map(x => x.value);
return msg;
1 Like

Thanks a lot, @Kermit and @olijouve for your help!

The target was to notify me when it’s time to prep my garden for winter and spring (I’m living in Quebec). I created a input_boolean in HA name summer:

input_boolean:
   summer:
      name: Summer
      icon: mdi:white-balance-sunny

When summer is on, I’m checking if the temperature will be dropping to 0 the next 5 days.
When summer is off, I’m checking if the minimum temperature was positive in the last 21 days.

In case summer or winter is coming, I send a notification to my phone.

It’s my first flow, so I’m sure it can be optimized (any subjection is welcome).
I drop my flow there in case it can be helpful for someone.

[{“id”:“2acfde26.ce8f82”,“type”:“api-call-service”,“z”:“5bdbd6ab.7e392”,“name”:“Winter is coming!”,“server”:“31f480d3.0e3b28”,“version”:1,“debugenabled”:false,“service_domain”:“notify”,“service”:“mobile_app_XXX”,“entityId”:“”,“data”:“{"title":"Winter is coming!","message":"The garden need to be prepared for winter","data":{"push":{"sound":"popcorn.wav"}}}”,“dataType”:“json”,“mergecontext”:“”,“output_location”:“”,“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1770,“y”:400,“wires”:[]},{“id”:“a8513ee4.8af8c8”,“type”:“debug”,“z”:“5bdbd6ab.7e392”,“name”:“Winter is Coming!”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“payload”,“targetType”:“msg”,“x”:1650,“y”:320,“wires”:},{“id”:“635ef727.f1d568”,“type”:“BooleanLogic”,“z”:“5bdbd6ab.7e392”,“name”:“”,“operation”:“AND”,“inputCount”:2,“topic”:“result”,“x”:1460,“y”:360,“wires”:[[“a8513ee4.8af8c8”,“45b62219.849334”]]},{“id”:“f1c8a932.6925c8”,“type”:“rbe”,“z”:“5bdbd6ab.7e392”,“name”:“”,“func”:“rbe”,“gap”:“”,“start”:“”,“inout”:“out”,“property”:“payload”,“x”:1290,“y”:320,“wires”:[[“635ef727.f1d568”]]},{“id”:“45b62219.849334”,“type”:“switch”,“z”:“5bdbd6ab.7e392”,“name”:“”,“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“true”}],“checkall”:“true”,“repair”:false,“outputs”:1,“x”:1610,“y”:400,“wires”:[[“2acfde26.ce8f82”]]},{“id”:“152523d3.dde954”,“type”:“rbe”,“z”:“5bdbd6ab.7e392”,“name”:“”,“func”:“rbe”,“gap”:“”,“start”:“”,“inout”:“out”,“property”:“payload”,“x”:1290,“y”:400,“wires”:[[“635ef727.f1d568”]]},{“id”:“c71532df.3507e8”,“type”:“inject”,“z”:“5bdbd6ab.7e392”,“name”:“”,“topic”:“”,“payload”:“”,“payloadType”:“date”,“repeat”:“”,“crontab”:“00 12 * * *”,“once”:false,“onceDelay”:0.1,“x”:230,“y”:560,“wires”:[[“e5f3dc43.c2637”]]},{“id”:“e5f3dc43.c2637”,“type”:“influxdb in”,“z”:“5bdbd6ab.7e392”,“influxdb”:“1dab2b84.ed7824”,“name”:“dark_sky_temperature”,“query”:“SELECT value FROM "°C" WHERE ("entity_id" = ‘dark_sky_temperature’) AND time > now() - 21d”,“rawOutput”:false,“precision”:“”,“retentionPolicy”:“”,“x”:440,“y”:560,“wires”:[[“2cd41634.4cffd2”]]},{“id”:“f91d7bd3.b19248”,“type”:“calculator”,“z”:“5bdbd6ab.7e392”,“name”:“Minimun “,“inputMsgField”:“payload”,“outputMsgField”:“payload”,“operation”:“min”,“constant”:””,“x”:980,“y”:560,“wires”:[[“f21e161d.6f177”]]},{“id”:“2cd41634.4cffd2”,“type”:“function”,“z”:“5bdbd6ab.7e392”,“name”:“Remove time”,“func”:“msg.payload.forEach(function(v){ delete v.time });\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:650,“y”:560,“wires”:[[“cb7cc5a3.211168”]]},{“id”:“61cbe55a.3eb084”,“type”:“api-call-service”,“z”:“5bdbd6ab.7e392”,“name”:“Spring is coming!”,“server”:“31f480d3.0e3b28”,“version”:1,“debugenabled”:false,“service_domain”:“notify”,“service”:“mobile_app_XXX”,“entityId”:“”,“data”:“{"title":"Spring is coming!","message":"No freezing temperature the last 21 days. The garden need to be prepare for spring","data":{"push":{"sound":"popcorn.wav"}}}”,“dataType”:“json”,“mergecontext”:“”,“output_location”:“”,“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1770,“y”:560,“wires”:[]},{“id”:“cb8ed0e.562e9b”,“type”:“server-state-changed”,“z”:“5bdbd6ab.7e392”,“name”:“Overnight low temperature next 5 days”,“server”:“31f480d3.0e3b28”,“version”:1,“entityidfilter”:“sensor.dark_sky_overnight_low_temperature_”,“entityidfiltertype”:“regex”,“outputinitially”:true,“state_type”:“num”,“haltifstate”:“”,“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:1,“output_only_on_state_change”:false,“x”:310,“y”:320,“wires”:[[“a109b7b8.4f7b1”]]},{“id”:“52cb7137.a120a8”,“type”:“join”,“z”:“5bdbd6ab.7e392”,“name”:“”,“mode”:“custom”,“build”:“array”,“property”:“payload”,“propertyType”:“msg”,“key”:“topic”,“joiner”:“”,“joinerType”:“str”,“accumulate”:false,“timeout”:“”,“count”:“5”,“reduceRight”:false,“reduceExp”:“”,“reduceInit”:“”,“reduceInitType”:“”,“reduceFixup”:“”,“x”:830,“y”:320,“wires”:[[“24b3fbd6.87d2b4”]]},{“id”:“a109b7b8.4f7b1”,“type”:“change”,“z”:“5bdbd6ab.7e392”,“name”:“Freezing”,“rules”:[{“t”:“set”,“p”:“topic”,“pt”:“msg”,“to”:“freezing”,“tot”:“str”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:680,“y”:320,“wires”:[[“52cb7137.a120a8”]]},{“id”:“24b3fbd6.87d2b4”,“type”:“calculator”,“z”:“5bdbd6ab.7e392”,“name”:“Minimun”,“inputMsgField”:“payload”,“outputMsgField”:“payload”,“operation”:“min”,“constant”:“”,“x”:980,“y”:320,“wires”:[[“3b972800.11c47”]]},{“id”:“cb7cc5a3.211168”,“type”:“function”,“z”:“5bdbd6ab.7e392”,“name”:“To array”,“func”:“msg.payload = msg.payload.map(x => x.value);\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:820,“y”:560,“wires”:[[“f91d7bd3.b19248”]]},{“id”:“d754f551.18c528”,“type”:“server-state-changed”,“z”:“5bdbd6ab.7e392”,“name”:“Summer”,“server”:“31f480d3.0e3b28”,“version”:1,“entityidfilter”:“input_boolean.summer”,“entityidfiltertype”:“exact”,“outputinitially”:true,“state_type”:“habool”,“haltifstate”:“”,“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:1,“output_only_on_state_change”:false,“x”:920,“y”:400,“wires”:[[“65b8ea5.0b8ec94”,“152523d3.dde954”]]},{“id”:“319d81b4.2f1c76”,“type”:“rbe”,“z”:“5bdbd6ab.7e392”,“name”:“”,“func”:“rbe”,“gap”:“”,“start”:“”,“inout”:“out”,“property”:“payload”,“x”:1290,“y”:480,“wires”:[[“3ba1bf89.b73c38”]]},{“id”:“65b8ea5.0b8ec94”,“type”:“Invert”,“z”:“5bdbd6ab.7e392”,“name”:“Invert”,“x”:1150,“y”:480,“wires”:[[“319d81b4.2f1c76”]]},{“id”:“43e21895.55d058”,“type”:“debug”,“z”:“5bdbd6ab.7e392”,“name”:“Spring is Coming!”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“payload”,“targetType”:“msg”,“x”:1650,“y”:480,“wires”:},{“id”:“3ba1bf89.b73c38”,“type”:“BooleanLogic”,“z”:“5bdbd6ab.7e392”,“name”:“”,“operation”:“AND”,“inputCount”:2,“topic”:“result”,“x”:1460,“y”:520,“wires”:[[“43e21895.55d058”,“4421328b.a228b4”]]},{“id”:“4421328b.a228b4”,“type”:“switch”,“z”:“5bdbd6ab.7e392”,“name”:“”,“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“true”}],“checkall”:“true”,“repair”:false,“outputs”:1,“x”:1610,“y”:560,“wires”:[[“61cbe55a.3eb084”]]},{“id”:“e94dcc5c.1069f8”,“type”:“rbe”,“z”:“5bdbd6ab.7e392”,“name”:“”,“func”:“rbe”,“gap”:“”,“start”:“”,“inout”:“out”,“property”:“payload”,“x”:1290,“y”:560,“wires”:[[“3ba1bf89.b73c38”]]},{“id”:“f21e161d.6f177”,“type”:“function”,“z”:“5bdbd6ab.7e392”,“name”:“positive”,“func”:“temp = msg.payload;\nif (temp > 0){\n msg.payload = true;\n}\nelse {\n msg.payload = false;\n}\nreturn msg; “,“outputs”:1,“noerr”:0,“x”:1140,“y”:560,“wires”:[[“e94dcc5c.1069f8”]]},{“id”:“3b972800.11c47”,“type”:“function”,“z”:“5bdbd6ab.7e392”,“name”:“Negative”,“func”:“temp = msg.payload;\nif (temp < 0){\n msg.payload = true;\n}\nelse {\n msg.payload = false;\n}\nreturn msg; “,“outputs”:1,“noerr”:0,“x”:1140,“y”:320,“wires”:[[“f1c8a932.6925c8”]]},{“id”:“31f480d3.0e3b28”,“type”:“server”,“z”:””,“name”:“Home Assistant”,“legacy”:false,“hassio”:false,“rejectUnauthorizedCerts”:false,“ha_boolean”:“y|yes|true|on|home|open”,“connectionDelay”:true,“cacheJson”:true},{“id”:“1dab2b84.ed7824”,“type”:“influxdb”,“z”:””,“hostname”:“192.168.XXX.XXX”,“port”:“8086”,“protocol”:“http”,“database”:“home_assistant”,“name”:“”,“usetls”:false,“tls”:“”}]

You can remove the Remove time node because the To array nodes accomplishes both tasks.

1 Like

You’re welcome, i’m glad you’ve achieved it quickly, well done !

I’ver never looked at node-red yet, but concerning extracting data i would get the Min aggregated well formated value directly from the influxdb request rather than to make transform operations on Node-Red side, it could saves you the steps before.
Anyway it works the way you’ve done it, if your confortable with it it’s the most important.

1 Like

You right thanks @Kermit !

Yes, you have a good idea to request de minimum value from InfluxDB.
There is the command if someone is interested:

SELECT MIN(value) FROM "°C" WHERE ("entity_id" = 'dark_sky_temperature') AND time > now() - 21d

Red Node is fun, very powerful and definitely addictive :slight_smile:
It’s remembering Houdini, my 3d software I’m using at work.

Thanks again @olijouve!