Ok so I just realized your title is “min and max value” so I get what you’re filtering on now.
Been doing some testing and came up with something. One challenge I faced though is the statistical nodes I mentioned all seem to work best when you have a continuous stream of data and are looking to reduce the stream. Like if you have a constant stream of data on power consumption from an IOT device and want to reduce the noise there’s a lot of tools for that. But getting the max over a whole set of data regardless of length is a bit trickier. I found a way but its probably worth considering whether you’d be better off just using a function node in this spot, the code is probably significantly simpler.
But anyway, without a function node here’s what you can do.
- Run the output through a split node
- Set
payload
to payload.state
converted to float (state is stored as a string even when numeric)
- Use the statistics node with input property set to
payload
and output property set to result
(note: input property seems to have to be payload
for some reason or I got errors, dunno why, payload.state
didn’t work). Uncheck the box that says “Only output result message” so each message going through the node is output
- Add a
switch
node which sends the output to a join
when result
is null and a debug
node that outputs the complete message object when its not. This way your statistical calculations will be debugged and your join node will wait to output anything until the original message has been fully reconstructed (i.e. everything has gone through the statistics
node)
- After the join node split to two separate change nodes. One sets
topic
to max
and the other sets topic
to min
. Feed these nodes back into the statistics
nodes. When a statistics
node gets a message with a topic set to a statistical function it will output the result of that calculation over its data set. This will then head back to your debug
node and give you the result.
In the end it looks like this:
Here’s code you can import that does this to try it out for yourself. Just put in the name of your sensor in the Get History
node and then you can play around with it from there:
[{"id":"6eaacbaa.36fe64","type":"api-get-history","z":"a74fee2d.ac9068","name":"Get history","server":"cc03735a.94933","startdate":"","enddate":"","entityid":"","entityidtype":"is","useRelativeTime":true,"relativeTime":"24 h","flatten":true,"output_type":"array","output_location_type":"msg","output_location":"payload","x":270,"y":1800,"wires":[["42163f5a.825ce"]]},{"id":"51d7d72a.3dbf28","type":"inject","z":"a74fee2d.ac9068","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":1800,"wires":[["6eaacbaa.36fe64"]]},{"id":"42163f5a.825ce","type":"split","z":"a74fee2d.ac9068","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":440,"y":1800,"wires":[["b6c1affe.7755a"]]},{"id":"5e3e26b6.18525","type":"statistics","z":"a74fee2d.ac9068","name":"","dataSetSize":0,"inputField":"payload","inputFieldType":"msg","resultField":"result","resultFieldType":"msg","parameterField":"","parameterFieldType":"msg","stripFunction":true,"resultOnly":false,"x":760,"y":1800,"wires":[["ed881de4.4eb048"]]},{"id":"546a03ff.cf8d8c","type":"join","z":"a74fee2d.ac9068","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":1090,"y":1780,"wires":[["6b265a54.f425ac"]]},{"id":"c1e4911f.3e568","type":"debug","z":"a74fee2d.ac9068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1090,"y":1820,"wires":[]},{"id":"6b265a54.f425ac","type":"link out","z":"a74fee2d.ac9068","name":"","links":["3bff4735.4bd658","c33b8fe4.2b9ab8"],"x":1215,"y":1780,"wires":[]},{"id":"3bff4735.4bd658","type":"link in","z":"a74fee2d.ac9068","name":"","links":["6b265a54.f425ac"],"x":415,"y":1860,"wires":[["1a92b252.6b5896"]]},{"id":"1a92b252.6b5896","type":"change","z":"a74fee2d.ac9068","name":"Get Max","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"topic","pt":"msg","to":"max","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1860,"wires":[["5e3e26b6.18525"]]},{"id":"ed881de4.4eb048","type":"switch","z":"a74fee2d.ac9068","name":"Result or no","property":"result","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":1800,"wires":[["546a03ff.cf8d8c"],["c1e4911f.3e568"]]},{"id":"b6c1affe.7755a","type":"string","z":"a74fee2d.ac9068","name":"Make float","methods":[{"name":"toFloat","params":[{"type":"num","value":""}]}],"prop":"payload.state","propout":"payload","object":"msg","objectout":"msg","x":590,"y":1800,"wires":[["5e3e26b6.18525"]]},{"id":"c33b8fe4.2b9ab8","type":"link in","z":"a74fee2d.ac9068","name":"","links":["6b265a54.f425ac"],"x":415,"y":1900,"wires":[["d684aca8.d849a8"]]},{"id":"d684aca8.d849a8","type":"change","z":"a74fee2d.ac9068","name":"Get Min","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"topic","pt":"msg","to":"min","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1900,"wires":[["5e3e26b6.18525"]]},{"id":"cc03735a.94933","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]