arachnetech / homebridge-mqttthing

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

3 speed fan with light config issue #390

Open jakesza opened 3 years ago

jakesza commented 3 years ago

Hi, I am trying to get a 3 speed fan with built in light to work with mqttthing but it seems to be limited config wise.

Can somebody please shed some light as to how the configuration would look, I have this below and can switch on the fan to low and switch it off. I am using an RF bridge.

I need to know how to use the topics to set the speeds and light based on the topics below. please anyone :)

{ "type": "fan", "name": "Girls Fan", "topics": { "setOn": "cmnd/RF-Bridge/rfraw" }, "onValue": "AAB0210308013602801B1C2819090908190818181908181818190909090909081908181855", "offValue": "AAB0210308014A026C1AC22819090908181909081908181819090819090909081818190855", "otherValueOff": false, "accessory": "mqttthing"

Jakohoho commented 3 years ago

Hi, you probably have to treat the light as a separate device. Since the plugin only supports speed 0-100% as far as I know, I configured the rest in Node Red: 1-33% = Speed 1, 34-66% = Speed 2,> 67% = Speed 3. Screenshot 2021-01-12 164724

jakesza commented 3 years ago

Interesting thanks, Do you mind sharing the node red code for the above?

Jakohoho commented 3 years ago

Speed 1: var t = msg.payload

if (t > 0) { if (t <= 33) { msg.payload = "1"; return msg; } }

Same for the others

rbswift commented 3 years ago

This works well for me using Tasmota and iFan03:

            "topics": {
                "setRotationSpeed": {
                    "topic": "cmnd/loungefan/fanspeed",
                    "apply": "return (Math.round(message/100*3))"
                },
                "getRotationSpeed": {
                    "topic": "stat/loungefan/RESULT",
                    "apply": "return (isNaN(JSON.parse(message).FanSpeed) ? state.rotationSpeed : (Math.round(JSON.parse(message).FanSpeed/3*100)))"
                }
            },
jakesza commented 3 years ago

This works well for me using Tasmota and iFan03:

            "topics": {
                "setRotationSpeed": {
                    "topic": "cmnd/loungefan/fanspeed",
                    "apply": "return (Math.round(message/100*3))"
                },
                "getRotationSpeed": {
                    "topic": "stat/loungefan/RESULT",
                    "apply": "return (isNaN(JSON.parse(message).FanSpeed) ? state.rotationSpeed : (Math.round(JSON.parse(message).FanSpeed/3*100)))"
                }
            },

This is great thanks!

pedroxns commented 3 years ago

This works well for me using Tasmota and iFan03:

            "topics": {
                "setRotationSpeed": {
                    "topic": "cmnd/loungefan/fanspeed",
                    "apply": "return (Math.round(message/100*3))"
                },
                "getRotationSpeed": {
                    "topic": "stat/loungefan/RESULT",
                    "apply": "return (isNaN(JSON.parse(message).FanSpeed) ? state.rotationSpeed : (Math.round(JSON.parse(message).FanSpeed/3*100)))"
                }
            },

Works perfectly with iFan02 also ! Thanks !

bassrock commented 3 years ago

@pedroxns Do you mind sharing the whole config? Do you have the light working for it as well?

pedroxns commented 3 years ago

@pedroxns Do you mind sharing the whole config? Do you have the light working for it as well?

Yes, for sure ! Sorry for taking 3 days to answer.

here it goes

 {
            "type": "fan",
            "name": "Ventilador Suite",
            "topics": {
                "setRotationSpeed": {
                    "topic": "cmnd/suite_vent/fanspeed",
                    "apply": "return (Math.round(message/100*3))"
                },
                "getRotationSpeed": {
                    "topic": "stat/suite_vent/RESULT",
                    "apply": "return (isNaN(JSON.parse(message).FanSpeed) ? state.rotationSpeed : (Math.round(JSON.parse(message).FanSpeed/3*100)))"
                }
            },
            "accessory": "mqttthing"
        },
{
            "type": "lightbulb-OnOff",
            "name": "Sanca suite",
            "topics": {
                "getOnline": "cmnd/suite_vent/LWT",
                "getOn": "stat/suite_vent/power1",
                "setOn": "cmnd/suite_vent/power1"
            },
            "onlineValue": "Online",
            "onValue": "ON",
            "offValue": "OFF",
            "accessory": "mqttthing"
        },

The only thing I wish I could take a better look and change is that Alexa now recognize the speeds only by percentages. Before tasmota+mqtt the request was "Alexa, bedroom fan speed 1/2/3" now it is "Alexa, bedroom fan speed 33/66/99". The ligh work perfectly and the fan stays on when I turn off just the lights.

rbswift commented 3 years ago

@pedroxns I didn't even know you could use Homebridge with Alexa. I thought it was only Apple/Siri. Anyway, you could try this if you want to set the fan using 1/2/3. It works from Siri but of course Siri responds "I've set the fan to 1 percent" which is a bit weird even though it shows 33% in the app.

                "setRotationSpeed": {
                    "topic": "cmnd/loungefan/fanspeed",
                    "apply": "return ( (message >= 1 && message <= 3) ? message : Math.round(message/100*3))"
rbswift commented 3 years ago

@bassrock for HomeKit you must configure the light as a separate accessory. You can use the configuration for the sonoff basic switch (not zigbee) from here: https://github.com/arachnetech/homebridge-mqttthing/wiki/Tested-Configurations#Dimmers-and-Switches

pedroxns commented 3 years ago

@pedroxns I didn't even know you could use Homebridge with Alexa. I thought it was only Apple/Siri. Anyway, you could try this if you want to set the fan using 1/2/3. It works from Siri but of course Siri responds "I've set the fan to 1 percent" which is a bit weird even though it shows 33% in the app.

                "setRotationSpeed": {
                    "topic": "cmnd/loungefan/fanspeed",
                    "apply": "return ( (message >= 1 && message <= 3) ? message : Math.round(message/100*3))"

Yes, you can ! Just have to use this plugin. I use Alexa for voice commands, Home app for pc/iphone control and node-red for automations like "light up a light when a door opens and luminance is below X" and buttons setup.

vk2tds commented 2 years ago

Thanks for the help. I have managed to implement code for a fan with High, Med and Low settings as well as Off using a Sonoff RF Bridge using the Tasmota firmware and Portisch firmware. The applyRaw shows a simplified version of what I was doing.

The only thing that doesn’t work is that I have needed to disable the Turn On command, as it seems to get sent whenever you change the fan speed. This means that you can’t turn the fan on by tapping the icon on, but rather by pushing on the icon and adjusting the fan speed to the desired level.

The code is basically a JavaScript nested ternary in the JSON. Hope this helps someone.

    {
        "type": "fan",
        "name": "MBR Fan",
        "url": "",
        "username": "",
        "password": "",
        "logMqtt": true,
        "topics": {
            "setOn": {
                "topic": "cmnd/tasmota_49DAC7/Backlog",
                "applyRaw": "return ( (message) ? 'RfRaw On; RfRaw 0' : 'RfRaw Off; RfRaw 0')",
                "apply": "return ( (message) ? '' : 'RfRaw AA B0 23 04 08 0122 02D0 00D2 1FEA 38181818181928192819281908190819090909090818181818 55; RfRaw 0')"
            },
            "setRotationSpeed": {
                "topic": "cmnd/tasmota_49DAC7/Backlog",
                "applyRaw": " return ( (message < 34)? 'low': (message < 67) ? 'med' : 'high')  ",
                "apply": " return ( (message < 34)? 'RfRaw AA B0 23 04 08 012C 02C6 00BE 1FD6 38181818181928192819281928192819281818181928181818 55; RfRaw 0': (message < 67) ? 'RfRaw AA B0 23 04 08 012C 02C6 00BE 1FE0 38181818181928192819281928192819081818181819281818 55; RfRaw 0' : 'RfRaw AA B0 23 04 08 012C 02D0 00C8 1FE0 38181818181928192819281928192819281818181909281818 55; RfRaw 0')  "
            }
        },
        "accessory": "mqttthing"
    }