Compare different msg and Trigger

Hello,

I tried to compare two values from my solar inverter.
One value is the state of charge from my battery: msg.payload
Other value should be the goal. Name of msg is: msg.payload.toSolar with value 95.6. This value is a fix value, changing each day/month.

If the solar power charge my battery the msg.payload increase and increase. If the msg.payload is equal or bigger than the value msg.payload.toSolar then an Trigger should be started.

image

[{"id":"35415e42.1457a2","type":"link in","z":"1bd00a5b.7e9796","name":"toSolar Wert","links":["5aa76440.263a4c"],"x":75,"y":2420,"wires":[["d6769cef.21438","ebdf752.9b79d88"]]},{"id":"85d3e269.3d413","type":"switch","z":"1bd00a5b.7e9796","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"payload.toSolar","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":2440,"wires":[["7c61d8f2.904908","30b30da2.cc3a82"]]},{"id":"c1d898f1.d7c888","type":"link in","z":"1bd00a5b.7e9796","name":"","links":["ef1b6ec4.06e55"],"x":75,"y":2480,"wires":[["1e621e7f.ce4382","d98a81cc.e0603"]]},{"id":"7c61d8f2.904908","type":"trigger","z":"1bd00a5b.7e9796","name":"","op1":"stop","op2":"","op1type":"str","op2type":"nul","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":600,"y":2420,"wires":[["d08829ba.642a58"]]},{"id":"30b30da2.cc3a82","type":"trigger","z":"1bd00a5b.7e9796","name":"","op1":"","op2":"3","op1type":"nul","op2type":"str","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":600,"y":2460,"wires":[["ad9b3f33.0303"]]},{"id":"d6769cef.21438","type":"debug","z":"1bd00a5b.7e9796","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload.toSolar","targetType":"msg","statusVal":"payload","statusType":"auto","x":240,"y":2340,"wires":[]},{"id":"1e621e7f.ce4382","type":"debug","z":"1bd00a5b.7e9796","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":190,"y":2540,"wires":[]},{"id":"ebdf752.9b79d88","type":"function","z":"1bd00a5b.7e9796","name":"string to number","func":"msg.payload = Number(msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":200,"y":2420,"wires":[["85d3e269.3d413"]]},{"id":"d98a81cc.e0603","type":"function","z":"1bd00a5b.7e9796","name":"string to number","func":"msg.payload = Number(msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":200,"y":2480,"wires":[["85d3e269.3d413"]]}]

I tried it but it doesn´t work. Can somebody help me?

You can't sensibly compare msg.payload with msg.payload.toSolar.

Are the two values which you want to compare in the same message eg
msg.payload = ("now": 55, "target": 100};?
if so your switch node can compare msg.payload.now with msg.payload.target

If not, store the target in context:

1 Like

Hi jbudd,

hmm I´m not an expert...
The "now" value comes from a external device and is available on msg.payload.

The target comes from a cronplus node.

I don´t understand what you mean with target in context with your example and absolutely not how I can program it.

Here is my target flow:

[{"id":"c2330005.6fdad","type":"cronplus","z":"28283065.a2357","name":"December","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"december","payloadType":"json","payload":"{\"toGrid\":96.0,\"toSolar\":98.0}","expressionType":"cron","expression":"0 */1 * * DEC *","location":"","offset":"0","solarType":"selected","solarEvents":"sunrise,sunset"}],"x":550,"y":1480,"wires":[["3b51f18b.c111ee"]]},{"id":"3b51f18b.c111ee","type":"change","z":"28283065.a2357","name":"update flow.limits","rules":[{"t":"set","p":"limits","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":1140,"wires":[["eb349c18.c008f","d70c70cb.f367b","21f0bc00.0a5b14","70b77b2f.9b6574","fe1af563.2ef258","4f8dff19.b29fa"]]},{"id":"eb349c18.c008f","type":"debug","z":"28283065.a2357","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":870,"y":1180,"wires":[]},{"id":"fe1af563.2ef258","type":"show-value","z":"28283065.a2357","name":"toSolar","path":"toSolar","x":1140,"y":1200,"wires":[["1e00a80b.db26c8"]]},{"id":"1e00a80b.db26c8","type":"calculator","z":"28283065.a2357","name":"Minus 0.1","inputMsgField":"payload.toSolar","outputMsgField":"payload.toSolar","operation":"sub","constant":"2.4","round":true,"decimals":"2","x":1300,"y":1200,"wires":[["a33735ef.fa8af8","5aa76440.263a4c"]]},{"id":"a33735ef.fa8af8","type":"debug","z":"28283065.a2357","name":"","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload.toSolar","targetType":"msg","statusVal":"payload","statusType":"auto","x":1500,"y":1220,"wires":[]}]

My data are available as your example like inject number value.

If they are in different mesages then you will need to store one in context or join the messages
here is an example of joining messages and comparing

[{"id":"3243f1f3.f1c8b6","type":"inject","z":"88fadd65b9040724","name":"solar","props":[{"p":"payload.toSolar","v":"95.6","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":580,"wires":[["ebdf752.9b79d88"]]},{"id":"ebdf752.9b79d88","type":"function","z":"88fadd65b9040724","name":"string to number","func":"msg.payload = Number(msg.payload.toSolar)\nmsg.topic = \"toSolar\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":580,"wires":[["d73e4f7.a9d763"]]},{"id":"d73e4f7.a9d763","type":"join","z":"88fadd65b9040724","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":470,"y":600,"wires":[["85d3e269.3d413"]]},{"id":"85d3e269.3d413","type":"switch","z":"88fadd65b9040724","name":"","property":"payload.charge","propertyType":"msg","rules":[{"t":"gte","v":"payload.toSolar","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":660,"y":600,"wires":[["7c61d8f2.904908","30b30da2.cc3a82"]]},{"id":"d98a81cc.e0603","type":"function","z":"88fadd65b9040724","name":"string to number","func":"msg.payload = Number(msg.payload)\nmsg.topic = \"charge\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":640,"wires":[["d73e4f7.a9d763"]]},{"id":"7c61d8f2.904908","type":"trigger","z":"88fadd65b9040724","name":"","op1":"stop","op2":"","op1type":"str","op2type":"nul","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":670,"y":540,"wires":[["1e621e7f.ce4382"]]},{"id":"30b30da2.cc3a82","type":"trigger","z":"88fadd65b9040724","name":"","op1":"","op2":"3","op1type":"nul","op2type":"str","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":650,"y":660,"wires":[["1e621e7f.ce4382"]]},{"id":"b060fa5b.23b808","type":"inject","z":"88fadd65b9040724","name":"charge","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"96","payloadType":"num","x":80,"y":640,"wires":[["d98a81cc.e0603"]]},{"id":"1e621e7f.ce4382","type":"debug","z":"88fadd65b9040724","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":720,"wires":[]}]

hope it helps.

1 Like

Hello,

THANKS it works. I love this Forum!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.