mqtt with fhem

Begonnen von bend94, 19 Juni 2019, 14:43:54

Vorheriges Thema - Nächstes Thema

bend94

hi,

I want to start FHEM-MQTT to be able to catch all message in nodered
i did this in FHEM

fhem> define MQfhem MQTT 192.168.0.6:1884
fhem> set MQfhem connect

When i list my MQfhem object it is always "Disconnected"

fhem> list MQfhem
Internals:
   CFGFN
   DEF        192.168.0.6:1884
   DeviceName 192.168.0.6:1884
   FUUID      5d0a2bd4-f33f-0be6-ab16-d0268acf8528ce0a
   NAME       MQfhem
   NEXT_OPEN  1560948152
   NOTIFYDEV  global
   NR         88
   NTFY_ORDER 50-MQfhem
   PARTIAL
   STATE      disconnected
   TYPE       MQTT
   msgid      1
   timeout    60
   READINGS:
     2019-06-19 14:41:32   state           disconnected
   messages:
Attributes:

Do you know why?
Thanks in advance

Beta-User

Sure about the port nr? e.g. mosquitto defaults to 1883.

If you are just about to start with MQTT and do not use much stuff yet, you may consider using MQTT2_SERVER. This way you'll not need any additional software like mosquitto nor additional Perl modules to get it up and running.
Also autocreate may help you to add new devices, and attrTemplate can be used to configure MQTT2_DEVICEs just in a few seconds (if it's a commonly used hardware with more or less default settings).
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bend94

i used port 1884 because i have already domoticz-mqtt speaking on 1883

Beta-User

so you have 2 server instances of mosquitto running?

If there's just one server (fomer:broker), all of the clients have to use the same port.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bend94


i have already domoticz-mqtt on 1883
when i enter in FHEM : define MQTT MQTT2_Server localhost:1883
i catch port already in use

Beta-User

#5
OK, that's a different story.

MQTT2_SERVER implements a Broker instance (similar to mosquittto), so you also have to use a different port for it (and the syntax is different also, se commandref!) .
Note: you'll _not need_ any MQTT device (TYPE=MQTT), MQTT2_SERVER acts as IO module itself.



If your data should be handled by mosquitto, try MQTT2_CLIENT as IO and have a look to the corresponding cref (should "listen" to the port mosquitto uses, most likely 1883).
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

Beta-User

Zitat von: Beta-User am 19 Juni 2019, 15:40:44
If your data should be handled by mosquitto, try MQTT2_CLIENT as IO and have a look to the corresponding cref (should "listen" to the port mosquitto uses, most likely 1883).
If your (non-FHEM-) system is configured as described here https://www.domoticz.com/wiki/MQTT, I'd recommend to do the following:

- define a MQTT2_CLIENT
define MQfhem MQTT2_CLIENT 192.168.0.6:1883
- switch autocreate (@MQfhem) on, set it to "simple"
- a new MQTT2_DEVICE will be created (could take some time), if a TYPE=autocreate device ist active (sth. like MQTT2_MQfhem).
- apply A_00_MQTT2_CLIENT_general_bridge to it:set MQTT2_MQfhem attrTemplate A_00_MQTT2_CLIENT_general_bridge
Then post RAW definitions of all your mqtt2-devices that will be have been created after some minutes waiting periode or mosquitto restart (and especially the readingList of MQTT2_MQfhem), if you need further help.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

bend94

hi

i followed your instructions but i not sure to have the good result
here with your configuration it seems that i received in fhem all messages coming from domoticz.

my goals is to have  FHEM to send to nodered all informations regarding some FHEM changes
In fact, i want domoticz to send to nodered (it is working with port 1883)
now i want fhem to send to nodered too (same port with another topic)

like this i will be able to aggregate domoticz and fhem in one node red application
please advise
best regards

bend94

i did a little test
i did

FHEM> define MQTT2 MQTT2_SERVER 1884 192.168.0.6

now i can do a notification

FHEM> set MQTT2 publish fhem/fhem toto

i receive the msg in nodered

But how to inform all my sensors to send to MQTT2 ?

Thx



rudolfkoenig

Either create a notify like
define f2m notify .* set MQTT2 publish $NAME $EVENTor use the MQTT_GENERIC_BRIDGE module.

bend94

many thanks !!!!!
It is working now

Very good !!!!!

bend94

#11
just one last question:
Now, if i want to do the reverse ?

sending a command from nodered to FHEM like : set Prise on

i receive in FHEM something like :
MQTT2_SERVER MQTT2 publish fhem/fhem MQTT2_mqtt_d8bf1a3b.fd4288 _: set Prise on
MQTT2_DEVICE MQTT2_mqtt_d8bf1a3b.fd4288 _: set Prise on


but the sensor do not activate and deactivate ?

best regards

rudolfkoenig

You can set the rawEvents attribute in MQTT2_SERVER, and create matching notifies forsetting the desired device, the Event-Monitor is your friend here.
Or use MQTT_GENERIC_BRIDGE, which was created exactly for this purpose.

bend94

sorry again, it is not easy stuff

now i create :
defmod mqttGeneric MQTT_GENERIC_BRIDGE

it looks like this

fhem> list mqttGeneric
Internals:
   CFGFN
   FUUID      5d0b7f88-f33f-0be6-6c2b-efb7b66eed73a43d
   IODev      MQTT2
   NAME       mqttGeneric
   NR         216
   NTFY_ORDER 50-mqttGeneric
   STATE      ? ? ?
   TYPE       MQTT_GENERIC_BRIDGE
   devspec    .*
   prefix     mqtt
   READINGS:
     2019-06-20 15:03:39   device-count    1
     2019-06-20 14:43:52   incoming-count  0
     2019-06-20 14:43:52   outgoing-count  0
     2019-06-20 15:03:39   transmission-state IO device initialized (mqtt2)
     2019-06-20 14:43:52   updated-reading-count 0
     2019-06-20 14:43:52   updated-set-count 0
   devices:
     TCM_ESP3_1:
       :subscribe:
   globalDeviceExcludes:
   globalReadingExcludes:
   globalTypeExcludes:
     pub:
       FHEMWEB    *
       Global     *
       MQTT       transmission-state
       MQTT_BRIDGE transmission-state
       MQTT_DEVICE transmission-state
       MQTT_GENERIC_BRIDGE *
       telnet     *
     sub:
       FHEMWEB    *
       Global     *
       MQTT       transmission-state
       MQTT_BRIDGE transmission-state
       MQTT_DEVICE transmission-state
       MQTT_GENERIC_BRIDGE *
       telnet     *
Attributes:

and now ?

rudolfkoenig

So it was not your last question after all :)
I am not the MQTT_GENERIC_BRIDGE maintainer, nor am I using it.
A first look at the documentation (https://fhem.de/commandref_modular.html#MQTT_GENERIC_BRIDGE) reveals a lot of examples, which I suppose you did nor read yet.
If you still have questions after reading it, open a new forum-entry with MQTT_GENERIC_BRIDGE in the subject