Need help with my first NodeRed automation

Hello,

I’m new to NodeRed and I’m trying to port this simple yaml automation. The automation should toggle my office lights (hue lights) when I press my xiaomi button. The zigbee devices are controlled with zigbee2mqtt.

- alias: toggle office lights
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/office_button'
  condition:
    condition: template
    value_template: "{{ 'single' == trigger.payload_json.click }}"
  action:
    service: light.toggle
    entity_id: group.office

So far, I created this flow, but it doesn’t work:

[
    {
        "id": "a283654c.0ac178",
        "type": "mqtt in",
        "z": "e5271cb8.c38fd",
        "name": "Office button",
        "topic": "zigbee2mqtt/office_button",
        "qos": "2",
        "broker": "fc8e76a0.5ba218",
        "x": 110,
        "y": 80,
        "wires": [
            [
                "6873eb4e.37ae04"
            ]
        ]
    },
    {
        "id": "6873eb4e.37ae04",
        "type": "switch",
        "z": "e5271cb8.c38fd",
        "name": "Click type",
        "property": "payload_json.click",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "single",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "double",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "long_click_press",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 320,
        "y": 80,
        "wires": [
            [
                "26543ec5.b6ff92"
            ],
            [],
            []
        ]
    },
    {
        "id": "26543ec5.b6ff92",
        "type": "api-call-service",
        "z": "e5271cb8.c38fd",
        "name": "Toggle office lights",
        "server": "ed7d5529.e1f368",
        "service_domain": "light",
        "service": "toggle",
        "data": "{\"entity_id\":\"group.office\"}",
        "render_data": false,
        "mergecontext": "",
        "output_location": "payload",
        "output_location_type": "msg",
        "x": 590,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "fc8e76a0.5ba218",
        "type": "mqtt-broker",
        "z": "",
        "name": "HA/Mosquitos",
        "broker": "(redacted)",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "ed7d5529.e1f368",
        "type": "server",
        "z": "",
        "name": "Home Assistant"
    }
]

Try dropping a json node between the mqtt and switch nodes and reference msg.payload.click in the switch node. If it’s not msg.payload.click drop a debug node after the json node to see the msg object.

Ah you found it! Work great with the json node. Thanks!

There are dedicated nodes for XIAOMI and for HUE.

By using the dedicated nodes you will get a faster response between the click of the xiaomi button and the Hue light.

Hello,

Theses nodes seem to support the Xioami and the Hue hubs. I don’t use theses. I only use zigbee2mqtt. Two main advantages:

  • No cloud and no data leak to the Internet (especially the Xiaomi hub that phone out to China).
  • A single zigbee network for all devices. My Hue bulbs extends my zigbee network so all my devices are in range (zigbee is a mesh network).

yeah, I’m aware of the internet issue and have blocked those devices on my router.

There is this nice Zigbee-Node I want to use in future especially because of the mesh feature :wink:

1 Like