Hello everyone,
I put a NodeRed-Flow together which should measure the energy offtake and injection correctly with an Shelly 3EM.
The Wh-values of the Shelly get injected with MQTT every 60 seconds, added together with Join/Function-Node and written either to the injection-value (if solar-plant produces more than house consumption) or written to the offtake-value. For those values I used an input_number.
To view those values in the energy dashboard, I created a template in yaml to convert the input_numbers into global sensors.
I attach the code below.
I’ll post in the next weeks, if the values match with our official digital meter of the grid opterator.
[{"id":"7f6ef726678ad590","type":"tab","label":"Saldierend MQTT","disabled":false,"info":"","env":[]},{"id":"4dff564fddf1349b","type":"change","z":"7f6ef726678ad590","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"val1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":200,"wires":[["4c52d95c665211b3"]]},{"id":"4c52d95c665211b3","type":"join","z":"7f6ef726678ad590","name":"Join","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"6","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":550,"y":340,"wires":[["8da9218cb3398bc2"]]},{"id":"10cb7b8d85d7a2fa","type":"change","z":"7f6ef726678ad590","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"val2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":260,"wires":[["4c52d95c665211b3"]]},{"id":"8da9218cb3398bc2","type":"function","z":"7f6ef726678ad590","name":"SUM","func":"msg.payload = Object.values(msg.payload).reduce((a,b) => a + parseFloat(b),0)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":340,"wires":[["8d416518864612c1"]]},{"id":"64752c3a9565984f","type":"change","z":"7f6ef726678ad590","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"val3","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":320,"wires":[["4c52d95c665211b3"]]},{"id":"e4d717b0237efdde","type":"change","z":"7f6ef726678ad590","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"val4","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":380,"wires":[["4c52d95c665211b3"]]},{"id":"e47f49165029675d","type":"change","z":"7f6ef726678ad590","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"val5","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":440,"wires":[["4c52d95c665211b3"]]},{"id":"034bfe8cc4b41258","type":"change","z":"7f6ef726678ad590","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"val6","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":500,"wires":[["4c52d95c665211b3"]]},{"id":"f2b7093a5a53258c","type":"switch","z":"7f6ef726678ad590","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"lt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1130,"y":340,"wires":[["92ab0d4b40973e6f","757ceaf1c9becdd6"],["cdfb66ae02312698","5668137c24d52fc3"]]},{"id":"92ab0d4b40973e6f","type":"change","z":"7f6ef726678ad590","name":"Neuer Wh-Wert","rules":[{"t":"set","p":"topic","pt":"msg","to":"val1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":740,"wires":[["7e2d8ba285b1535e","72d1836556a284af"]]},{"id":"cdfb66ae02312698","type":"change","z":"7f6ef726678ad590","name":"Neuer Wh-Wert","rules":[{"t":"set","p":"topic","pt":"msg","to":"val1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":1040,"wires":[["3c732a44a7805e20"]]},{"id":"7e2d8ba285b1535e","type":"join","z":"7f6ef726678ad590","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":760,"wires":[["52fd1354476abad7"]]},{"id":"3c732a44a7805e20","type":"join","z":"7f6ef726678ad590","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":680,"y":1060,"wires":[["71566bcc7728e54a"]]},{"id":"52fd1354476abad7","type":"function","z":"7f6ef726678ad590","name":"Add","func":"msg.payload = Object.values(msg.payload).reduce((a,b) => a + (parseFloat(b) || 0),0)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":760,"wires":[["3b0ac6f89791d5cb"]]},{"id":"71566bcc7728e54a","type":"function","z":"7f6ef726678ad590","name":"Add","func":"msg.payload = Object.values(msg.payload).reduce((a,b) => a + (parseFloat(b) || 0),0)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":1060,"wires":[["a755706f5666bc26"]]},{"id":"57e2be01613f64ed","type":"change","z":"7f6ef726678ad590","name":"Alter Netzbezug-Wert","rules":[{"t":"set","p":"topic","pt":"msg","to":"val2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":780,"wires":[["7e2d8ba285b1535e","b46ffb1857d49102"]]},{"id":"188cdb768d45659a","type":"change","z":"7f6ef726678ad590","name":"Alter Einspeise-Wert","rules":[{"t":"set","p":"topic","pt":"msg","to":"val2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":1080,"wires":[["3c732a44a7805e20"]]},{"id":"407268debb09a15a","type":"mqtt in","z":"7f6ef726678ad590","name":"Wh L1","topic":"shellies/shellyem3-C45BBE5F6156/emeter/0/energy","qos":"0","datatype":"auto","broker":"59474d9ba318645d","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":200,"wires":[["4dff564fddf1349b"]]},{"id":"e5cdf1949053b415","type":"mqtt in","z":"7f6ef726678ad590","name":"Wh L2","topic":"shellies/shellyem3-C45BBE5F6156/emeter/1/energy","qos":"0","datatype":"auto","broker":"59474d9ba318645d","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":260,"wires":[["10cb7b8d85d7a2fa"]]},{"id":"f8462feb8c7a1e2c","type":"mqtt in","z":"7f6ef726678ad590","name":"Wh L3","topic":"shellies/shellyem3-C45BBE5F6156/emeter/2/energy","qos":"0","datatype":"auto","broker":"59474d9ba318645d","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":320,"wires":[["64752c3a9565984f"]]},{"id":"3e93ba02ce86c0e1","type":"mqtt in","z":"7f6ef726678ad590","name":"Wh Return L1","topic":"shellies/shellyem3-C45BBE5F6156/emeter/0/returned_energy","qos":"0","datatype":"auto","broker":"59474d9ba318645d","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":380,"wires":[["e4d717b0237efdde"]]},{"id":"4eaa4eacf543d11f","type":"mqtt in","z":"7f6ef726678ad590","name":"Wh Return L2","topic":"shellies/shellyem3-C45BBE5F6156/emeter/1/returned_energy","qos":"0","datatype":"auto","broker":"59474d9ba318645d","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":440,"wires":[["e47f49165029675d"]]},{"id":"c23e75b93cd23e29","type":"mqtt in","z":"7f6ef726678ad590","name":"Wh Return L3","topic":"shellies/shellyem3-C45BBE5F6156/emeter/2/returned_energy","qos":"0","datatype":"auto","broker":"59474d9ba318645d","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":500,"wires":[["034bfe8cc4b41258"]]},{"id":"8d416518864612c1","type":"function","z":"7f6ef726678ad590","name":"/ 60000 => kWh","func":"var x = msg.payload\nmsg.payload = x/60000\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":340,"wires":[["46a32ae0c2f7464c"]]},{"id":"72d1836556a284af","type":"debug","z":"7f6ef726678ad590","name":"Neuer Wert für WH","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"msg","x":605,"y":680,"wires":[],"l":false},{"id":"b46ffb1857d49102","type":"debug","z":"7f6ef726678ad590","name":"Netzbezug Alt","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":585,"y":840,"wires":[],"l":false},{"id":"bfdd6cfc3580756b","type":"poll-state","z":"7f6ef726678ad590","name":"Input-Number: Einspeisung Total","server":"6f93cefd.a282a","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"10","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"input_number.einspeisung_total","state_type":"str","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":170,"y":1080,"wires":[["188cdb768d45659a"]]},{"id":"481ea78526b01390","type":"comment","z":"7f6ef726678ad590","name":"---------------------------------------------------------------------------- NETZBEZUG BERECHNEN ----------------------------------------------------------------------------","info":"","x":660,"y":600,"wires":[]},{"id":"76cc8c2e5b960f53","type":"comment","z":"7f6ef726678ad590","name":"---------------------------------------------------------------------------- WATTSTUNDEN ALLER SECHS SENSOREN ADDIEREN ----------------------------------------------------------------------------","info":"","x":690,"y":120,"wires":[]},{"id":"6a96a7a8b3956c5a","type":"comment","z":"7f6ef726678ad590","name":"---------------------------------------------------------------------------- EINSPEISUNG BERECHNEN ----------------------------------------------------------------------------","info":"","x":640,"y":960,"wires":[]},{"id":"c21c1fd6d2fff8da","type":"poll-state","z":"7f6ef726678ad590","name":"Input-Number: Netzbezug Total","server":"6f93cefd.a282a","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"10","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"input_number.netzbezug_total","state_type":"str","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":170,"y":780,"wires":[["57e2be01613f64ed"]]},{"id":"3b0ac6f89791d5cb","type":"api-call-service","z":"7f6ef726678ad590","name":"Neuen Netzbezug setzen","server":"6f93cefd.a282a","version":3,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.netzbezug_total","data":"{\"value\":payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1130,"y":760,"wires":[["16ac7fda9aab1997"]]},{"id":"16ac7fda9aab1997","type":"debug","z":"7f6ef726678ad590","name":"Neuer Netzbezug_Total","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1290,"y":680,"wires":[]},{"id":"757ceaf1c9becdd6","type":"debug","z":"7f6ef726678ad590","name":"Neuer Wert für WH","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"msg","x":1265,"y":260,"wires":[],"l":false},{"id":"5668137c24d52fc3","type":"debug","z":"7f6ef726678ad590","name":"Neuer Wert für WH","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"msg","x":1265,"y":420,"wires":[],"l":false},{"id":"46a32ae0c2f7464c","type":"function","z":"7f6ef726678ad590","name":"Round","func":"msg.payload = Number(msg.payload.toFixed(7));\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1010,"y":340,"wires":[["f2b7093a5a53258c"]]},{"id":"a755706f5666bc26","type":"api-call-service","z":"7f6ef726678ad590","name":"Neue Einspeisung setzen","server":"6f93cefd.a282a","version":3,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.einspeisung_total","data":"{\"value\":payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1130,"y":1060,"wires":[["e3928a8d20f685be"]]},{"id":"e3928a8d20f685be","type":"debug","z":"7f6ef726678ad590","name":"Neuer Einspeisung_Total","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1350,"y":960,"wires":[]},{"id":"59474d9ba318645d","type":"mqtt-broker","name":"HomeAssistant","broker":"192.168.0.208","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"6f93cefd.a282a","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]```