# Stop Switch Passing through Data

**URL:** <https://discourse.nodered.org/t/stop-switch-passing-through-data/90780>\
**Category:** General\
**Tags:** home-assistant, switch-node\
**Created:** [7 September 2024 23:18 UTC](https://discourse.nodered.org/t/stop-switch-passing-through-data/90780 "2024-09-07T23:18:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cameronjust](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cameronjust/32/94288_2.png) [@cameronjust](https://discourse.nodered.org/u/cameronjust)\
**Post date:** [7 September 2024 23:18 UTC](https://discourse.nodered.org/t/stop-switch-passing-through-data/90780/1 "2024-09-07T23:18:12Z")

</div>

I've had this working for years but something has changed with a recent update where my dimming buttons no longer dim lights.

When I press a button I pass the button action through to a "switch" which then routes based on the input. This works fine based on the button press type present in "payload.action".

The problem is "payload.action" is then passed through to the next node ["api-call-service"](https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/action.html) which says it doesn't understand the payload.action and throws this error

"InputError: Invalid action format: brightness\_down\_click"

This is the data passed through from switch

```auto
{"topic":"zigbee2mqtt/bedroom_buttons","payload":{"action":"brightness_down_click","battery":20,"last_seen":"2024-09-08T09:14:48+10:00","linkquality":25,"update":{"installed_version":604241925,"latest_version":604241925,"state":"idle"},"update_available":null},"qos":0,"retain":false,"_msgid":"839ebdb5c100c484"}

```

How can I stop the switch from passing this data through?

```auto
[
    {
        "id": "ad08df176725d5c3",
        "type": "mqtt in",
        "z": "898fbae0f3586e7c",
        "name": "",
        "topic": "zigbee2mqtt/bedroom_buttons",
        "qos": "2",
        "datatype": "json",
        "broker": "cc06606981aaf0a9",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 220,
        "y": 760,
        "wires": [
            [
                "16ad3d0d74c5983c"
            ]
        ]
    },
    {
        "id": "16ad3d0d74c5983c",
        "type": "switch",
        "z": "898fbae0f3586e7c",
        "name": "",
        "property": "payload.action",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "toggle",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "brightness_up_click",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "brightness_down_click",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_left_hold",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "arrow_right_hold",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 5,
        "x": 510,
        "y": 760,
        "wires": [
            [
                "c4f6b5696c253458",
                "3d3fcde6213ad06b"
            ],
            [
                "d27251e8c55c2df7"
            ],
            [
                "bcc45c48056685ed",
                "954d1934afefda3f"
            ],
            [],
            []
        ]
    },
    {
        "id": "c4f6b5696c253458",
        "type": "api-call-service",
        "z": "898fbae0f3586e7c",
        "name": "All Bedroom Toggle",
        "server": "33d171f4d54f205e",
        "version": 6,
        "debugenabled": true,
        "action": "light.toggle",
        "floorId": [],
        "areaId": [
            "bedroom"
        ],
        "deviceId": [],
        "entityId": [],
        "labelId": [],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "domain": "light",
        "service": "toggle",
        "x": 670,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "d27251e8c55c2df7",
        "type": "api-call-service",
        "z": "898fbae0f3586e7c",
        "name": "Lights Brighter",
        "server": "33d171f4d54f205e",
        "version": 6,
        "debugenabled": false,
        "action": "light.turn_on",
        "floorId": [],
        "areaId": [
            "bedroom"
        ],
        "deviceId": [],
        "entityId": [],
        "labelId": [],
        "data": "{\"brightness_step_pct\":5,\"transition\":2}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "domain": "light",
        "service": "turn_on",
        "x": 720,
        "y": 740,
        "wires": [
            []
        ]
    },
    {
        "id": "bcc45c48056685ed",
        "type": "api-call-service",
        "z": "898fbae0f3586e7c",
        "name": "Lights Dimmer",
        "server": "33d171f4d54f205e",
        "version": 6,
        "debugenabled": true,
        "action": "homeassistant.turn_on",
        "floorId": [],
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.bedroom_all"
        ],
        "labelId": [],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "{\"brightness_step_pct\":10}",
                "valueType": "jsonata"
            }
        ],
        "queue": "none",
        "domain": "homeassistant",
        "service": "turn_on",
        "x": 740,
        "y": 820,
        "wires": [
            []
        ]
    },
    {
        "id": "cc06606981aaf0a9",
        "type": "mqtt-broker",
        "name": "Stafford MQTT",
        "broker": "192.168.64.64",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "33d171f4d54f205e",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": false,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": true,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": "at: ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "h23",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": true
    }
]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 September 2024 00:11 UTC](https://discourse.nodered.org/t/stop-switch-passing-through-data/90780/2 "2024-09-08T00:11:49Z")

</div>

> [@cameronjust](#):
>
> "InputError: Invalid action format: brightness\_down\_click"

It seems that the api-call-service node knows about msg.payload.action, it just does not recognise the particular value `brightness_down_click`.

So what do you want to send to api\_call\_service instead?

Generally speaking, the change node is the right way to manipulate the message contents.

---

<div class="post-metadata">

**Author:** ![cameronjust](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cameronjust/32/94288_2.png) [@cameronjust](https://discourse.nodered.org/u/cameronjust)\
**Post date:** [8 September 2024 00:27 UTC](https://discourse.nodered.org/t/stop-switch-passing-through-data/90780/3 "2024-09-08T00:27:10Z")

</div>

Correct that's what I suspected too. This is the flow that used to work before a recent update.

 ![Screenshot from 2024-09-08 10-23-12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/582efb105fcc6d07c43a6327fa3af3e67a7561bc.png)

Either the behaviour of switch or api-call-service has changed.

Ideally I'd like api-service-call to ignore whatever was passed to it and just perform the action I configured it to do on the node itself. The other option is if I can tell the switch to not pass through the payload.action that it used to determine which path to trigger.

I'm hoping to avoid putting another node between these to manipulate/neuter the payload passed from switch as that will really make all my flows overly complicated.

Edit: Note the "Current state" node on the right hand side with two paths to turn on/off the lights. I just added that today to "fix" the previous working "All Bedroom Toggle" which is also failing now due to the payload.action being passed with an invalid action from the switch statement. So it went from requiring only one node to 3x nodes now.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 September 2024 00:58 UTC](https://discourse.nodered.org/t/stop-switch-passing-through-data/90780/4 "2024-09-08T00:58:30Z")

</div>

Um....

This has caught me a lot of times.

If it is a `MQTT` message, you need to look at the `msg.payload`

So what you may think is `msg.brightness_down_click` is ACTUALLY `msg.payload.brightness_down_click`

But I am not sure I am reading the problem correctly.

(Got the flu' and it is not easy to think.)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [8 September 2024 01:10 UTC](https://discourse.nodered.org/t/stop-switch-passing-through-data/90780/5 "2024-09-08T01:10:58Z")

</div>

> [@cameronjust](#):
>
> Either the behaviour of switch or api-call-service has changed.

Or perhaps something has changed in whatever publishes to MQTT.

> [@cameronjust](#):
>
> Ideally I'd like api-service-call to ignore whatever was passed to it and just perform the action I configured it to do on the node itself.

That seems to me eccentric. Isn't it possible to get rid of some of the api\_call\_service nodes, perhaps leaving only one, and control it's action using the data published to MQTT?  
That would eliminate the switch and leave just the mqtt-in and one api\_call\_service nodes.

I don't use Home Assistant though so I don't know how it works to control lights.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 December 2024 01:11 UTC](https://discourse.nodered.org/t/stop-switch-passing-through-data/90780/6 "2024-12-07T01:11:24Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
