Pushing array with dictionaries to HA (Node-red-contrib-home-assistant-websocket)

So I am pulling dynamic energy proces from an API and I want them in Home Assistant to make a graph. I’ve put several hours in this but just can’t figure it out. I created a rest-sensor in HA and that works fine and it’s peanuts to get those values in HA. But I want to do it the other way around. This is the dictionary I create from the API-call:

[{"Time":"2024-09-16T00:00:00","Price":0.2313,"Price excluding taxes":0.105,"Price level":"NORMAL"},{"Time":"2024-09-16T01:00:00","Price":{"total":0.1975,"energy":0.078,"startsAt":"2024-09-16T01:00:00.000+02:00","level":"CHEAP"},"Price excluding taxes":0.078,"Price level":"CHEAP"},{"Time":"2024-09-16T02:00:00","Price":{"total":0.2049,"energy":0.0839,"startsAt":"2024-09-16T02:00:00.000+02:00","level":"CHEAP"},"Price excluding taxes":0.0839,"Price level":"CHEAP"},{"Time":"2024-09-16T03:00:00","Price":{"total":0.2245,"energy":0.0996,"startsAt":"2024-09-16T03:00:00.000+02:00","level":"CHEAP"},"Price excluding taxes":0.0996,"Price level":"CHEAP"},{"Time":"2024-09-16T04:00:00","Price":{"total":0.2411,"energy":0.1128,"startsAt":"2024-09-16T04:00:00.000+02:00","level":"NORMAL"},"Price excluding taxes":0.1128,"Price level":"NORMAL"},{"Time":"2024-09-16T05:00:00","Price":{"total":0.2722,"energy":0.1377,"startsAt":"2024-09-16T05:00:00.000+02:00","level":"NORMAL"},"Price excluding taxes":0.1377,"Price level":"NORMAL"},{"Time":"2024-09-16T06:00:00","Price":{"total":0.357,"energy":0.2056,"startsAt":"2024-09-16T06:00:00.000+02:00","level":"EXPENSIVE"},"Price excluding taxes":0.2056,"Price level":"EXPENSIVE"},{"Time":"2024-09-16T07:00:00","Price":{"total":0.822,"energy":0.5776,"startsAt":"2024-09-16T07:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.5776,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T08:00:00","Price":{"total":1.8594,"energy":1.4075,"startsAt":"2024-09-16T08:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":1.4075,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T09:00:00","Price":{"total":1.3146,"energy":0.9717,"startsAt":"2024-09-16T09:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.9717,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T10:00:00","Price":{"total":0.8082,"energy":0.5665,"startsAt":"2024-09-16T10:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.5665,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T11:00:00","Price":{"total":0.6668,"energy":0.4534,"startsAt":"2024-09-16T11:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.4534,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T12:00:00","Price":{"total":0.698,"energy":0.4784,"startsAt":"2024-09-16T12:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.4784,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T13:00:00","Price":{"total":0.6674,"energy":0.4539,"startsAt":"2024-09-16T13:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.4539,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T14:00:00","Price":{"total":0.6916,"energy":0.4732,"startsAt":"2024-09-16T14:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.4732,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T15:00:00","Price":{"total":0.7072,"energy":0.4858,"startsAt":"2024-09-16T15:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.4858,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T16:00:00","Price":{"total":0.7085,"energy":0.4868,"startsAt":"2024-09-16T16:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.4868,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T17:00:00","Price":{"total":0.8056,"energy":0.5645,"startsAt":"2024-09-16T17:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.5645,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T18:00:00","Price":{"total":1.1012,"energy":0.8009,"startsAt":"2024-09-16T18:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.8009,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T19:00:00","Price":{"total":0.7436,"energy":0.5148,"startsAt":"2024-09-16T19:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.5148,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T20:00:00","Price":{"total":0.7225,"energy":0.498,"startsAt":"2024-09-16T20:00:00.000+02:00","level":"VERY_EXPENSIVE"},"Price excluding taxes":0.498,"Price level":"VERY_EXPENSIVE"},{"Time":"2024-09-16T21:00:00","Price":{"total":0.4378,"energy":0.2703,"startsAt":"2024-09-16T21:00:00.000+02:00","level":"EXPENSIVE"},"Price excluding taxes":0.2703,"Price level":"EXPENSIVE"},{"Time":"2024-09-16T22:00:00","Price":{"total":0.3574,"energy":0.2059,"startsAt":"2024-09-16T22:00:00.000+02:00","level":"NORMAL"},"Price excluding taxes":0.2059,"Price level":"NORMAL"},{"Time":"2024-09-16T23:00:00","Price":{"total":0.2982,"energy":0.1585,"startsAt":"2024-09-16T23:00:00.000+02:00","level":"CHEAP"},"Price excluding taxes":0.1585,"Price level":"CHEAP"}]

I use Node-red-contrib-home-assistant-websocket. I use a sensor node. I understood that state needs to be string, number or boolean so I just took the first item in the first dictionary. Then I created an attribute in which I put msg.payload_today with a name “Prices”. That payload gives the dictionary I just showed. But I do not see any dictionary in HA! I’m going absolutely crazy. I tried many things and also spent a lot of time searching but to no avail. Does anyone have an idea?

Are you looking in the states table in dev tools? Can you share your flow?

I’m not a big fan of creating HA entities from Node Red - I would create an MQTT sensor in HA and then publish to it from NR. Much easier to see what is happening.

At one point I would have agree but there has been a lot of updates lately and I prefer them now.

@SAFP

If you go to the nodered companion on the integration page, it will show you the entities created by NR. If you did not name the sensor before you deployed it, it generates a random name, shown below. I used you’re example.

[{"id":"03dc68887efa6251","type":"function","z":"0a325c35fc29f44e","name":"function 4","func":"\nmsg.payload_today = [{ \"Time\": \"2024-09-16T00:00:00\", \"Price\": 0.2313, \"Price excluding taxes\": 0.105, \"Price level\": \"NORMAL\" }, { \"Time\": \"2024-09-16T01:00:00\", \"Price\": { \"total\": 0.1975, \"energy\": 0.078, \"startsAt\": \"2024-09-16T01:00:00.000+02:00\", \"level\": \"CHEAP\" }, \"Price excluding taxes\": 0.078, \"Price level\": \"CHEAP\" }, { \"Time\": \"2024-09-16T02:00:00\", \"Price\": { \"total\": 0.2049, \"energy\": 0.0839, \"startsAt\": \"2024-09-16T02:00:00.000+02:00\", \"level\": \"CHEAP\" }, \"Price excluding taxes\": 0.0839, \"Price level\": \"CHEAP\" }, { \"Time\": \"2024-09-16T03:00:00\", \"Price\": { \"total\": 0.2245, \"energy\": 0.0996, \"startsAt\": \"2024-09-16T03:00:00.000+02:00\", \"level\": \"CHEAP\" }, \"Price excluding taxes\": 0.0996, \"Price level\": \"CHEAP\" }, { \"Time\": \"2024-09-16T04:00:00\", \"Price\": { \"total\": 0.2411, \"energy\": 0.1128, \"startsAt\": \"2024-09-16T04:00:00.000+02:00\", \"level\": \"NORMAL\" }, \"Price excluding taxes\": 0.1128, \"Price level\": \"NORMAL\" }, { \"Time\": \"2024-09-16T05:00:00\", \"Price\": { \"total\": 0.2722, \"energy\": 0.1377, \"startsAt\": \"2024-09-16T05:00:00.000+02:00\", \"level\": \"NORMAL\" }, \"Price excluding taxes\": 0.1377, \"Price level\": \"NORMAL\" }, { \"Time\": \"2024-09-16T06:00:00\", \"Price\": { \"total\": 0.357, \"energy\": 0.2056, \"startsAt\": \"2024-09-16T06:00:00.000+02:00\", \"level\": \"EXPENSIVE\" }, \"Price excluding taxes\": 0.2056, \"Price level\": \"EXPENSIVE\" }, { \"Time\": \"2024-09-16T07:00:00\", \"Price\": { \"total\": 0.822, \"energy\": 0.5776, \"startsAt\": \"2024-09-16T07:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.5776, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T08:00:00\", \"Price\": { \"total\": 1.8594, \"energy\": 1.4075, \"startsAt\": \"2024-09-16T08:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 1.4075, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T09:00:00\", \"Price\": { \"total\": 1.3146, \"energy\": 0.9717, \"startsAt\": \"2024-09-16T09:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.9717, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T10:00:00\", \"Price\": { \"total\": 0.8082, \"energy\": 0.5665, \"startsAt\": \"2024-09-16T10:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.5665, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T11:00:00\", \"Price\": { \"total\": 0.6668, \"energy\": 0.4534, \"startsAt\": \"2024-09-16T11:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.4534, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T12:00:00\", \"Price\": { \"total\": 0.698, \"energy\": 0.4784, \"startsAt\": \"2024-09-16T12:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.4784, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T13:00:00\", \"Price\": { \"total\": 0.6674, \"energy\": 0.4539, \"startsAt\": \"2024-09-16T13:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.4539, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T14:00:00\", \"Price\": { \"total\": 0.6916, \"energy\": 0.4732, \"startsAt\": \"2024-09-16T14:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.4732, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T15:00:00\", \"Price\": { \"total\": 0.7072, \"energy\": 0.4858, \"startsAt\": \"2024-09-16T15:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.4858, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T16:00:00\", \"Price\": { \"total\": 0.7085, \"energy\": 0.4868, \"startsAt\": \"2024-09-16T16:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.4868, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T17:00:00\", \"Price\": { \"total\": 0.8056, \"energy\": 0.5645, \"startsAt\": \"2024-09-16T17:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.5645, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T18:00:00\", \"Price\": { \"total\": 1.1012, \"energy\": 0.8009, \"startsAt\": \"2024-09-16T18:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.8009, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T19:00:00\", \"Price\": { \"total\": 0.7436, \"energy\": 0.5148, \"startsAt\": \"2024-09-16T19:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.5148, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T20:00:00\", \"Price\": { \"total\": 0.7225, \"energy\": 0.498, \"startsAt\": \"2024-09-16T20:00:00.000+02:00\", \"level\": \"VERY_EXPENSIVE\" }, \"Price excluding taxes\": 0.498, \"Price level\": \"VERY_EXPENSIVE\" }, { \"Time\": \"2024-09-16T21:00:00\", \"Price\": { \"total\": 0.4378, \"energy\": 0.2703, \"startsAt\": \"2024-09-16T21:00:00.000+02:00\", \"level\": \"EXPENSIVE\" }, \"Price excluding taxes\": 0.2703, \"Price level\": \"EXPENSIVE\" }, { \"Time\": \"2024-09-16T22:00:00\", \"Price\": { \"total\": 0.3574, \"energy\": 0.2059, \"startsAt\": \"2024-09-16T22:00:00.000+02:00\", \"level\": \"NORMAL\" }, \"Price excluding taxes\": 0.2059, \"Price level\": \"NORMAL\" }, { \"Time\": \"2024-09-16T23:00:00\", \"Price\": { \"total\": 0.2982, \"energy\": 0.1585, \"startsAt\": \"2024-09-16T23:00:00.000+02:00\", \"level\": \"CHEAP\" }, \"Price excluding taxes\": 0.1585, \"Price level\": \"CHEAP\" }];\n\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":3760,"wires":[["10f384d0f08cca94","cc674fa135b19cf8"]]},{"id":"aae181d2d2d0de74","type":"inject","z":"0a325c35fc29f44e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":530,"y":3760,"wires":[["03dc68887efa6251"]]},{"id":"10f384d0f08cca94","type":"debug","z":"0a325c35fc29f44e","name":"debug 206","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":940,"y":3740,"wires":[]},{"id":"cc674fa135b19cf8","type":"ha-sensor","z":"0a325c35fc29f44e","name":"test measurement","entityConfig":"c494497903243436","version":0,"state":"$now()","stateType":"jsonata","attributes":[{"property":"prices","value":"payload_today","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":770,"y":3900,"wires":[[]]},{"id":"c494497903243436","type":"ha-entity-config","server":"6b1110b5.183a4","deviceConfig":"","name":"test measurement","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":""},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":"date"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":true,"debugEnabled":false},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like

Not sure where to find dev tools in NR. My flow contains a lot of unused nodes since I’m experimenting, so I have copied the node in JSON that comes right after the node which creates the dictionary that I posted in the topic start.

[{"id":"7bd33ce005769d56","type":"ha-sensor","z":"f4326620f57cfd96","name":"DAP_NR","entityConfig":"8225d9f35042a916","version":0,"state":"prices_today[0].Time","stateType":"msg","attributes":[{"property":"Prices","value":"prices_today","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":760,"y":480,"wires":[[]]},{"id":"8225d9f35042a916","type":"ha-entity-config","server":"a82d47fc.bfaf68","deviceConfig":"8fa3601b18aec66b","name":"DAP_NRconfig","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"DAP"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":"EUR"},{"property":"state_class","value":""}],"resend":true,"debugEnabled":false},{"id":"a82d47fc.bfaf68","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","deviceSelector":"id","entitySelector":"id","statusSeparator":"","enableGlobalContextStore":false},{"id":"8fa3601b18aec66b","type":"ha-device-config","name":"Tibber_prices_NR","hwVersion":"","manufacturer":"Node-RED","model":"Tibber day ahead prices","swVersion":""}]

I certainly don’t have those properties in HA. I need to do something else right now but I’ll try to learn from your flow in a couple of hours. Thanks for sharing.

Edit: I compared our flow and don’t see any meaningful differences. However, I have messed with names in NR and HA only shows the old names. I can’t remove the entities in HA, the button is greyed out. Is there any way to just delete all those entities created by NR and have them inserted again?

Edit 2: for some reason I have been able to delete the “old” sensor. Injected again and now there is one sensor without any state history and with the notification that the sensor is not available.

In order to delete a sensor, you will need to delete it’s entity config. Open a sensor node, select the entity config and then hit edit(pencil icon), top left delete, then deploy.

Go to the companion integration and look at the entities it provides to see that it has been completely removed.

This goes for all entities created in nodered. You can also find all of your ha entity config nodes where the debug panel is by selecting the configuration node radio button. Double clicking on one will open the it’s edit panel and you can delete it from there.

image

1 Like

Awesome! I removed the entity config in NR, then restarted HA after which I was able to remove the entity. I then created a new config, which was actually configured the same and then injected again - profit! It must have been an entity config problem or something like that. Now onto the next challenge which should be easier than the problem I (you :stuck_out_tongue: ) just solved:

prices: 
- Time: '2024-09-17T00:00:00'
  Price: 0.326
  Price excluding taxes: 0.1808
  Price level: NORMAL
- Time: '2024-09-17T01:00:00'
  Price:
    total: 0.3143
    energy: 0.1714
    startsAt: '2024-09-17T01:00:00.000+02:00'
    level: CHEAP
  Price excluding taxes: 0.1714
  Price level: CHEAP
- Time: '2024-09-17T02:00:00'
  Price:
    total: 0.3081
    energy: 0.1664
    startsAt: '2024-09-17T02:00:00.000+02:00'
    level: CHEAP
  Price excluding taxes: 0.1664
  Price level: CHEAP

It looks like it’s actually passing both msg.payload_today and msg.payload. perhaps passing on the complete msg object and mixing the content.

I got it to work exactly the way I wanted! I discovered why why the JSON was mixed up; I though the property in the JSON-node was the input property but I discovered it actually was the output property :smiley: So the JSON-converted object was added to the earlier msg.payload json-converted object. But the way I made it now I don’t even need to convert it. The flow is compact, easy to understand and light. Exactly what I wanted. Thanks :slight_smile:

1 Like