TotallyInformation / node-red-contrib-moment

Node-Red Node that produces formatted Date/Time output using the Moment.JS library. Timezone, dst and locale aware.
Apache License 2.0
34 stars 16 forks source link

How to append time to payload? #29

Closed 877dev closed 4 years ago

877dev commented 4 years ago

I seem to be missing something obvious. I have a true or false switch node, when "false" is outputted I want to set the payload message to "<time/date> Door is open".

As the input to the moment node is to be triggered by a "false" message from the switch node, I can't see how to get the time/date appended.

Any ideas?

877dev commented 4 years ago

Setting up like this I get the date passed through but not the time for some reason...

image

TotallyInformation commented 4 years ago

Hi, thanks for raising. Often best to raise general questions in the Node-RED forum though as you tend to get a faster and possibly more complete response because lots of people will be looking at it.

In this case, if I've understood you correctly, you have two choices:

  1. Use MomentJS's formatting. You can add text to the output format by escaping it with square brackets.

    See here under "Escaping Characters" for details.

    [today] dddd

    image

  2. Alternatively, add the timestamp to some field other than payload and then use a change node after the moment node to merge the timestamp with whatever other text you want.

877dev commented 4 years ago

Hi @TotallyInformation

Thank you, although that is also useful I don't think I explained myself clearly. The issue is that unless I use a timestamp trigger node, the time does not set and it shows 00:00. The date is correct.

I've posted over on node red as you suggested HERE

Many thanks 877dev