zachowj / node-red-contrib-home-assistant-websocket

Node-RED integration with Home Assistant
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/
MIT License
506 stars 96 forks source link

api-call-service wrong part of JSON gets used #241

Closed martinhoess closed 4 years ago

martinhoess commented 4 years ago

Describe the bug

I'm trying to call a HA service with JSON. If the JSON is set directly in the call service node as data the call works but if the data is coming from a template only some parts of the JSON is used

To Reproduce

use the provided flow, the called service should not matter

Expected behavior

the complete JSON should be used as data value not only some parts

Screenshots

image

Example Flow

[
    {
        "id": "6a9ba829.16adf8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "d9faa907.01b058",
        "type": "template",
        "z": "6a9ba829.16adf8",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{\n    \"data\": {\n        \"attachment\": \"http://xyl.abc\",\n        \"priority\": 0,\n        \"sound\": \"intermission\",\n        \"url\": \"homeassistant://\",\n        \"url_title\": \"Home Assistant\"\n    },\n    \"message\": \"   ​\",\n    \"title\": \"🚨\"\n}",
        "output": "json",
        "x": 280,
        "y": 160,
        "wires": [
            [
                "a0bd1410.6888d8",
                "4de07c49.77d474"
            ]
        ]
    },
    {
        "id": "4de07c49.77d474",
        "type": "api-call-service",
        "z": "6a9ba829.16adf8",
        "name": "Pushover Nachricht",
        "server": "810914b4.ec2e78",
        "version": 1,
        "debugenabled": true,
        "service_domain": "notify",
        "service": "pushover",
        "entityId": "",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 510,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "a0bd1410.6888d8",
        "type": "debug",
        "z": "6a9ba829.16adf8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 510,
        "y": 100,
        "wires": []
    },
    {
        "id": "44c630a3.e6b",
        "type": "inject",
        "z": "6a9ba829.16adf8",
        "name": "",
        "topic": "Test",
        "payload": "on",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 130,
        "y": 160,
        "wires": [
            [
                "d9faa907.01b058"
            ]
        ]
    },
    {
        "id": "810914b4.ec2e78",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]

Environment (please complete the following information):

Other (please complete the following information):

I've tried using plain text, using JSON converter, function with JSON.stringify ... no luck. I know that there is a pushover node ... but this affects all HA service calls

Additional context

zachowj commented 4 years ago

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/call-service.html#data

The node input requires the data to be in the msg.payload.data property.

{ 
    "data": {
        "data": {
            "attachment": "http://xyl.abc",
            "priority": 0,
            "sound": "intermission",
            "url": "homeassistant://",
            "url_title": "Home Assistant"
        },
        "message": "   ​",
        "title": "🚨"
    }
}