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

Tasmota Light flickering when turning off when HomeKit command issued #641

Open SoWizard opened 10 months ago

SoWizard commented 10 months ago

I've got a Tasmota light with colour temperature control running through homebridge-mqttthing. Config:

        {
            "type": "lightbulb-ColTemp",
            "name": "Bathroom Ceiling",
            "username": "***",
            "password": "***",
            "mqttOptions": {
                "keepalive": 30
            },
            "logMqtt": true,
            "topics": {
                "getOnline": "tele/tasmota_x/LWT",
                "setOn": "cmnd/tasmota_x/POWER",
                "getOn": {
                    "topic": "stat/tasmota_x/RESULT",
                    "apply": "return JSON.parse(message).POWER;"
                },
                "setBrightness": "cmnd/tasmota_x/Dimmer",
                "getBrightness": {
                    "topic": "stat/tasmota_x/RESULT",
                    "apply": "return JSON.parse(message).Dimmer;"
                },
                "setColorTemperature": "cmnd/tasmota_x/CT",
                "getColorTemperature": {
                    "topic": "stat/tasmota_x/RESULT",
                    "apply": "return JSON.parse(message).CT;"
                }
            },
            "onlineValue": "Online",
            "offlineValue": "Offline",
            "onValue": "ON",
            "offValue": "OFF",
            "minColorTemperature": 153,
            "maxColorTemperature": 500,
            "accessory": "mqttthing"
        },

It works perfectly when I click on the switch in Home.app to flick it on/off: Pasted Graphic 4

These are the respective commands displayed the Homebridge log:

9/3/2023, 4:41:18 PM] [Bathroom Ceiling] Publishing MQTT: cmnd/tasmota_x/POWER = OFF
[9/3/2023, 4:41:18 PM] [Bathroom Ceiling] Received MQTT: stat/tasmota_x/RESULT = {"POWER":"OFF"}
[9/3/2023, 4:41:18 PM] [Bathroom Ceiling] apply() function decoded message to [OFF]
[9/3/2023, 4:41:18 PM] [Bathroom Ceiling] apply() function decoded message to [undefined]
[9/3/2023, 4:41:18 PM] [Bathroom Ceiling] apply() function decoded message to [undefined]

And in Tasmota:

06:04:51.430 MQT: stat/tasmota_x/RESULT = {"POWER":"OFF"}
06:04:51.435 MQT: stat/tasmota_x/POWER = OFF

Now I have a Siri Shortcut Automation setup as an action for the push-button switch. Purpose is to toggle the light on/off. It uses simple logic. The CT values are unchanged when this shortcut is activated, i.e., in Home.app they do not differ. I only set my lights at the same CT and don't change it. Pasted Graphic 3

The issue is that when I run this, the Tasmota light flickers and changes temperature as it turns off. It's a really jarring experience.

When you look at the logs you can see why: this Siri Shortcut doesn't just send a power on/off signal, but rather the whole desired state of the light.

In Homebridge:

[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] Publishing MQTT: cmnd/tasmota_x/POWER = OFF
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] Publishing MQTT: cmnd/tasmota_x/CT = 489
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] Publishing MQTT: cmnd/tasmota_x/Dimmer = 0
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] Received MQTT: stat/tasmota_x/RESULT = {"POWER":"OFF"}
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [OFF]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [undefined]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [undefined]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] Received MQTT: stat/tasmota_x/RESULT = {"POWER":"ON","Dimmer":100,"Color":"08F7","White":100,"CT":489,"Channel":[3,97]}
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [ON]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [100]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [489]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] Received MQTT: stat/tasmota_x/RESULT = {"POWER":"OFF","Dimmer":0,"Color":"0000","White":0,"CT":489,"Channel":[0,0]}
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [OFF]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [0]
[9/3/2023, 4:56:08 PM] [Bathroom Ceiling] apply() function decoded message to [489]

In Tasmota:

07:53:35.964 MQT: stat/tasmota_x/RESULT = {"POWER":"OFF"}
07:53:35.967 MQT: stat/tasmota_x/POWER = OFF
07:53:36.020 MQT: stat/tasmota_x/RESULT = {"POWER":"ON","Dimmer":100,"Color":"08F7","White":100,"CT":489,"Channel":[3,97]}
07:53:36.069 MQT: stat/tasmota_x/RESULT = {"POWER":"OFF","Dimmer":0,"Color":"0000","White":0,"CT":489,"Channel":[0,0]}

The questions are:

Let me know if y'all need more info :)