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
503 stars 93 forks source link

light domain service turn_on being called instead of turn_off #201

Closed Bodge-IT closed 4 years ago

Bodge-IT commented 4 years ago

Describe the bug Setup a node to call light domain and turn_off service. Light is not turned off and status info under node reports "light.turn_on" service called

To Reproduce Use "Call Service" node. Enter light for domain and turn_off for service.

Expected behavior Expect light to be turned off and status info under node to reflect the "light.turn_off" status called at :

Screenshots

Example Flow If applicable, add an example of exported json of a flow exhibiting the issue to aid in reproduction.

Environment (please complete the following information): Nodered is in container.

Additional context The node is being triggered by an "On" status message in msg.payload, but even if I convert that to an "Off" payload, the turn_on service is still called.

zachowj commented 4 years ago

Can you export your flow and post it?

Bodge-IT commented 4 years ago
[
    {
        "id": "81fc35f0.b5b4b8",
        "type": "tab",
        "label": "BR Routine",
        "disabled": false,
        "info": ""
    },
    {
        "id": "c42c3d43.7484a8",
        "type": "inject",
        "z": "81fc35f0.b5b4b8",
        "name": "",
        "topic": "",
        "payload": "On",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 90,
        "y": 360,
        "wires": [
            [
                "7b62a534.65a32c"
            ]
        ]
    },
    {
        "id": "3feab56b.2d5c7a",
        "type": "mqtt out",
        "z": "81fc35f0.b5b4b8",
        "name": "BR Fan",
        "topic": "dbzoo/hal/Controller/rf/6",
        "qos": "",
        "retain": "",
        "broker": "aef63b41.e6e1f8",
        "x": 900,
        "y": 400,
        "wires": []
    },
    {
        "id": "e64f9809.e1cf3",
        "type": "debug",
        "z": "81fc35f0.b5b4b8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "complete": "false",
        "x": 1150,
        "y": 200,
        "wires": []
    },
    {
        "id": "f9da4e34.4c66e",
        "type": "function",
        "z": "81fc35f0.b5b4b8",
        "name": "RF6 Toggle",
        "func": "var rf6status = msg.payload;\nmsg.payload = [\n  \"xap-header\",\n  \"{\",\n  \"v=12\",\n  \"hop=1\",\n  \"class=xAPBSC.cmd\",\n  \"target=dbzoo.hal.Controller:rf.6\",\n  \"source=dbzoo.hal.nodered\",  // Use the top level address not an endpoint.\n  \"uid=FF00D800\",  // 00 for the unit a whole, 07 would be an endpoint of the unit.\n  \"}\",\n  \"output.state.1\",\n  \"{\",\n  \"state=\"+rf6status,\n  \"ID=*\", // You can use * here its easier and works the same.\n  \"}\"\n].join(\"\\n\");\n \nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 390,
        "y": 400,
        "wires": [
            [
                "9873b2d.9561a5",
                "3feab56b.2d5c7a"
            ]
        ]
    },
    {
        "id": "9873b2d.9561a5",
        "type": "delay",
        "z": "81fc35f0.b5b4b8",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 560,
        "y": 440,
        "wires": [
            [
                "7f7f0e4f.757e68"
            ]
        ]
    },
    {
        "id": "7f7f0e4f.757e68",
        "type": "function",
        "z": "81fc35f0.b5b4b8",
        "name": "RF6 Status",
        "func": "msg.payload = [\n  \"xap-header\",\n  \"{\",\n  \"v=12\",\n  \"hop=1\",\n  \"class=xAPBSC.query\",\n  \"target=dbzoo.hal.Controller:rf.6\",\n  \"source=dbzoo.hal.nodered\",  // Use the top level address not an endpoint.\n  \"uid=FF00D800\",  // 00 for the unit a whole, 07 would be an endpoint of the unit.\n  \"}\",\n  \"request\",\n  \"{\",\n  \"}\"\n].join(\"\\n\");\n \nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 730,
        "y": 440,
        "wires": [
            [
                "3feab56b.2d5c7a"
            ]
        ]
    },
    {
        "id": "7b62a534.65a32c",
        "type": "bigtimer",
        "z": "81fc35f0.b5b4b8",
        "outtopic": "dbzoo/hal/Controller/rf/6",
        "outpayload1": "On",
        "outpayload2": "Off",
        "name": "Big Timer",
        "comment": "",
        "lat": "51.025",
        "lon": "-1.4",
        "starttime": "450",
        "endtime": "570",
        "startoff": "0",
        "endoff": "0",
        "startoff2": "0",
        "endoff2": "0",
        "offs": "0",
        "outtext1": "On",
        "outtext2": "Off",
        "timeout": 1440,
        "sun": false,
        "mon": true,
        "tue": true,
        "wed": true,
        "thu": true,
        "fri": true,
        "sat": true,
        "jan": true,
        "feb": true,
        "mar": true,
        "apr": true,
        "may": true,
        "jun": true,
        "jul": true,
        "aug": true,
        "sep": true,
        "oct": true,
        "nov": true,
        "dec": true,
        "day1": 0,
        "month1": 0,
        "day2": 0,
        "month2": 0,
        "day3": 0,
        "month3": 0,
        "day4": 0,
        "month4": 0,
        "day5": 0,
        "month5": 0,
        "day6": "",
        "month6": "",
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "d6": "",
        "w6": "",
        "xday1": "",
        "xmonth1": "",
        "xday2": "",
        "xmonth2": "",
        "xday3": "",
        "xmonth3": "",
        "xday4": "",
        "xmonth4": "",
        "xday5": "",
        "xmonth5": "",
        "xday6": "",
        "xmonth6": "",
        "xd1": "",
        "xw1": "",
        "xd2": "",
        "xw2": "",
        "xd3": "",
        "xw3": "",
        "xd4": "",
        "xw4": "",
        "xd5": "",
        "xw5": "",
        "xd6": "",
        "xw6": "",
        "suspend": false,
        "random": false,
        "repeat": false,
        "atstart": false,
        "odd": false,
        "even": false,
        "x": 380,
        "y": 200,
        "wires": [
            [
                "c12bbea1.788668",
                "f9da4e34.4c66e"
            ],
            [],
            []
        ]
    },
    {
        "id": "97e76b0d.2e25f8",
        "type": "inject",
        "z": "81fc35f0.b5b4b8",
        "name": "",
        "topic": "",
        "payload": "Off",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 90,
        "y": 320,
        "wires": [
            [
                "7b62a534.65a32c",
                "c8e0cbf7.b4833"
            ]
        ]
    },
    {
        "id": "aa29d578.968ab",
        "type": "inject",
        "z": "81fc35f0.b5b4b8",
        "name": "",
        "topic": "",
        "payload": "Toggle",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 90,
        "y": 400,
        "wires": [
            [
                "f9da4e34.4c66e"
            ]
        ]
    },
    {
        "id": "c8e0cbf7.b4833",
        "type": "squeezebox-out",
        "z": "81fc35f0.b5b4b8",
        "squeezebox_server": "a9e361aa.4883f8",
        "player_name": "Bedroom",
        "command": "sleep,5",
        "x": 870,
        "y": 340,
        "wires": [
            [
                "e64f9809.e1cf3"
            ]
        ]
    },
    {
        "id": "c12bbea1.788668",
        "type": "switch",
        "z": "81fc35f0.b5b4b8",
        "name": "Filter",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "Off",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "On",
                "vt": "str"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 390,
        "y": 140,
        "wires": [
            [
                "4d710427.59757c"
            ],
            [
                "c8e0cbf7.b4833",
                "b46b49e5.b4bc98",
                "d4bd607a.75257"
            ]
        ]
    },
    {
        "id": "359fcb7f.96668c",
        "type": "comment",
        "z": "81fc35f0.b5b4b8",
        "name": "Bedroom Routine",
        "info": "Turns fades light on in morning\nWhen light turns on, fan and turn off radio",
        "x": 440,
        "y": 100,
        "wires": []
    },
    {
        "id": "27c778ef.eebf08",
        "type": "alexa-local",
        "z": "81fc35f0.b5b4b8",
        "devicename": "Bedroom Routine",
        "inputtrigger": false,
        "x": 110,
        "y": 140,
        "wires": [
            [
                "7b62a534.65a32c",
                "2f0e7161.3d4f86"
            ]
        ]
    },
    {
        "id": "b46b49e5.b4bc98",
        "type": "ha-fire-event",
        "z": "81fc35f0.b5b4b8",
        "name": "Bedroom Routine (On)",
        "server": "a9f81eb0.331e68",
        "event": "state_changed",
        "data": "{\"entity_id\":\"switch.bedroom_routine\",\"old_state\":\"Off\",\"new_state\":\"On\"}",
        "dataType": "json",
        "x": 860,
        "y": 140,
        "wires": [
            [
                "e64f9809.e1cf3"
            ]
        ]
    },
    {
        "id": "b2c5514d.af9dc",
        "type": "api-call-service",
        "z": "81fc35f0.b5b4b8",
        "name": "Turn Lamp Off",
        "server": "a9f81eb0.331e68",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_off",
        "entityId": "light.bedroom_lamp",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 880,
        "y": 280,
        "wires": [
            [
                "e64f9809.e1cf3"
            ]
        ]
    },
    {
        "id": "4d710427.59757c",
        "type": "ha-fire-event",
        "z": "81fc35f0.b5b4b8",
        "name": "Bedroom Routine (Off)",
        "server": "a9f81eb0.331e68",
        "event": "state_changed",
        "data": "{\"entity_id\":\"switch.bedroom_routine\",\"old_state\":\"On\",\"new_state\":\"Off\"}",
        "dataType": "json",
        "x": 860,
        "y": 80,
        "wires": [
            [
                "e64f9809.e1cf3"
            ]
        ]
    },
    {
        "id": "d1a67b96.4868",
        "type": "server-state-changed",
        "z": "81fc35f0.b5b4b8",
        "name": "BR Routine Switch",
        "server": "a9f81eb0.331e68",
        "version": 1,
        "exposeToHomeAssistant": true,
        "haConfig": [
            {
                "property": "name",
                "value": "switch.bedroom_routine"
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "switch.bedroom_routine",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 110,
        "y": 220,
        "wires": [
            [
                "7b62a534.65a32c"
            ],
            [
                "7b62a534.65a32c"
            ]
        ]
    },
    {
        "id": "2f0e7161.3d4f86",
        "type": "bigtimer",
        "z": "81fc35f0.b5b4b8",
        "outtopic": "",
        "outpayload1": "On",
        "outpayload2": "Off",
        "name": "Big Timer",
        "comment": "",
        "lat": "51.025",
        "lon": "-1.4",
        "starttime": "345",
        "endtime": "420",
        "starttime2": 0,
        "endtime2": 0,
        "startoff": 0,
        "endoff": 0,
        "startoff2": 0,
        "endoff2": 0,
        "offs": 0,
        "outtext1": "On",
        "outtext2": "Off",
        "timeout": 1440,
        "sun": true,
        "mon": true,
        "tue": true,
        "wed": true,
        "thu": true,
        "fri": true,
        "sat": true,
        "jan": true,
        "feb": true,
        "mar": true,
        "apr": true,
        "may": true,
        "jun": true,
        "jul": true,
        "aug": true,
        "sep": true,
        "oct": true,
        "nov": true,
        "dec": true,
        "day1": 0,
        "month1": 0,
        "day2": 0,
        "month2": 0,
        "day3": 0,
        "month3": 0,
        "day4": 0,
        "month4": 0,
        "day5": 0,
        "month5": 0,
        "day6": 0,
        "month6": 0,
        "d1": 0,
        "w1": 0,
        "d2": 0,
        "w2": 0,
        "d3": 0,
        "w3": 0,
        "d4": 0,
        "w4": 0,
        "d5": 0,
        "w5": 0,
        "d6": 0,
        "w6": 0,
        "xday1": 0,
        "xmonth1": 0,
        "xday2": 0,
        "xmonth2": 0,
        "xday3": 0,
        "xmonth3": 0,
        "xday4": 0,
        "xmonth4": 0,
        "xday5": 0,
        "xmonth5": 0,
        "xday6": 0,
        "xmonth6": 0,
        "xd1": 0,
        "xw1": 0,
        "xd2": 0,
        "xw2": 0,
        "xd3": 0,
        "xw3": 0,
        "xd4": 0,
        "xw4": 0,
        "xd5": 0,
        "xw5": 0,
        "xd6": 0,
        "xw6": 0,
        "suspend": false,
        "random": false,
        "repeat": true,
        "atstart": true,
        "odd": false,
        "even": false,
        "x": 380,
        "y": 500,
        "wires": [
            [
                "8827c74a.6af3e8"
            ],
            [],
            []
        ]
    },
    {
        "id": "f0c0fba8.834ce",
        "type": "api-call-service",
        "z": "81fc35f0.b5b4b8",
        "name": "Fade Lamp on",
        "server": "a9f81eb0.331e68",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.bedroom_lamp",
        "data": "{\"transition\":\"900\",\"kelvin\":\"6500\",\"brightness_pct\":\"100\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "payload",
        "output_location_type": "msg",
        "mustacheAltTags": false,
        "x": 920,
        "y": 480,
        "wires": [
            [
                "e64f9809.e1cf3"
            ]
        ]
    },
    {
        "id": "d4bd607a.75257",
        "type": "api-call-service",
        "z": "81fc35f0.b5b4b8",
        "name": "Lamp Brightness",
        "server": "a9f81eb0.331e68",
        "version": 1,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.bedroom_lamp",
        "data": "{\"brightness_pct\":\"15\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "payload",
        "output_location_type": "msg",
        "mustacheAltTags": false,
        "x": 870,
        "y": 200,
        "wires": [
            [
                "e64f9809.e1cf3",
                "b2c5514d.af9dc"
            ]
        ]
    },
    {
        "id": "8827c74a.6af3e8",
        "type": "switch",
        "z": "81fc35f0.b5b4b8",
        "name": "Filter",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "On",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "Off",
                "vt": "str"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 750,
        "y": 500,
        "wires": [
            [
                "f0c0fba8.834ce"
            ],
            []
        ]
    },
    {
        "id": "89faa372.5dfe5",
        "type": "change",
        "z": "81fc35f0.b5b4b8",
        "name": "Off to On",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "Off",
                "fromt": "str",
                "to": "On",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 160,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "fb56b17b.667e6",
        "type": "change",
        "z": "81fc35f0.b5b4b8",
        "name": "On to Off",
        "rules": [
            {
                "t": "change",
                "p": "pay to Offload",
                "pt": "msg",
                "from": "On",
                "fromt": "str",
                "to": "Off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 160,
        "y": 700,
        "wires": [
            []
        ]
    },
    {
        "id": "aef63b41.e6e1f8",
        "type": "mqtt-broker",
        "z": "",
        "name": "",
        "broker": "mqtt",
        "port": "1883",
        "clientid": "node-red",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "a9e361aa.4883f8",
        "type": "squeezebox-server",
        "z": "",
        "host": "http://172.16.10.225",
        "port": "9000",
        "name": "Logitech Media Server"
    },
    {
        "id": "a9f81eb0.331e68",
        "type": "server",
        "z": "",
        "name": "Animus",
        "legacy": false,
        "hassio": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]

The change nodes aren't in here

zachowj commented 4 years ago

If it's the Turn Lamp Off call-service node that is doing it. It's because you have Lamp Brightness outputting to msg.payload and it is overriding the config of Turn Lamp Off

Bodge-IT commented 4 years ago

Turn off node comes after? But turning the bright output off has indeed fixed it.

I was setting the brightness as I have a turn on node that transitions from low light to full brightness elsewhere in the flow.

Bodge-IT commented 4 years ago

I was under the impression the node would be triggered by any preceding event as payload not used? Anyway, thanks...