Home usage, solarproduction, math and with if else then..? need some help

I suceeded to create a visualisation of power usage at home, it looks like this....
image
sql table tags includes 1 or 0, picked by the gui, where 1 enable color-arrows and 0 to hide them, the tags in table looks like this..
image

Now.. i need node-red to calculate kw and send tags of 1 or 0 to sql-db but.. i feel my approach wont work as i think... any suggestion where to start to calculate? my brain in stuck in a loop..

I think I understand your diagram - you want the arrows visible or invisible depending on which way the power is flowing now?

But what does it have to do with the database?

Can you show us the db structure and at least a screenshot of your flow?

you want the arrows visible or invisible depending on which way the power is flowing now?

yes

But what does it have to do with the database?

its just temporary storage, the db structure is not finished, cause i cannot get the code correct.

[{"id":"54a9a5742e6589df","type":"inject","z":"0f9de81aaa0f53ef","name":"grid 10kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"grid","payload":"10","payloadType":"num","x":1060,"y":280,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"98de6e3932b870cb","type":"inject","z":"0f9de81aaa0f53ef","name":"grid 5kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"grid","payload":"5","payloadType":"num","x":1070,"y":320,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"d64e5e3cef802ac1","type":"inject","z":"0f9de81aaa0f53ef","name":"grid 0kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"grid","payload":"0","payloadType":"num","x":1070,"y":360,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"20ecf3913e027a6d","type":"inject","z":"0f9de81aaa0f53ef","name":"pv 10kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pv","payload":"10","payloadType":"num","x":1180,"y":160,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"2eba78cae8d3539d","type":"inject","z":"0f9de81aaa0f53ef","name":"pv 5kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pv","payload":"5","payloadType":"num","x":1180,"y":200,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"617c9b100fa7de22","type":"inject","z":"0f9de81aaa0f53ef","name":"pv 0kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pv","payload":"0","payloadType":"num","x":1180,"y":240,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"568404e6d863285c","type":"inject","z":"0f9de81aaa0f53ef","name":"home 10kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"home","payload":"10","payloadType":"num","x":1310,"y":280,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"97da716273846630","type":"inject","z":"0f9de81aaa0f53ef","name":"home 5kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"home","payload":"5","payloadType":"num","x":1310,"y":320,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"c735f94eec9b7789","type":"inject","z":"0f9de81aaa0f53ef","name":"home 0kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"home","payload":"0","payloadType":"num","x":1310,"y":360,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"ed5e86035a25a4ad","type":"inject","z":"0f9de81aaa0f53ef","name":"bp 10kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bp","payload":"10","payloadType":"num","x":1180,"y":400,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"84fb9bb7243ccdc3","type":"inject","z":"0f9de81aaa0f53ef","name":"bp 5kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bp","payload":"5","payloadType":"num","x":1180,"y":440,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"f18a622f04ac9109","type":"inject","z":"0f9de81aaa0f53ef","name":"bp 0kw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bp","payload":"0","payloadType":"num","x":1180,"y":480,"wires":[["b0f91c6b7a6a9ebe"]]},{"id":"b0f91c6b7a6a9ebe","type":"join","z":"0f9de81aaa0f53ef","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1490,"y":300,"wires":[["0f0a0d4929135d48","ee178b050bd410cc"]]},{"id":"0f0a0d4929135d48","type":"debug","z":"0f9de81aaa0f53ef","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1530,"y":220,"wires":[]},{"id":"ee178b050bd410cc","type":"function","z":"0f9de81aaa0f53ef","name":"pv,home,bp","func":"//var pv = payload.pv\n//var home = payload.home\n//var bp  = payload.bp\n//var grid = \"0\"\n\n//math... \nvar plusorminus = (msg.payload.home - msg.payload.pv)\nmsg.payload = plusorminus;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1670,"y":300,"wires":[["62b7b58.d85804c"]]},{"id":"62b7b58.d85804c","type":"switch","z":"0f9de81aaa0f53ef","name":"","property":"$number(payload)","propertyType":"jsonata","rules":[{"t":"lt","v":"0","vt":"num"},{"t":"gt","v":"0","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":1510,"y":440,"wires":[["b2f576f7.07073"],["8e0f836.ea41a8"],["4855cece.93e67"]]},{"id":"4855cece.93e67","type":"debug","z":"0f9de81aaa0f53ef","name":"0","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1690,"y":480,"wires":[]},{"id":"b2f576f7.07073","type":"debug","z":"0f9de81aaa0f53ef","name":"-1 (overproduction","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1730,"y":400,"wires":[]},{"id":"8e0f836.ea41a8","type":"debug","z":"0f9de81aaa0f53ef","name":"1 (from power source)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1740,"y":440,"wires":[]}]
1 Like

When you are editing a thread these options should appear.
Screen Shot 02-13-22 at 02.41 PM

Paste you code between the back ticks.
Screen Shot 02-13-22 at 02.42 PM

1 Like

Your code still doesn't look quite right (although it will probably import OK when someone clicks it).
Did you click the 'compact' option when you copied it to the clipboard?
Screen Shot 02-13-22 at 02.48 PM

1 Like

First off, none of the joins groups (pv, grid, home or pv) will work when you press the three injects because they are all (in each group) sending the same topic and the join is waiting for three different topics.

If you click on three injects (one from home, pv and bp) then you will see a result.
If you click on three injects (one from home, pv and grid) then you will see a result.
BUT if you don't send a msg from the 'home' and 'pv' groups, the NAN appears because the function you have:
var plusorminus = (msg.payload.home - msg.payload.pv)
and if msg.payload.home or msg.payload.pv is missing you get a NAN

1 Like

i have no access to node-red for moment, this is what i wrote at the train without any error check with notepad... i think this is a good start..

i use grid meter to first check if theres a export or not, this is only the export-senario.

//debug option... remove when go production.

//grid meter
var gridA = 16,1 	//debug power from grid
var gridB = 20,4 	//debug power to grid
//home meter
var homeA = 27,8 	//debug power usage
var pvA = 32,1		//debug power production
//battery pack
var bpA = 32,1		//debug power production
var bpB = 0			//debug power usage


var gridDIFF = gridA-gridB 		//we are exporting, but to what? result is 4,3
if(gridDIFF = positive)}
//export function, this is not finished, this need to be put into a own function block...
pvA-homeA = pvMINUShome 		// result is 4,3
if(pvMINUShome==gridDIFF){
	set pv2grid = 1
	set pv2home = 1
};

if(bpA>bpB){					//is production higher than usage?
								//it was higher (but what usage?)
	var compare = (pbA+bpA)-homeA /
	if(compare==gridDIFF){
		set bp2home = 1
		set bp2grid = 1
	}
}elseif{						//it was lower,batteries are charing, but from where?
	var compare = pvA-home
	var compare = compare - gridDIFF
	if(compare == gridDIFF){
		set pv2bp = 1
		set pv2grid = 1
		set pv2home = 1
	}
}
}
//export function ends here...
//import function starts here
elseif(gridDIFF = negative){
	
}

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