Example - Tasmota wall Switch with Humidity/Temp/Dewpoint (Martin Jerry US-FC-01) #529
glasscake
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is an example of my flow for martin jerry wall fan speed controls. There is blocking functionality to stop input loops. It also allows outside inputs (button on device, Tasmota interface, other automation) with feedback to homekit. I am currently using a 2-second repeat input on "get all Tasmota state". When implementing multiple devices just use one "get all Tasmota state" for all Tasmota devices.
Do note if installing on a fan with a built-in control box it must be bypassed, if installing on a fan with manual chain type controls the fan must be switched manually to max speed.
Amazon Link: https://www.amazon.com/dp/B0BFGL98K6?ref=ppx_yo2ov_dt_b_product_details&th=1
https://www.martinjerry.com/us-fc-01
My recommended Tasmota settings:
BackLog MqttHost (YourMQTTIp); MqttUser (your MQTT Login)t; MqttPassword (Your MQTT PW); PowerRetain 1; SetOption53 1; SetOption41 20; Topic (Your mqtt topic); Hostname (your hostname)
Do note if you have a router that handles tasmota devices well drop "SetOption41". If you're noticing a lot of dropped connections renable it.
!!!NOTE: these fan switches need two additional Tasmota commands to work properly!!!:
SetOption66 1
weblog 4 (this can be changed back to weblog 2 if you do not want to see the tuya keep alives but is useful for debugging)
Example flow:
[ { "id": "bddab53deb1c18a3", "type": "mqtt in", "z": "c16b8cbf103f2790", "name": "", "topic": "tele/YOUR_TASMOTA/RESULT", "qos": "2", "datatype": "auto-detect", "broker": "", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 170, "y": 1760, "wires": [ [ "b05d327951e18ba4" ] ] }, { "id": "b05d327951e18ba4", "type": "function", "z": "c16b8cbf103f2790", "name": "TUYA MQTT to Homekit", "func": "\n//translate the mqtt to homekit\n\nif (msg.payload.TuyaReceived[\"3\"] == null)\n{\n return null\n}\n\nmsg.payload = msg.payload.TuyaReceived[\"3\"]\n\nswitch(msg.payload.DpIdData)\n{\n case \"03\":\n msg.payload = { \"RotationSpeed\": 4 }\n break;\n case \"02\":\n msg.payload = { \"RotationSpeed\": 3 }\n break;\n case \"01\":\n msg.payload = { \"RotationSpeed\": 2 }\n break;\n case \"00\":\n msg.payload = { \"RotationSpeed\": 1 }\n break;\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 470, "y": 1760, "wires": [ [ "cb2a0c97623750e5" ] ] }, { "id": "93379e7298da43ed", "type": "mqtt out", "z": "c16b8cbf103f2790", "name": "", "topic": "cmnd/YOUR_TASMOTA/tuyasend0", "qos": "2", "retain": "true", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "", "x": 400, "y": 1700, "wires": [] }, { "id": "631c473d2a0fd6c2", "type": "function", "z": "c16b8cbf103f2790", "name": "MQTT - Homekit Plug", "func": "\n//translate the mqtt to homekit\n\nif (msg.payload.POWER != null) {\n msg.mqtt = msg.payload;\n msg.payload = {\n \"On\": false\n }\n if (msg.mqtt.POWER == \"ON\") {\n msg.payload.On = true\n }\n return msg;\n}\n\n\nreturn null;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 480, "y": 1800, "wires": [ [ "cb2a0c97623750e5" ] ] }, { "id": "7998874454ccb4cc", "type": "homekit-service", "z": "c16b8cbf103f2790", "isParent": true, "hostType": "0", "bridge": "", "accessoryId": "", "parentService": "", "name": "Your HK Fan", "serviceName": "Fan", "topic": "", "filter": false, "manufacturer": "NRCHKB", "model": "1.5.0", "serialNo": "Default Serial Number", "firmwareRev": "1.5.0", "hardwareRev": "1.5.0", "softwareRev": "1.5.0", "cameraConfigVideoProcessor": "ffmpeg", "cameraConfigSource": "", "cameraConfigStillImageSource": "", "cameraConfigMaxStreams": 2, "cameraConfigMaxWidth": 1280, "cameraConfigMaxHeight": 720, "cameraConfigMaxFPS": 10, "cameraConfigMaxBitrate": 300, "cameraConfigVideoCodec": "libx264", "cameraConfigAudioCodec": "libfdk_aac", "cameraConfigAudio": false, "cameraConfigPacketSize": 1316, "cameraConfigVerticalFlip": false, "cameraConfigHorizontalFlip": false, "cameraConfigMapVideo": "0:0", "cameraConfigMapAudio": "0:1", "cameraConfigVideoFilter": "scale=1280:720", "cameraConfigAdditionalCommandLine": "-tune zerolatency", "cameraConfigDebug": false, "cameraConfigSnapshotOutput": "disabled", "cameraConfigInterfaceName": "", "characteristicProperties": "{\"RotationSpeed\":{\"minValue\":0,\"maxValue\":4}}", "waitForSetupMsg": false, "outputs": 2, "x": 1330, "y": 1760, "wires": [ [ "1dd712e2b45acd32", "b4beb5611ff44e06" ], [] ] }, { "id": "cccccfe0a3ceb293", "type": "comment", "z": "c16b8cbf103f2790", "name": "tasmota must setup commands for fans", "info": "SetOption66 1\nweblog 4", "x": 830, "y": 1700, "wires": [] }, { "id": "014c151a13757146", "type": "function", "z": "c16b8cbf103f2790", "name": "inject 3", "func": "\nmsg.payload = \"3\"\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 160, "y": 1700, "wires": [ [ "93379e7298da43ed" ] ] }, { "id": "49e0b8f9c3263f64", "type": "comment", "z": "c16b8cbf103f2790", "name": "Speed control fans", "info": "", "x": 190, "y": 1600, "wires": [] }, { "id": "1dd712e2b45acd32", "type": "function", "z": "c16b8cbf103f2790", "name": "Homekit to MQTT ", "func": "\n//update mqtt rotation speed\n\n\nif (msg.payload.RotationSpeed != null)\n{\n switch (msg.payload.RotationSpeed)\n {\n case 0:\n //same as the fan being off\n return null;\n case 1:\n msg.payload = \"3,0\"\n break;\n case 2:\n msg.payload = \"3,1\"\n break;\n case 3:\n msg.payload = \"3,2\"\n break;\n case 4:\n msg.payload = \"3,3\"\n break;\n }\n return [msg,null]\n}\n\nif (msg.payload.On != null) {\n if (msg.payload.On == true) {\n return [null, {payload:true}];\n }\n return [null, {payload:false}];\n}\n\nreturn [null,null];", "outputs": 2, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1550, "y": 1760, "wires": [ [ "b67f65a185f2fecf" ], [ "47ad609a92d0b157" ] ] }, { "id": "47ad609a92d0b157", "type": "mqtt out", "z": "c16b8cbf103f2790", "name": "", "topic": "cmnd/YOUR_TASMOTA/Power", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "", "x": 1830, "y": 1780, "wires": [] }, { "id": "b67f65a185f2fecf", "type": "mqtt out", "z": "c16b8cbf103f2790", "name": "", "topic": "cmnd/YOUR_TASMOTA/tuyasend4", "qos": "2", "retain": "true", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "", "x": 1840, "y": 1740, "wires": [] }, { "id": "145104fcb4f306f4", "type": "mqtt in", "z": "c16b8cbf103f2790", "name": "", "topic": "stat/YOUR_TASMOTA/RESULT", "qos": "2", "datatype": "auto-detect", "broker": "", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 170, "y": 1800, "wires": [ [ "631c473d2a0fd6c2" ] ] }, { "id": "e13bd7d348f5f8dd", "type": "function", "z": "c16b8cbf103f2790", "name": "Block", "func": "//block all messages until the device has updated itself\n//this also stops loops and other odd issues\n\n//initalize into passing\nif (context.get('blocking') == null) {\n node.status({ fill: \"green\", shape: \"dot\", text: \"passing\" });\n context.set('blocking', false)\n return null\n}\n\n//is this a homekit message\nif (msg.payload.type == 1)\n{\n //that means the homekit service is sending data to the device\n //block all messages untill the device responds on mqtt\n context.set('blocking', true)\n //save what the message was so we confirm it is correct\n //also need to save what the last change was since homekit only reports either brightness or power\n if (msg.payload.Brightness != null)\n {\n context.set('lastchange', 0)\n context.set('RotationSpeed', msg.payload.RotationSpeed)\n }\n if (msg.payload.On != null)\n {\n context.set('lastchange', 1)\n context.set('status', msg.payload.On)\n }\n node.status({ fill: \"red\", shape: \"dot\", text: \"blocking\" });\n return null\n}\n\nif (msg.payload.type == 0)\n{\n //this is an mqtt response, lets see if the response matches the set status\n //check what the last homekit message was and comapare\n if (\n //was the last change a brightness change and do they match?\n (context.get('lastchange') == 0 && context.get('RotationSpeed') == msg.payload.RotationSpeed)\n || //or\n //was the last change a power change and do they match\n (context.get('lastchange') == 1 && context.get('status') == msg.payload.On)\n )\n {\n //one of the above were true\n //they match, disable blocking\n context.set('blocking', false)\n node.status({ fill: \"green\", shape: \"dot\", text: \"passing\" });\n }\n}\n\n//get the current blocking state\nvar blocking = context.get('blocking')\n\nif (blocking == true)\n{\n return null\n}\n\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 870, "y": 1760, "wires": [ [ "94bfc8978a0e139b" ] ] }, { "id": "cb2a0c97623750e5", "type": "function", "z": "c16b8cbf103f2790", "name": "Set Type", "func": "//let the block know this is an mqtt message\n\nmsg.payload.type = 0\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 700, "y": 1760, "wires": [ [ "e13bd7d348f5f8dd" ] ] }, { "id": "b4beb5611ff44e06", "type": "function", "z": "c16b8cbf103f2790", "name": "Set Type", "func": "//let the block know if this is a homekit message\n\nmsg.payload.type = 1\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1100, "y": 1820, "wires": [ [ "e13bd7d348f5f8dd" ] ] }, { "id": "94bfc8978a0e139b", "type": "change", "z": "c16b8cbf103f2790", "name": "", "rules": [ { "t": "delete", "p": "payload.type", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1090, "y": 1760, "wires": [ [ "7998874454ccb4cc" ] ] }, { "id": "8672283051b5d3ee", "type": "mqtt out", "z": "c16b8cbf103f2790", "name": "Get all tasmotas state", "topic": "cmnd/tasmotas/STATE", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "", "x": 300, "y": 1640, "wires": [] }, { "id": "8eae04883ab85cbf", "type": "inject", "z": "c16b8cbf103f2790", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 100, "y": 1640, "wires": [ [ "8672283051b5d3ee", "014c151a13757146" ] ] } ]
Beta Was this translation helpful? Give feedback.
All reactions