# Getting grid\_total from HA

**URL:** <https://discourse.nodered.org/t/getting-grid-total-from-ha/80076>\
**Category:** General\
**Tags:** home-assistant\
**Created:** [26 July 2023 09:25 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076 "2023-07-26T09:25:45Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [26 July 2023 09:25 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/1 "2023-07-26T09:25:45Z")

</div>

Im trying to get the grid total value from HA energy tab. But if i understand correct this is not a value you can get within HA, so i wanted to do that myself.

for that i made 4 utility meter Helpers. and in nodered i made the following function node

```auto
var tarif1 = global.get('homeassistant.homeAssistant.states["sensor.consumption_tarif1"].state');
var tarif2 = global.get('homeassistant.homeAssistant.states["sensor.consumption_tarif2"].state');
var tarif3 = global.get('homeassistant.homeAssistant.states["sensor.production_tarif1"].state');
var tarif4 = global.get('homeassistant.homeAssistant.states["sensor.production_tarif2"].state');

let c1 = parseFloat(tarif1);
let c2 = parseFloat(tarif2);
let p1 = parseFloat(tarif3);
let p2 = parseFloat(tarif4);

msg.consumption = (c1 + c2);
msg.production = (p1 + p2);
msg.gtt = msg.consumption - msg.production;

return msg;

```

But no matter what i do i keep getting NaN as msg. and i dont know why.

Anybode? thanks!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 July 2023 09:33 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/2 "2023-07-26T09:33:00Z")

</div>

You would need to check what the values in tarif1-4 are  
Add an  
`node.warn({tarif1,tarif2,tarif3,tarif4})`  
to line 5 and run the code, you will then see the HA global values that are being returned in the debug sidebar.

---

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [26 July 2023 12:01 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/3 "2023-07-26T12:01:15Z")

</div>

Hi E1cid, thanks! now i'm a little more lost. 🤣

node.warn gives the follwing:

```auto
function : (warn)
{ tarif1: undefined, tarif2: undefined, tarif3: undefined, tarif4: undefined }

```

If i make 4 'current state node' each come with the correct value.

exp. below

```auto
msg : Object
{ _msgid: "90bb32029ec3a49e", payload: "2.068", data: object }

```

Just to be sure, in the command _global.get('homeassistant.homeAssistant.states_.....

what are homeassistant and homeAssistant representing? the name off the configuration node or?, maybe i'm messing something up there (i'm running everything in docker containers, not supervised).

Thanks for thinking with me!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 July 2023 12:11 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/4 "2023-07-26T12:11:59Z")

</div>

So they are undefined, which will result in a NaN.  
Can you show us your context store in the sidebar showing the HA global vars.

This is really a HA question and you may find a quicker answer on the HA forum.

---

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [26 July 2023 13:05 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/5 "2023-07-26T13:05:38Z")

</div>

I hope this is the correct info that you asked for?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c5139ccf255fe63cf82b6e31e96b42681a13b9e.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 July 2023 13:22 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/6 "2023-07-26T13:22:29Z")

</div>

If you clicked refresh in the global section, it would appear that there are no global context vars, that would be why they are undefined.

I am not a HA user.

So you need to use the state change nodes to get the readings and add them to context. Set up 4 state change nodes and use change node to set them to a context (global) var.  
e.g  
set `global``tarif1`  
to value of `msg.``payload`.

Then use `global.get("tarif1")`

---

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [26 July 2023 13:34 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/7 "2023-07-26T13:34:40Z")

</div>

Thanks.

I will try with your hints and ask further in the HA forums.

May i quote your last answer there?

Thanks again!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 July 2023 13:47 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/8 "2023-07-26T13:47:22Z")

</div>

You are free to do whatever you wish. You may find there is a way to get states direct to node-red context. As I am not a HA user my answer is Just what info I have seen over the years, HA users may have more info for you

---

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [26 July 2023 15:58 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/9 "2023-07-26T15:58:15Z")

</div>

I think i made work with below flow (you now see that i feed the output to a matrix). I'm so proud on that. 😋

but, the msg node outputs 4x the same message. is that correct? or is there still something missing?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b6bdd73fcfb9fcc0552223b495527b62d9ab1e25.png)

```auto
var tarif1 = global.get('consumption_tarif1');
var tarif2 = global.get('consumption_tarif2');
var tarif3 = global.get('production_tarif1');
var tarif4 = global.get('production_tarif2');

let c1 = parseFloat(tarif1);
let c2 = parseFloat(tarif2);
let p1 = parseFloat(tarif3);
let p2 = parseFloat(tarif4);

var consumption = (c1 + c2);
var production = (p1 + p2);
var gtt = (consumption - production).toFixed(2);

//msg.payload = price;

msg.payload = {
    // "text": value + ' KW', 
    "text": gtt + ' ' + 'kWh',
    "icon": 32930,
    "repeat": 1,
    "pushIcon": 0
};

node.status({ fill: 'green', shape: 'ring', text: gtt + ' ' + 'kWh' });

return msg;

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 July 2023 16:08 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/10 "2023-07-26T16:08:10Z")

</div>

Export your flow. [How to import/Export a flow](https://nodered.org/docs/user-guide/editor/workspace/import-export) and paste here and i will give you a join example.

You just need to join the payload, probably don't require context at all, unless you want the readings elsewhere in another flow.

---

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [26 July 2023 18:21 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/11 "2023-07-26T18:21:19Z")

</div>

[fixed by moderator]

```auto
[{"id":"3d3ac876aebd8472","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"51baa685a0efa654","type":"inject","z":"3d3ac876aebd8472","name":"","props":[{"p":"payload"}],"repeat":"60","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":150,"y":540,"wires":[["598eee99d92290b9","537c9b9708543493","cd142b43a9c0c375","ed6aae5687ab99d2"]]},{"id":"1c7e2e601b6ef29b","type":"debug","z":"3d3ac876aebd8472","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":660,"wires":[]},{"id":"598eee99d92290b9","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get production_tarif1","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.production_tarif1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":420,"y":540,"wires":[["7ac52375126756ec"]]},{"id":"537c9b9708543493","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get production_tarif2","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.production_tarif2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":420,"y":600,"wires":[["c21d3b73b37e1446"]]},{"id":"cd142b43a9c0c375","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get consumption_tarif1","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.consumption_tarif1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":660,"wires":[["f0996d22acc979d4"]]},{"id":"ed6aae5687ab99d2","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get consumption_tarif1","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.consumption_tarif2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":720,"wires":[["b54dbb9ab83c8da4"]]},{"id":"e9ba902d7ff71e91","type":"function","z":"3d3ac876aebd8472","name":"","func":"var tarif1 = global.get('consumption_tarif1');\nvar tarif2 = global.get('consumption_tarif2');\nvar tarif3 = global.get('production_tarif1');\nvar tarif4 = global.get('production_tarif2');\n\nlet c1 = parseFloat(tarif1);\nlet c2 = parseFloat(tarif2);\nlet p1 = parseFloat(tarif3);\nlet p2 = parseFloat(tarif4);\n\nvar consumption = (c1 + c2);\nvar production = (p1 + p2);\nvar gtt = (consumption - production).toFixed(2);\n\n//msg.payload = price;\n\nmsg.payload = {\n // \"text\": value + ' KW', \n \"text\": gtt + ' ' + 'kWh',\n \"icon\": 32930,\n \"repeat\": 1,\n \"pushIcon\": 0\n};\n\nnode.status({ fill: 'green', shape: 'ring', text: gtt + ' ' + 'kWh' });\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":920,"y":540,"wires":[["1c7e2e601b6ef29b","6f96734b1b49efb4"]]},{"id":"c21d3b73b37e1446","type":"change","z":"3d3ac876aebd8472","name":"production_tarif2","rules":[{"t":"set","p":"production_tarif2","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":600,"wires":[["e9ba902d7ff71e91"]]},{"id":"f0996d22acc979d4","type":"change","z":"3d3ac876aebd8472","name":"consumption_tarif1","rules":[{"t":"set","p":"consumption_tarif1","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":660,"wires":[["e9ba902d7ff71e91"]]},{"id":"b54dbb9ab83c8da4","type":"change","z":"3d3ac876aebd8472","name":"consumption_tarif2","rules":[{"t":"set","p":"consumption_tarif2","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":720,"wires":[["e9ba902d7ff71e91"]]},{"id":"7ac52375126756ec","type":"change","z":"3d3ac876aebd8472","name":"production_tarif1","rules":[{"t":"set","p":"production_tarif1","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":540,"wires":[["e9ba902d7ff71e91"]]},{"id":"6f96734b1b49efb4","type":"mqtt out","z":"3d3ac876aebd8472","name":"","topic":"awtrix_6ffae0/custom/power_usage","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ab43d7d9dd038e9e","x":1200,"y":540,"wires":[]},{"id":"8c12cc5593f9646e","type":"server","name":"homeassistant","version":5,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":false},{"id":"ab43d7d9dd038e9e","type":"mqtt-broker","name":"Mosqitto","broker":"192.168.2.203","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":{},"userProps":"","sessionExpiry":""}]

```

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [26 July 2023 18:31 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/12 "2023-07-26T18:31:25Z")

</div>

You seem to have neglected to read @E1cid comment on how to post a flow.

We cannot import flows that are just 'Cut and Paste', the forum reformats some of the characters and so we lose some of the content.

You can edit your post by clicking the pencil icon.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 July 2023 18:44 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/13 "2023-07-26T18:44:03Z")

</div>

I don't think my link mentions using \</\> button, but I did think OP knew this, as his js code is posted correctly.

@riddertommie here is a join example with no context

```auto
[{"id":"51baa685a0efa654","type":"inject","z":"3d3ac876aebd8472","name":"","props":[{"p":"payload"}],"repeat":"60","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":150,"y":540,"wires":[["598eee99d92290b9","537c9b9708543493","cd142b43a9c0c375","ed6aae5687ab99d2"]]},{"id":"598eee99d92290b9","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get production_tarif1","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.production_tarif1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":420,"y":540,"wires":[["7ac52375126756ec"]]},{"id":"537c9b9708543493","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get production_tarif2","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.production_tarif2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":420,"y":600,"wires":[["c21d3b73b37e1446"]]},{"id":"cd142b43a9c0c375","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get consumption_tarif1","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.consumption_tarif1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":660,"wires":[["f0996d22acc979d4"]]},{"id":"ed6aae5687ab99d2","type":"api-current-state","z":"3d3ac876aebd8472","name":"Get consumption_tarif1","server":"8c12cc5593f9646e","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.consumption_tarif2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":720,"wires":[["b54dbb9ab83c8da4"]]},{"id":"7ac52375126756ec","type":"change","z":"3d3ac876aebd8472","name":"production_tarif1","rules":[{"t":"set","p":"topic","pt":"msg","to":"production_tarif1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":540,"wires":[["0525f009e6dda23f"]]},{"id":"c21d3b73b37e1446","type":"change","z":"3d3ac876aebd8472","name":"production_tarif2","rules":[{"t":"set","p":"topic","pt":"msg","to":"production_tarif2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":600,"wires":[["0525f009e6dda23f"]]},{"id":"f0996d22acc979d4","type":"change","z":"3d3ac876aebd8472","name":"consumption_tarif1","rules":[{"t":"set","p":"topic","pt":"msg","to":"consumption_tarif1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":660,"wires":[["0525f009e6dda23f"]]},{"id":"b54dbb9ab83c8da4","type":"change","z":"3d3ac876aebd8472","name":"consumption_tarif2","rules":[{"t":"set","p":"topic","pt":"msg","to":"consumption_tarif2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":720,"wires":[["0525f009e6dda23f"]]},{"id":"0525f009e6dda23f","type":"join","z":"3d3ac876aebd8472","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":910,"y":620,"wires":[["e9ba902d7ff71e91"]]},{"id":"e9ba902d7ff71e91","type":"function","z":"3d3ac876aebd8472","name":"","func":"var tarif1 = msg.consumption_tarif1;\nvar tarif2 = msg.consumption_tarif2;\nvar tarif3 = msg.production_tarif1;\nvar tarif4 = msg.production_tarif2;\n\nlet c1 = parseFloat(tarif1);\nlet c2 = parseFloat(tarif2);\nlet p1 = parseFloat(tarif3);\nlet p2 = parseFloat(tarif4);\n\nvar consumption = (c1 + c2);\nvar production = (p1 + p2);\nvar gtt = (consumption - production).toFixed(2);\n\n//msg.payload = price;\n\nmsg.payload = {\n // \"text\": value + ' KW', \n \"text\": gtt + ' ' + 'kWh',\n \"icon\": 32930,\n \"repeat\": 1,\n \"pushIcon\": 0\n};\n\nnode.status({ fill: 'green', shape: 'ring', text: gtt + ' ' + 'kWh' });\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":920,"y":540,"wires":[["1c7e2e601b6ef29b","6f96734b1b49efb4"]]},{"id":"1c7e2e601b6ef29b","type":"debug","z":"3d3ac876aebd8472","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":660,"wires":[]},{"id":"6f96734b1b49efb4","type":"mqtt out","z":"3d3ac876aebd8472","name":"","topic":"awtrix_6ffae0/custom/power_usage","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ab43d7d9dd038e9e","x":1200,"y":540,"wires":[]},{"id":"ab43d7d9dd038e9e","type":"mqtt-broker","name":"Mosqitto","broker":"192.168.2.203","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":{},"userProps":"","sessionExpiry":""}]

```

Untested as I do not have HA installed.

---

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [27 July 2023 09:13 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/14 "2023-07-27T09:13:16Z")

</div>

Hi E1cid FYI, I did run both flows and now the following happens:

Because off the bad weather here in Holland, the solar panels are not providing anything, (giving -0).

Your (joined) version is now showing NaN  
and my (old) version is still showing correct butt still sending 4 messages

I tried to copy your join node in my flow but then its complete not working, but i also see that you did something else with getting the var trafik1-4.

If i changes this in your flow

```auto
var tarif1 = msg.consumption_tarif1;
var tarif2 = msg.consumption_tarif2;
var tarif3 = msg.production_tarif1;
var tarif4 = msg.production_tarif2;

```

to

```auto
var tarif1 = global.get('consumption_tarif1');
var tarif2 = global.get('consumption_tarif2');
var tarif3 = global.get('production_tarif1');
var tarif4 = global.get('production_tarif2');

```

it works as a charm, one message with the correct value. (it does send 2 messages the first time, but no problem there i think).

Thanks!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [27 July 2023 12:51 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/15 "2023-07-27T12:51:54Z")

</div>

If you want help please provide the output of the join node, can not work on guess work. `-0` should not produce a NaN. The join requires a topic on each wire. Context should be avoided if not really needed.

I had 4 typo's in my example

```auto
var tarif1 = msg.consumption_tarif1;
var tarif2 = msg.consumption_tarif2;
var tarif3 = msg.production_tarif1;
var tarif4 = msg.production_tarif2;

```

should be

```auto
var tarif1 = msg.payload.consumption_tarif1;
var tarif2 = msg.payload.consumption_tarif2;
var tarif3 = msg.payload.production_tarif1;
var tarif4 = msg.payload.production_tarif2;

```

---

<div class="post-metadata">

**Author:** ![riddertommie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riddertommie/32/81540_2.png) [@riddertommie](https://discourse.nodered.org/u/riddertommie)\
**Post date:** [29 July 2023 10:41 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/16 "2023-07-29T10:41:41Z")

</div>

Hi, with your last add, everything is working great now.

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 September 2023 10:42 UTC](https://discourse.nodered.org/t/getting-grid-total-from-ha/80076/17 "2023-09-27T10:42:02Z")

</div>

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