# On/off buttons syncing with HA

**URL:** https://discourse.nodered.org/t/on-off-buttons-syncing-with-ha/43833
**Category:** Dashboard
**Created:** [7 April 2021 20:24 UTC](https://discourse.nodered.org/t/on-off-buttons-syncing-with-ha/43833 "2021-04-07T20:24:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ACJUK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acjuk/32/23496_2.png) [@ACJUK](https://discourse.nodered.org/u/ACJUK)
#### Post date: [7 April 2021 20:24 UTC](https://discourse.nodered.org/t/on-off-buttons-syncing-with-ha/43833/1 "2021-04-07T20:24:22Z")

</div>

I appear to have fallen at the first hurdle for creating my dashboard.

I can set up a switch that will turn the light on and off but it's not in sync if something like a sensor turns the light on or off.

I put and events: state in to detect a change in the state of the entity and inject that into my switch node which then turns the light on or off.

It seems to work most of the time but sometimes it gets messed up and turned the light on and off repeatedly - I've blown an LED controller this afternoon due to this. This is my flow, with the code below.

 ![Screen Shot 2021-04-07 at 21.20.04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6fa8d0e559cf3a2ab9d7133c2322b776f2ec97bf.png)

I'm sure this can't be the right way. I'd be interested to know what the best way of doing this is.

```auto
    {
        "id": "8ecc988f.dad0b8",
        "type": "server-state-changed",
        "z": "d18850c2.58c1",
        "name": "Landing Light Check",
        "server": "7b1d3390.03561c",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "switch.landing_ceiling_shelly",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "habool",
        "haltifstate": "true",
        "halt_if_type": "bool",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "x": 90,
        "y": 480,
        "wires": [
            [
                "a4ca29b9.xxxxxx"
            ],
            [
                "a4ca29b9.xxxxxx"
            ]
        ]
    },
    {
        "id": "a4ca29b9.xxxxxx",
        "type": "ui_switch",
        "z": "d18850c2.xxxxxx",
        "name": "",
        "label": "Light",
        "tooltip": "",
        "group": "cb5e63c3.xxxxxx",
        "order": 2,
        "width": 6,
        "height": 2,
        "passthru": true,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "true",
        "onvalueType": "bool",
        "onicon": "fa-lightbulb-o fa-4x",
        "oncolor": "orange",
        "offvalue": "false",
        "offvalueType": "bool",
        "officon": "fa-lightbulb-o fa-4x",
        "offcolor": "gray",
        "animate": false,
        "x": 330,
        "y": 480,
        "wires": [
            [
                "a29daba6.xxxxxx"
            ]
        ]
    },
    {
        "id": "a29daba6.xxxxxx",
        "type": "switch",
        "z": "d18850c2.xxxxxx",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 490,
        "y": 480,
        "wires": [
            [
                "d50ed502.xxxxxx"
            ],
            [
                "ff76b90f.xxxxxx"
            ]
        ]
    },
    {
        "id": "d50ed502.xxxxxx",
        "type": "api-call-service",
        "z": "d18850c2.xxxxxx",
        "name": "Landing Light On",
        "server": "7b1d3390.xxxxxx",
        "version": 1,
        "debugenabled": false,
        "service_domain": "switch",
        "service": "turn_on",
        "entityId": "switch.landing_ceiling_shelly",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 670,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "ff76b90f.xxxxxx",
        "type": "api-call-service",
        "z": "d18850c2.xxxxxx",
        "name": "Landing Light Off",
        "server": "7b1d3390.xxxxxx",
        "version": 1,
        "debugenabled": false,
        "service_domain": "switch",
        "service": "turn_off",
        "entityId": "switch.landing_ceiling_shelly",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 670,
        "y": 520,
        "wires": [
            []
        ]
    },
    {
        "id": "7b1d3390.xxxxxx",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    },
    {
        "id": "cb5e63c3.xxxxxx",
        "type": "ui_group",
        "name": "Landing",
        "tab": "d9ec6cf6.xxxxxx",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "d9ec6cf6.xxxxxx",
        "type": "ui_tab",
        "name": "Misc",
        "icon": "fa-random",
        "order": 8,
        "disabled": false,
        "hidden": false
    }
]
```

---

<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 May 2021 20:25 UTC](https://discourse.nodered.org/t/on-off-buttons-syncing-with-ha/43833/2 "2021-05-07T20:25:14Z")

</div>

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