arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
462 stars 104 forks source link

Toggling the physical switch on Sonoff Basic does not update its state in Homebridge #557

Closed reinisb closed 2 years ago

reinisb commented 2 years ago

What happens

When I press the physical button located on Sonoff Basic, then it toggles the switch, but the updated status is not reflected in Homebridge.

What should happen

I expect the status to be reflected in Homebridge when using Sonoff Basic's physical button.

Config

Screen Shot 2022-05-14 at 14 08 51
reinisb commented 2 years ago

@arachnetech Could you please have a quick look? I bet you could infer the issue in a few seconds by looking at the above config screenshot. Thanks!

KiwiV commented 2 years ago

Try changing Get On MQTT topic to: stat/sonoff-basic-r2-b/POWER

reinisb commented 2 years ago

Try changing Get On MQTT topic to: stat/sonoff-basic-r2-b/POWER

I tried, but that does not resolve the problem.

reinisb commented 2 years ago

I figured it out. The solution was neither documented, nor obvious.

You see, my Sonoff Basic is running Tasmota firmware. When the physical switch (or the tasmota web ui switch) is toggled, tasmota sends the following MQTT messages:

stat/sonoff-basic-r2-b/POWER = ON

or

stat/sonoff-basic-r2-b/POWER = OFF

What I realized is that homebridge-mqttthing does not understand what ON or OFF means. It expects the values to be true or false. I would expect homebridge-mqttthing to understand what ON or OFF means.

The solution is to go into homebridge-mqttthing Advanced settings in Homebridge and add ON or OFF values to these fields.

Screen Shot 2022-06-03 at 19 34 57

The final working config looks like:

    "accessories": [
        {
            "type": "lightbulb-OnOff",
            "name": "Lampa",
            "username": "reinis",
            "password": "macbook",
            "topics": {
                "getOnline": "tele/sonoff-basic-r2-b/LWT",
                "getOn": "stat/sonoff-basic-r2-b/POWER",
                "setOn": "cmnd/sonoff-basic-r2-b/POWER"
            },
            "onlineValue": "ON",
            "offlineValue": "OFF",
            "integerValue": false,
            "onValue": "ON",
            "offValue": "OFF",
            "accessory": "mqttthing"
        }
    ]
degudejung commented 1 year ago

Thank you for posting this solution. I was struggling with the same and found the missing on=true off=false mapping too obvious to consider.

sachasmart commented 1 year ago

Gosh this was brutal. Same went for me when trying to integrate Nodered with Homebridge. Thank you for posting this!