Setting the payload correctly in node-red (missing service_data)

I am working on a flow for my Elk M1 security system. When I try to do things like set the keypad display text using the developer service tab, it works fine. But I am having trouble getting it to work in node-red. I watched the call_service events in the developer tab and here is what it looks like when I use the developer tab (which works correctly)


entity_id: alarm_control_panel.home
clear: 2
beep: 0
timeout: 10
line1: 'Clear'
line2: '51.1 deg F'


Event 0 fired 10:35 AM:
{
    "event_type": "call_service",
    "data": {
        "domain": "elkm1",
        "service": "alarm_display_message",
        "service_data": {
            "entity_id": "alarm_control_panel.home",
            "clear": 2,
            "beep": 0,
            "timeout": 10,
            "line1": "Clear",
            "line2": "51.1 deg F"
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-12-25T15:35:05.082147+00:00",
    "context": {
        "id": "b5b6035697a6b1b5267e09e677d40e24",
        "parent_id": null,
        "user_id": "f9f3286363484ae6ab1a6f8fca3de911"
    }
}

But when I run what I think should work in node-red, I get this:

Event 1 fired 10:36 AM:
{
    "event_type": "call_service",
    "data": {
        "domain": "elkm1",
        "service": "alarm_display_message",
        "service_data": {}
    },
    "origin": "LOCAL",
    "time_fired": "2020-12-25T15:36:55.805907+00:00",
    "context": {
        "id": "c9ab9b9ed6f3b623bc919636aef47f14",
        "parent_id": null,
        "user_id": "8acfd50682b247aa8cace63eda7841e9"
    }
}

As you can see, the service_data is empty.

Here’s how I am currently trying (not working) to create the payload in a function node:

entity_id = "alarm_control_panel.home"
line1 = msg.payload.weather
line2 = Number.parseFloat(msg.payload.tempc * 9/5 + 32).toFixed(1) + " deg F"
clear = 2
beep = 0
timeout = 0
var newMsg = { "payload": {"entity_id": entity_id, "line1": line1, "line2": line2, "clear": clear, "beep": beep, "timeout": timeout }}
return newMsg;

This is creating a JSON message that looks like this:

{
  "entity_id": "alarm_control_panel.home",
  "line1": "Mist",
  "line2": "65.8 deg F",
  "clear": 2,
  "beep": 0,
  "timeout": 0
}

and looks like this in the debug window:

entity_id: "alarm_control_panel.home"
line1: "Mist"
line2: "65.8 deg F"
clear: 2
beep: 0
timeout: 0

The elk integration folks have taken a look at this and are wondering if this is more of a node-red issue, most likely because I am not doing it right. I tend to agree with them.

Thoughts?

I figured it out. I needed to fill in the Data field like so:

Data:

Copy to clipboard
{
  "line1": "{{payload.line1}}",
  "line2": "{{payload.line2}}",
  "clear": "{{payload.clear}}",
  "beep": "{{payload.beep}}",
  "timeout": "{{payload.timeout}}"
}