Getting Tasmota working with OH3 using MQTT
This is for someone that has installed openhabian and wants to use tasmota to control their device.
Prerequisite
SSH Access - I like and use https://termius.com/
MQTT Broker - I Mosquitto as the Broker for all of my MQTT devices. I install using the openhabian config tool.
Device - Tasmota installed on a device and be able to view webpage.
MQTT Client - http://mqtt-explorer.com/
SSH
If you haven’t done so installed mosquitto using ssh
- login to SSH
sudo openhabian-config
- Optional Componets
- Mosquitto
- If you want password enter it in here. Mine is
pleasework
Tasmota
For this example I will use a sonoff basic for a Light called My Light.
- Get device working with the webage so you can control it through TASMOTA
Doccumentation - Open Configuration - Config MQTT
- In Host enter the IP address of your MQTT Broker (RPI)
- Port 1883 and Client DVES_%06X can be left default
- User if default and password is set openhabian
- Pass pleasework
- Test Connection to MQTT works in console
MQTT Client
- Enter connection details
Using the client is will automaticy subscribe to every topic and show it to you. You Can also publish anything to any topic.
- Get the MQTT Client to turn the light ON
Publish ON to cmnd/MyLIGHT/POWER topic.
You can see that after publishing this you can see that TASMOTA sends state to stat/MyLIGHT/POWER
openHAB 3 Broker Creation
Only one broker bridge is needed for all of you’re MQTT Thing’s
- Install MQTT Binding
Settings / Addons / Bindings / Blue + / MQTT Binding
- Create Broker Bridge connection
- Settings / Things / Blue + / MQTT Binding / MQTT Broker Link
- Change the Unique ID at the top it can’t be changed later.
- Enter other details select show advanced if you need to put a password in
You’re Broker should show online
openHAB 3 Generic MQTT Thing Creation
-
Settings / Things / Blue + / MQTT Binding / Generic MQTT Thing Link
-
Enter settings clicking Show advanced
- Unique ID
MYlight
- Label
MY Light
- Click on Parent Bridge and Select
- Avalibility Topic
tele/MyLIGHT/LWT
- Payload available
Online
- Payload not availabe
Offline
- Create Thing
Add Channels to Generic MQTT Thing
- Select The My Light thing
- Channels Tab
- Add Channel
- Enter Settings
- Channel Identifier
POWER
- Can be anything - Label
MY Light
- On/Off Switch
- MQTT State Topic
stat/MyLIGHT/POWER
- MQTT Command Topic
cmnd/MyLIGHT/POWER
- Custom On/Open Value
ON
- Custom Off/Closed Value
OFF
This is how you add channels to you thing you can go ahead and create all the channels you need this way or enter them in YAML code in the code tab.
channels:
- id: POWER
channelTypeUID: mqtt:switch
label: Power Switch
description: ""
configuration:
stateTopic: stat/MyLIGHT/POWER
off: OFF
on: ON
commandTopic: cmnd/MyLIGHT/POWER
Add these channels below
- id: Uptime
channelTypeUID: mqtt:string
label: UP time
description: ""
configuration:
stateTopic: tele/MyLIGHT/STATE
transformationPattern: JSONPATH:$.Uptime
- id: LoadAvg
channelTypeUID: mqtt:string
label: LoadAvg
description: null
configuration:
stateTopic: tele/MyLIGHT/STATE
transformationPattern: JSONPATH:$.LoadAvg
- id: WIFI_Signal
channelTypeUID: mqtt:string
label: WIFI Signal
description: null
configuration:
stateTopic: tele/MyLIGHT/STATE
transformationPattern: JSONPATH:$.Wifi.Signal
Install JSONPATH transofrmation
If you haven’t allready done so add a couple of locations to your Model.
Create items using Create Equipment from Thing
-
Settings / Model / Select Location if desired /Create Equipment from Thing
-
Select your thing MY Light
- Simantic Class: Light Bulb
-
Select ALL
-
Add To Model
-
Navigate to My Light Power Switch Point and Add Metadata
- Change Default Standalone Widget to oh-toggle-card
This Should now show up in the equipment tab of your openhab Front Page under light bulb
Coustom Widget
Here is a custom widget you can add so you can set the default stanadalone widget to see more than just a toggle switch.
uid: Tasmota_SONOFF
tags: []
props:
parameters:
- description: A text prop
label: Name
name: prop1
required: false
type: TEXT
- context: item
description: An item to control
label: Item
name: item
required: false
type: TEXT
parameterGroups: []
component: f7-card
config:
outline: false
noBorder: true
padding: false
noShadow: true
style:
--f7-safe-area-right: 0
--f7-safe-area-left: 0
slots:
content:
- component: oh-button
config:
action: toggle
actionItem: =(props.item + "_PowerSwitch")
actionCommand: ON
actionCommandAlt: OFF
icon-f7: lightbulb_fill
iconSize: 25
iconColor: '=(items[props.item + "_PowerSwitch"].state === "OFF") ? "black" : "yellow"'
- component: f7-card
config:
content: =items[props.item + "_PowerSwitch"].displayState || items[props.item + "_PowerSwitch"].state
- component: f7-card
config:
title: Load Average
content: =items[props.item + "_LoadAvg"].displayState || items[props.item + "_LoadAvg"].state
- component: f7-card
config:
title: UP Time
content: =items[props.item + "_UPtime"].displayState || items[props.item + "_UPtime"].state
- component: f7-card
config:
title: WIFI Signal
content: =items[props.item + "_WIFISignal"].displayState || items[props.item + "_WIFISignal"].state