c_wolsey
(Chris Wolsey)
February 19, 2019, 9:17pm
1
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
data:
{
"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?
subzero79
(Subzero79)
February 19, 2019, 10:07pm
2
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.
c_wolsey
(Chris Wolsey)
February 19, 2019, 10:45pm
3
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
delete msg.data
so now the complete msg looks like this…
19/02/2019, 22:40:59[node: 955eb29e.e6623](https://########.duckdns.org:1880/#)msg : Object
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
c_wolsey
(Chris Wolsey)
February 19, 2019, 11:16pm
4
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 msg.data infomation.
I added two rules that
set msg.payload.date
msg.payload[0]
set msg.payload.time
msg.payload[1]
it just didn’t like getting the array data. not really sure why?
subzero79
(Subzero79)
February 20, 2019, 12:19am
5
Don’t know either. I haven’t used mustache with array index before. You can paste the flow here to test it later.
Kermit
February 20, 2019, 1:24am
6
Mustache Templates use dot notation.
{{payload.0}}
and {{payload.1}}
will get you what you’re looking for.