Autor Thema: tasmota mosquitto and mqtt2_client example needed  (Gelesen 1355 mal)

Offline kroonen

  • Full Member
  • ***
  • Beiträge: 166
    • http://www.kroonen.eu/mobile
tasmota mosquitto and mqtt2_client example needed
« am: 26 April 2020, 16:35:38 »
Hi,

I setup mqtt2 with mosquitto

define mqtt2 MQTT2_CLIENT 192.168.180.5:8883
attr mqtt2 SSL 1
attr mqtt2 devStateIcon .*:mqtt
attr mqtt2 room System
attr mqtt2 username fhem

define bridge_mqtt MQTT_GENERIC_BRIDGE
attr bridge_mqtt IODev mqtt2
attr bridge_mqtt room System


And works with a dummy device with mqttsubscriibe for temperature sensors.

Now I want it to work with tasmota switches. I only found examples with mqtt2_server. Does someone have an example for tamsota with mqtt2_client with mosquitto broker ?


Offline Beta-User

  • Developer
  • Hero Member
  • ****
  • Beiträge: 14097
  • "Developer"?!? Meistens doch eher "User"
Antw:tasmota mosquitto and mqtt2_client example needed
« Antwort #1 am: 26 April 2020, 17:12:39 »
Not a direct answer: I'd recommend to use two "helper MQTT2_DEVICE"s:
One that collects all messages that do not have any "recipient" in FHEM yet (if you let autocreate work (make a test with "simple"), basically all MQTT info will go to one singe MQTT2_DEVICE...).

Note: autocreate and MQTT_GENERIC_BRIDGE may not work too good together, so see other option below...

The second you can create by do an attrTemplate-assignment to the first: attr <your collecting device> attrTemplate MQTT2_CLIENT_general_bridgeThis second device will have a "bridgeRegexp" to sort out the original devices that will work if you use "standard" MQTT topic structure in your tasmota devices. You may change this setting to your needs.

Perhaps the best way to get a first impression how this may work is to add a MQTT2_SERVER device using a different Port ("define myMQTT2test server 1884 global") and point one tasmota after oneother to that IP/Port combination for initial setup. Later you may just change the IO from M2_Server to M2_Client.

Hope this helps as a starting point.

Kind regards, Beta-User
Server: HP-T620@Debian 10, aktuelles FHEM + ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | BT@OpenMQTTGateway
svn:MySensors, WeekdayTimer, RandomTimer, Twilight,  AttrTemplate => {mqtt2, mysensors, zwave}

Offline RaspiLED

  • Hero Member
  • *****
  • Beiträge: 2451
  • Es begann alles so klein ;-)
tasmota mosquitto and mqtt2_client example needed
« Antwort #2 am: 26 April 2020, 18:04:20 »
Hi,

Here is my Tasmota coffee machine switch:
stat/Wuudi/RESULT = {"Topic":"Wuudi"}
and in FHEM:
defmod KU_Kaffee MQTT2_DEVICE DVES_2A360A
attr KU_Kaffee IODev MQTT2_FHEM_Server
attr KU_Kaffee autocreate 0
attr KU_Kaffee comment NOTE: For on-for-timer SetExtensions are used. You may add on-for-timer option running on the device. The following is limited to 1h max duration, but will not affect future simple "on" commands:<br>on-for-timer {my $duration = $EVTPART1*10;; 'cmnd/Wuudi/Backlog POWER1 1;; delay '.$duration.';; POWER1 0'}<br>See the "Praxisbeispiele" in the wiki for "pulseTime1" alternative option and it's restrictions.
attr KU_Kaffee genericDeviceType switch
attr KU_Kaffee icon virtualbox
attr KU_Kaffee jsonMap POWER1:0 POWER2:0 POWER3:0 POWER4:0 Dimmer:0 Channel_0:0 Channel_1:0 Channel_2:0 Channel_3:0 Channel_4:0 HSBColor:0 Color:0
attr KU_Kaffee model tasmota_basic_state_power1
attr KU_Kaffee readingList tele/Wuudi/LWT:.* LWT\
  tele/Wuudi/STATE:.* { json2nameValue($EVENT,'',$JSONMAP) }\
  tele/Wuudi/SENSOR:.* { json2nameValue($EVENT,'',$JSONMAP) }\
  tele/Wuudi/INFO.:.* { json2nameValue($EVENT,'',$JSONMAP) }\
  tele/Wuudi/UPTIME:.* { json2nameValue($EVENT,'',$JSONMAP) }\

subscriptions
cmnd/DVES_2A360A_fb/# cmnd/Wuudi/# cmnd/tasmotas/#
FallbackTopic
cmnd/DVES_2A360A_fb/
GroupTopic
cmnd/tasmotas/

And here the mqtt2 Device in FHEM:

defmod MQTT2_FHEM_Server MQTT2_SERVER 1883 global

setstate MQTT2_FHEM_Server 2020-04-26 17:57:34 RETAIN {"tele/DVES_93AADA/LWT":"Offline","tele/Wuudi/LWT":"Online","tele/tasmota/LWT":"Online","tele/tasmota_809852/LWT":"Offline","tele/tasmota_93AADA/LWT":"Offline"}
setstate MQTT2_FHEM_Server 2020-04-17 09:10:34 lastPublish cmnd/InSmart/Backlog:StateText1 off;; StateText2 on;; StateText3 toggle;; StateText4 hold;; SetOption26 1;; SaveData 1
setstate MQTT2_FHEM_Server 2020-04-26 17:58:37 nrclients 6
setstate MQTT2_FHEM_Server 2020-04-17 15:46:32 state Initialized

Greetings, Arnd


Signalduino (Nano, ESP, ...), CUL (Busware, Nano, Maple, ...), Homematic (HM-MOD-UART-RPI, ESP, Maple, ...), LaCrosseGateway (LGW, ESP, ...), 1-wire, ESPEasy, Bravia, Yamaha, ...
Raspberry Pi mit FHEM, CUL, Signalduino, MySensors, HomeBridge, Presence, WifiLight2, Bravia, ...

Offline kroonen

  • Full Member
  • ***
  • Beiträge: 166
    • http://www.kroonen.eu/mobile
Antw:tasmota mosquitto and mqtt2_client example needed
« Antwort #3 am: 28 April 2020, 19:52:42 »
@beta-user,

Looks like a nice option, can you give me some more , as an example, so I can test it. I have a clean fhem installation on a different server, I only want to use the mosquitto broker, I also ude homeassistant, and want to use both smarthome systems together

regards RIchard
« Letzte Änderung: 28 April 2020, 19:54:52 von kroonen »

Offline Beta-User

  • Developer
  • Hero Member
  • ****
  • Beiträge: 14097
  • "Developer"?!? Meistens doch eher "User"
Antw:tasmota mosquitto and mqtt2_client example needed
« Antwort #4 am: 28 April 2020, 20:51:46 »
So just use your clean test installation and point MQTT2_CLIENT to your mosquitto and activate "autocreate simple", then apply the already mentionned "sorting" attrTemplate. Then we should see to which extend everything works?
Server: HP-T620@Debian 10, aktuelles FHEM + ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | BT@OpenMQTTGateway
svn:MySensors, WeekdayTimer, RandomTimer, Twilight,  AttrTemplate => {mqtt2, mysensors, zwave}

Offline kroonen

  • Full Member
  • ***
  • Beiträge: 166
    • http://www.kroonen.eu/mobile
Antw:tasmota mosquitto and mqtt2_client example needed
« Antwort #5 am: 29 April 2020, 10:35:25 »
Hi,

I got some results and looks like its working (created a lot of devices). Now I modifying an devices

I have one question. The icon appears when I press it in the fhem web interface light on , it changes shot orange and that green (icon is correct nut green). When I press it from the tasmota webinterface it goes only to te right icon. My wish that it also change the orange color.

When I do the jsonmap POWER:State (with capitel S) than fhem works  with color, but the state form tasmota doesn't work anymore. Any idea how to fix that the icon color en type is right?

l MQTT2_lampslaap
Internals:
   CID        lampslaap
   DEF        lampslaap
   DEVICETOPIC MQTT2_lampslaap
   FUUID      5ea92a45-f33f-d772-afa7-c64962a965eb31ff
   IODev      mqtt2
   LASTInputDev mqtt2
   MSGCNT     81
   NAME       MQTT2_lampslaap
   NR         67
   STATE      OFF
   TYPE       MQTT2_DEVICE
   mqtt2_MSGCNT 81
   mqtt2_TIME 2020-04-29 10:20:37
   JSONMAP:
     POWER      state
   READINGS:
     2020-04-29 10:19:17   Heap            24
     2020-04-29 10:02:43   LWT             Online
     2020-04-29 10:19:17   LoadAvg         19
     2020-04-29 10:19:17   MqttCount       3
     2020-04-29 10:06:01   POWER           OFF
     2020-04-29 10:19:17   Sleep           50
     2020-04-29 10:19:17   SleepMode       Dynamic
     2020-04-29 10:19:17   State           OFF
     2020-04-29 10:19:17   Switch1         OFF
     2020-04-29 10:19:17   Time            2020-04-29T09:19:17
     2020-04-29 10:19:17   Uptime          2T11:45:31
     2020-04-29 10:19:17   UptimeSec       215131
     2020-04-29 10:19:17   Wifi_AP         1
     2020-04-29 10:19:17   Wifi_BSSId      B0:B8:67:08:14:84
     2020-04-29 10:19:17   Wifi_Channel    1
     2020-04-29 10:19:17   Wifi_Downtime   0T00:00:18
     2020-04-29 10:19:17   Wifi_LinkCount  1
     2020-04-29 10:19:17   Wifi_RSSI       56
     2020-04-29 10:19:17   Wifi_SSId       sensors
     2020-04-29 10:19:17   Wifi_Signal     -72
     2020-04-28 22:09:16   associatedWith  MQTT2_GeneralBridge
     2020-04-29 10:20:37   state           OFF
Attributes:
   IODev      mqtt2
   Webcmd     on:off:reboot
   autocreate 0
   icon       light_ceiling_light
   jsonMap    POWER:state
   readingList tele/lampslaap/LWT:.* LWT
  tele/lampslaap/STATE:.* { json2nameValue($EVENT,'',$JSONMAP) }
  tele/lampslaap/SENSOR:.* { json2nameValue($EVENT,'',$JSONMAP) }
  tele/lampslaap/INFO.:.* { json2nameValue($EVENT,'',$JSONMAP) }
  tele/lampslaap/UPTIME:.* { json2nameValue($EVENT,'',$JSONMAP) }
  stat/lampslaap/RESULT:.* { json2nameValue($EVENT,'',$JSONMAP) }
   room       Slaapkamer
   setList    on cmnd/lampslaap/POWER on
   off cmnd/lampslaap/POWER off

   stateFormat state

Offline Beta-User

  • Developer
  • Hero Member
  • ****
  • Beiträge: 14097
  • "Developer"?!? Meistens doch eher "User"
Antw:tasmota mosquitto and mqtt2_client example needed
« Antwort #6 am: 29 April 2020, 11:00:06 »
Hm, hard to follow your description, and even harder to suggest a solution...

So short story: there are a lot more attrTemplates available to configure Tasmota-MQTT-Devices, but they have one big disadvantages when beeing applied while using a second controller software: They will change some basic settings on the ESP itself (e.g. sending states in lowercase and use POWER1 instead of POWER for first relay). Not sure, if homeassistant will "like" these changes.
Perhaps you best do also a test on that with a single device? (There should be also a template available to revert these changes; if not: it's just a couple of backlog commands). Otherwise we would have to do a much deeper digg into the interdependencies of different attributes...
Server: HP-T620@Debian 10, aktuelles FHEM + ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | BT@OpenMQTTGateway
svn:MySensors, WeekdayTimer, RandomTimer, Twilight,  AttrTemplate => {mqtt2, mysensors, zwave}