Process Data from Home-Assistant Entity in function to template

i have an entity sun.sun (from Homeassistant) with attribute rising data.attributes.next_rising with payload 2024-01-18T07:26:56.471638+00:00 and want to process this raw data to hh:mm (with hh+1)
2024-01-18T07:26:56.471638+00:00 > 08:26 (8 cause hh+1)

I have read many topics about processing messages but have no clue how to proceed. It seems like all messages between objects in nodered are passed (default) with JavaScript. Do i have to build a JavaScript function between entity and template? And how i can get the data from the function?
I have a working solution with raw-data in Mustache-Template:

"text": "{{data.attributes.next_rising}}",

Thank you in advice


Use a change node and $moment

Demo flow (use CTRL+I to import)

[{"id":"0152ae8510f48dce","type":"inject","z":"dda2f44974393278","name":"fake entity data","props":[{"p":"","v":"2024-01-18T07:26:56.471638+00:00","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":710,"y":480,"wires":[["d8cd9d547b2c2b31","fd06c7fdfcc5aac4"]]},{"id":"d8cd9d547b2c2b31","type":"change","z":"dda2f44974393278","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment(\"HH:mm\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":480,"wires":[["3ec93364c36afcc8"]]},{"id":"3ec93364c36afcc8","type":"debug","z":"dda2f44974393278","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":960,"y":540,"wires":[]},{"id":"fd06c7fdfcc5aac4","type":"debug","z":"dda2f44974393278","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"msg","x":900,"y":420,"wires":[]}]

Thank you, this is working really fine! :slight_smile:
Just had to change
$moment("HH:mm") to $moment(data.attributes.next_rising).format("HH:mm")

Just found documentation here as well: node-red-contrib-moment (node) - Node-RED Its described there.

Another question:
Which JS library can i use for the following things:

%-value example: 10,00% to 10% and
cutting after a few characters example:
Whatever-text-here to Whatever ?

Show us the source data

(for example, if it is already a number, then string processing may be unnecessary)

also, explain what you wish to do with the data.

(For example, if it is to be displayed on a dashboard, the answer might be different)

Steve-Mcl has you covered on this - but if it does need changing then look at the change node and jsonata within it to reformat


Mhh Home-Assistant gave me (for exampl)e for Speedtest the following entity-value: "100.10 Mbit/s" but i can see that NodeRed is only recognizing the 100.10. Same with my mouse-entity. From Homeassistant its for example 30.00% but in Nodered 30. Nothing to fix so :smiley:
Thank you guys

Attach a debug mode showing what is coming from ha and paste a screen shot of the debug output here.

Or do you mean all is well?

Yes all is well. :slight_smile:

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