Node red Set_datetime from payload

I am working on an alarm clock flow in node red and trying to set a home assistant input_datetime with the data from a payload.

I have the moment node that will give me the date and time in any format I want it but am struggling to work out how to do the call service to set_datetime.

I know you have to send “date:” and “time:” in the service data of the call service. My best guess at the moment is… I have two moment nodes set up to output “YYYY-MM-DD” and “HH:mm:ss” flowing into a join node which is making an array. It then flows into a call service node with these settings.

domain:   input_datetime
service:   set_datetime
entity_id: input_datetime.work_alarm_with_offset
    "date": "{{payload[0]}}",
    "time": "{{payload[1]}}"

but in the node red debug window I get…

Error call service, home assistant api error. Error Message: Invalid format

If I use the sevice dev tool in home assistant.

Service:   input_datetime.set_datetime

        "entity_id": "input_datetime.work_alarm_with_offset",
        "date": "2018-02-01",
        "time": "21:22:23"

it works??? any ideas node red gurus?

Something is overriding from input. Can you put a debug node before the service call to see what’s the msg content from previous node that is going into the service call.

Your right there was data in the payload from previous nodes.

So I put in a change node to remove that data. The change node had these rules…

delete msg.topic

so now the complete msg looks like this…

19/02/2019, 22:40:59[node: 955eb29e.e6623]( : Object
payload: array[2]
0: "2019-02-20"
1: "08:25:00"
_msgid: "974f75d1.697978"

but I still get the same error

Error call service, home assistant api error. Error Message: Invalid format

I made it work!

In the end I added a couple more rules to the change node I was using to remove the msg.topic and infomation.

I added two rules that


set msg.payload.time

it just didn’t like getting the array data. not really sure why?

Don’t know either. I haven’t used mustache with array index before. You can paste the flow here to test it later.

Mustache Templates use dot notation.

{{payload.0}} and {{payload.1}} will get you what you’re looking for.