I am assuming that your Washing machine is now going to run for days. So the “humanize” is unlikely to be “last week” !
In this case, you can use https://flows.nodered.org/node/node-red-contrib-sun-position it will very easily output the duration in minutes.
GV
@greengolferperhaps humaize wasn’t the right example but was thinking more along the notion of filters. Nodered is based on mustache AFAIK and I dont think you can have such logic in templates
Not sure I understand what you mean… If duration is accessible using msg.payload.duration as in your example, the node I have suggested works. But, maybe I missed something.
GV
Are you just wanting to show number of minutes? I didn’t read this well enough because $fromMillis() will turn an input millisecond into a date/time, but I don’t think that is what you want.
On a Node-Red change node you can just set payload.duration using jsonata (look like a bold J:) using $round(payload/1000) - JSONata Documentation · JSONata
arr = msg.payload
let persons = []
arr.forEach(function(v){
date = mom(new Date(v.last_changed)).calendar().toLowerCase()
persons.push(v.attributes.friendly_name.toLowerCase()+' is '+v.state+' since '+date)
})
text = '`'+persons.join('\n')+'`'
return {payload:{data:{message:text,title:'*INFO*'}}};
will give me ricardo is home since today at 1:30 pm
mom is the moment module defined in settings.js functionsGlobalContext
mom:require('moment'),
You don’t need to use code though, there is a moment node available also
Yes every think is good, i just miss understand what it turns to be a very important step, in the first node ( state node ) choose- state type: boolean - i know you mention that, i just missed.
By the way you could edit the data there of the state node to match what you put in this topic:
{"message": "Washing machine used {{payload.energy}} kwh and ran for {{payload.duration}} for the last cycle"}
Very nice work, i,m just an ordinary begginner turning to medium user , so its easy to amuse me, but i must say that this was the most powerfull/usefull function i,ve seen in node red.