Which FHEM commands for MQTT2_CLIENT and Home Assistant (FIXED)

Begonnen von Christian1, 31 Mai 2020, 16:54:49

Vorheriges Thema - Nächstes Thema

Christian1

My question posted https://forum.fhem.de/index.php/topic,81098.msg1026806.html#msg1026806 will be more consistent in this channel I think (sorry about that, I just start in FHEM and not accustomed with this forum, but I will improve myself) :

My project is to launch/control my eltako FSB61NP for roller shutters with Home Assistant. For that : 
   1) I have installed MQTT Mosquitto broker from Home Assistant
   2) on FHEM, beta_user explains to me that I should declare MQTT2_CLIENT
   3) I understand that the 2 last things are to declare a cover on configuration.yaml, and an automation on automations.yaml

So, I was wondering :

1) which FHEM commands I need to declare : is it the code bellow ?
define examplemqtt MQTT2_CLIENT 192.168.1.12.cl:9883
define mqttGenBridge MQTT_GENERIC_BRIDGE
attr mqttGenBridge IODev examplemqtt

That's all ? do I need to add this code below ? (but how to fill it exactly ?) I beleive it is useful to make the link with Home Assistant but not sure :-(
attr mqttGenBridge globalDefaults base={{"enocean/$device"}}
attr mqttGenBridge globalPublish *.topic={{"$base/$reading"}}


2) with my device defined below on FHEM, what should I write in Home Assistant ? I have found the code below but I don't know how to make it match with my Eltako actuator device :-(

I think you in advance for your help !

define EnO_switch1_FSB61 EnOcean 05235687
setuuid EnO_switch1_FSB61 5ed2e2c0-f33f-2658-73bb-b4b6e746b02195bc
attr EnO_switch1_FSB61 IODev TCM310_0
attr EnO_switch1_FSB61 eep A5-3F-7F
attr EnO_switch1_FSB61 manufID 00D
attr EnO_switch1_FSB61 model Eltako_FSB61
attr EnO_switch1_FSB61 room EnOcean
attr EnO_switch1_FSB61 subType manufProfile
attr EnO_switch1_FSB61 webCmd opens:stop:closes
define FileLog_EnO_switch1_FSB61 FileLog ./log/EnO_switch1_FSB61-%Y.log EnO_switch1_FSB61
setuuid FileLog_EnO_switch1_FSB61 5ed2e2c0-f33f-2658-c8dd-01dd1c5e4b2c77c0
attr FileLog_EnO_switch1_FSB61 logtype text
attr FileLog_EnO_switch1_FSB61 room EnOcean


Home Assistant command found on the web :
cover:
  - platform: mqtt
    name: "MQTT Cover"
    command_topic: "home-assistant/cover/set"
    state_topic: "home-assistant/cover/state"
    availability_topic: "home-assistant/cover/availability"
    qos: 0
    retain: true
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STOP"
    state_open: "open"
    state_opening: "opening"
    state_closed: "closed"
    state_closing: "closing"
    payload_available: "online"
    payload_not_available: "offline"
    optimistic: false
    value_template: '{{ value.x }}'


Beta-User

You should first have a look at the FHEM-MQTT part. Means: try to steer your blinds via MQTT publishes from a simple toolset like mosquitto_pub. If that works, you can adjust also the HomeAssistant part (or change topic structures to the needs of that software.

In FHEM, after having defined MQTT2_CLIENT and MQTT_GENERIC_BRIDGE, there are additional attributes available on _each other_ device. So first add the MQTT info to EnO_switch1_FSB61.

See especially examples in https://fhem.de/commandref_modular.html#MQTT_GENERIC_BRIDGE referring to "stopic". This is where the commands to the devices will be expected.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

Christian1

#2
Ok, reading the instructions and you answer, if I understand I intend to type at right the the "+" Icon (at the top of the fhem webpage snapshot enclosed) these 3 lines :

define examplemqtt MQTT2_CLIENT 192.168.1.32:1883
defmod mqttGeneric MQTT_GENERIC_BRIDGE
attr mqttGeneric IODev exeample mqtt

Am I right ?

Then I intend to write in fhem.cfg the code bellow, but to be honest I am lost in the explanations of this documentation on mqttPublish/stopic :-(
attr mqttGeneric mqttDefaults base={"EnOcean/$device"}
attr EnO_switch1_FSB61 mqttPublish state:topic={"EnOcean/EnO_switch1-FSB61/set"}
attr EnO_switch1_FSB61 mqttSubscribe state:topic={"EnOcean/En0_switch1-FSB61/state"}


Afterward, I will intend to write  the code bellow on a ssh for test, but pratically sure it won't be good ?
mosquitto_pub -h 192.168.1.32 -t /EnOcean/EnO_switch1_FSB61/set -m "closes"

Beta-User

Yes, these commands are ment to be passed through commandline - either one by one or together via the extended multiline version accessibel through "+" or "RAW Definition" at the end of each detail page. (Below your screenshot. Btw.: better do _not_ post screenshots, use copied text instead: in MQTT I personally prefer "RAW" code, as it is easier to copy to test systems, in general it's recommended to use "list" output of the devices).

FHEM is case-sensitive and a single blank can make a big difference. Means: your third line will cause trouble.

The three additional lines to the device should be slightly different too (afaik, I'm not using MQTT_GENERIC_BRIDGE and only did some testing on it in the past):
attr EnO_switch1_FSB61 mqttPublish state:topic={"EnOcean/EnO_switch1-FSB61/state"}
attr EnO_switch1_FSB61 mqttSubscribe state:stopic={"EnOcean/En0_switch1-FSB61/set"}

"publish" means: use this topic for changes comming from within FHEM, "subscribe" means: listen at this branch for incomming commands; so using a branch ending with "/set" is closer to usual use of that type of naming.

Some additional remarks:
Better start with a simple setup, so using the defaults for parts of the topic tree - both in MQTT_GENERIC_BRIDGE and the devices - might easen the process for multiple devices, but you only intend to go for two.
I noticed some questions wrt. to authenification@MQTT in yesterday's version of your post. This might be handled by an additional device TYPE=allowed. See commandref for details.

Most likely you didn't notice, there are at least some basic instructions on general FHEM (and forum) usage available in english as well. So you might read the pinned Thread in the english corner and the https://wiki.fhem.de/wiki/Quick-Start/en as well. And last not least, commandref also contains the most recent description of all modules and basics. For a better revelation of the basic structure, I recommend switching to the "modular" variant:
attr global commandref modular or https://fhem.de/commandref_modular.htm
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

Christian1

Thank you very much Beta-user for your help and your time !
When I write define examplemqtt MQTT2_CLIENT 192.168.1.32:1883 I see this message in the logfile 2020.06.01 10:00:27 3: Opening examplemqtt device 192.168.1.32:1883
2020.06.01 10:00:27 3: examplemqtt device opened
2020.06.01 10:00:27 1: examplemqtt: Connection refused, not authorized
2020.06.01 10:00:27 1: 192.168.1.32:1883 disconnected, waiting to reappear (examplemqtt)
And when I write defmod mqttGeneric MQTT_GENERIC_BRIDGE The FHEM's answer is Cannot load module MQTT_GENERIC_BRIDGE even if I add TYPE=allowed for the 2 commands
I understand from the research on https://wiki.fhem.de/wiki/Quick-Start/en that it is probably because I don't have given allowed access (please see my fhem.cfg below). For that, do I need to write these 2 commands before going back to my MQTT commands ?
define allowedWEB allowed
define allowedTelnet allowed

Do I need also to type the code below ? and for that do I need to generate a certificate ? (I don't understand in the quick start if certificate was necessary and where to put it exactly :-( )
attr WEB HTTPS

Thank you again for your precious help in my learning period !

Extract of my fhem.cfg could help you to check what is missing.
attr global userattr cmdIcon devStateIcon:textField-long devStateStyle icon sortby webCmd webCmdLabel:textField-long widgetOverride
attr global autoload_undefined_devices 1
attr global autosave 0
attr global logfile ./log/fhem-%Y-%m.log
attr global modpath .
attr global motd
attr global statefile ./log/fhem.save
attr global verbose 3

define WEB FHEMWEB 8083 global
setuuid WEB 5ed28597-f33f-2658-c822-0471a4e2f770c9a8

# Fake FileLog entry, to access the fhem log from FHEMWEB
define Logfile FileLog ./log/fhem-%Y-%m.log fakelog
setuuid Logfile 5ed28597-f33f-2658-06ce-d39999a7a3aff50f

define autocreate autocreate
setuuid autocreate 5ed28597-f33f-2658-a929-ba19004319ce8503
attr autocreate filelog ./log/%NAME-%Y.log

define eventTypes eventTypes ./log/eventTypes.txt
setuuid eventTypes 5ed28597-f33f-2658-5d7c-32ccf23e3799491e

# Disable this to avoid looking for new USB devices on startup
# define initialUsbCheck notify global:INITIALIZED usb create
define TCM310_0 TCM 310 /dev/ttyS0@57600
setuuid TCM310_0 5ed28597-f33f-2658-614a-794cfd6b43950beb
attr TCM310_0 sendInterval 0
attr TCM310_0 smartAckMailboxMax 0
define EnO_002B422B EnOcean 002B422B
setuuid EnO_002B422B 5ed28608-f33f-2658-e723-a374fceddc2ee87c
attr EnO_002B422B IODev TCM310_0
attr EnO_002B422B eep F6-02-01
attr EnO_002B422B manufID 7FF

Beta-User

First of all: Sorry for pointing to allowed. This is only usefull for server services like MQTT2_SERVER (or telnet- or FHEMWEB-TYPE of FHEM-modules) , for MQTT2_CLIENT there are some attributes and a setter command to store info about (mosquitto) server credentials, pls. have a look at commandref section for MQTT2_CLIENT.

Wrt. to MQTT_GENERIC_BRIDGE, you'll need one additional Perl module (e.g. via apt-get or cpan, dependent on your OS. For Debian-based OS, it's (sudo) apt-get install libmodule-pluggable-perl, see https://wiki.fhem.de/wiki/MQTT#MQTT_GENERIC_BRIDGE for further details.

In general, you should get yourself an idea, what a "define" does (or a "defmod" = "define" or "modify") and what I'm talking about when speaking about "TYPE" (see Internals of the items you already defined). Also the "devspec" part of commandref might be useful for you now (https://fhem.de/commandref_modular.html#devspec).
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

Christian1

#6
No problem Beta-user, it is already kind of you to help me.
Unfortunately, even after reading/and trying to understand your links, after installing libmodule-pluggable-perl without error (just the last line writing "Processing of deferred actions ("triggers") for man-db (2.8.5-2) ...." do I need to make Something ?)

So after reading and installing this perl module, I launch again my 2 lines
define examplemqtt MQTT2_CLIENT 192.168.1.32:1883
defmod mqttGeneric MQTT_GENERIC_BRIDGE

and I so these logfiles :-(
2020.06.01 18:27:10 3: Opening examplemqtt device 192.168.1.32:1883
2020.06.01 18:27:10 3: examplemqtt device opened
2020.06.01 18:27:10 1: examplemqtt: Connection refused, not authorized
2020.06.01 18:27:10 1: 192.168.1.32:1883 disconnected, waiting to reappear (examplemqtt)
2020.06.01 18:27:55 3: Opening examplemqtt device 192.168.1.32:1883
2020.06.01 18:27:55 3: examplemqtt device opened
2020.06.01 18:27:55 1: examplemqtt: Connection refused, not authorized
2020.06.01 18:27:55 1: 192.168.1.32:1883 disconnected, waiting to reappear (examplemqtt)
2020.06.01 18:28:49 1: reload: Error:Modul 00_MQTT deactivated:
Attempt to reload Net/MQTT/Message.pm aborted.
Compilation failed in require at ./FHEM/00_MQTT.pm line 80.
BEGIN failed--compilation aborted at ./FHEM/00_MQTT.pm line 80.

2020.06.01 18:28:49 0: Attempt to reload Net/MQTT/Message.pm aborted.
Compilation failed in require at ./FHEM/00_MQTT.pm line 80.
BEGIN failed--compilation aborted at ./FHEM/00_MQTT.pm line 80.

2020.06.01 18:28:49 1: reload: Error:Modul 10_MQTT_GENERIC_BRIDGE deactivated:
Can't continue after import errors at ./FHEM/10_MQTT_GENERIC_BRIDGE.pm line 456.
BEGIN failed--compilation aborted at ./FHEM/10_MQTT_GENERIC_BRIDGE.pm line 495.

2020.06.01 18:28:49 0: Can't continue after import errors at ./FHEM/10_MQTT_GENERIC_BRIDGE.pm line 456.
BEGIN failed--compilation aborted at ./FHEM/10_MQTT_GENERIC_BRIDGE.pm line 495.


Do you think it could be a problem of port (I have made a redirection 1883 > 1883) ? or ssl or https access ?
Isn't there any "standard" configuration/pre-requisite before launching a MQTT_CLIENT and MQTT_GENERIC_BRIDGE ?

I don't know how to progress ? :-(

Beta-User

Installation of libmodule-pluggable-perl seems to be ok.

Wrt. to MQTT2_CLIENT: "not authorized" imo means you didn't set suitable credentials. Pls. have a look at commandref how to do that. You should not get "disconnect" messages in FHEM logfile.

MQTT_GENERIC_BRIDGE originally has been developed for use with "00_MQTT.pm" as IO module, so that has to bee loaded in the background - so all dependencies of that module have to be satisfied, too. As Message.pm is delievered with the FHEM Debian package, this should work, but to be honest, I don't have any real idea, what went wrong (line 79 contains a second, similar prerequisite that seems to work flawlessly).
So what's the output of (Linux command line):
ls -l /opt/fhem/FHEM/lib/Net/MQTT
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

Christian1

Hello Beta-user

MQTT2_CLIENT:
I have added these code lines directly by editing the fhem.cfg (at the end of the file)
define allowedWEB allowed
attr allowedWEB validFor WEB,WEBphone,WEBtablet
attr allowedWEB basicAuth { "myuser:mypassword" }
attr allowedWEB allowedCommands set,get
define allowedTelnet allowed
attr allowedTelnet validFor telnetPort
attr allowedTelnet password secret

I have also added
"attr WEB editConfig 1"
then writing the code "bedefine examplemqtt MQTT2_CLIENT 192.168.1.32:1883" low the answer is "Forbidden command define" :-( in fact I realize that it refuses all my commands. I am probably not very far away, but it seems that 1 additionnal command line is missing, no ? do you need my global fhem.cfg to see what could miss ?

The logfile is
2020.06.03 00:17:14 1: Including fhem.cfg
2020.06.03 00:17:15 3: WEB: port 8083 opened
2020.06.03 00:17:15 2: eventTypes: loaded 48 events from ./log/eventTypes.txt
2020.06.03 00:17:15 3: Opening TCM310_0 device /dev/ttyS0
2020.06.03 00:17:15 3: Setting TCM310_0 serial parameters to 57600,8,N,1
2020.06.03 00:17:15 3: TCM310_0 device opened
2020.06.03 00:17:16 2: EnOcean Cryptographic functions available.
2020.06.03 00:17:16 2: EnOcean XML functions available.
2020.06.03 00:17:16 1: Including ./log/fhem.save
2020.06.03 00:17:16 3: TCM TCM310_0 set reset
2020.06.03 00:17:16 2: TCM TCM310_0 RESPONSE: OK
2020.06.03 00:17:17 3: TCM TCM310_0 get baseID
2020.06.03 00:17:17 2: TCM TCM310_0 RESPONSE: BaseID: FFA5E400 RemainingWriteCycles: 0A
2020.06.03 00:17:17 3: TCM TCM310_0 get version
2020.06.03 00:17:17 2: TCM TCM310_0 RESPONSE: APIVersion: 02060900 APPVersion: 020F0000 ChipID: 058A4BC8 ChipVersion: 454F0103 Desc: GATEWAYCTRL
2020.06.03 00:17:17 3: TCM TCM310_0 set repeater 0000
2020.06.03 00:17:17 2: TCM TCM310_0 RESPONSE: OK
2020.06.03 00:17:17 2: TCM TCM310_0 repeater 0000 restored
2020.06.03 00:17:17 3: TCM TCM310_0 set smartAckMailboxMax 0
2020.06.03 00:17:17 2: TCM TCM310_0 RESPONSE: OK
2020.06.03 00:17:17 2: TCM TCM310_0 smartAckMailboxMax 0 restored
2020.06.03 00:17:17 3: TCM TCM310_0 set mode 00
2020.06.03 00:17:17 2: TCM TCM310_0 RESPONSE: NOT_SUPPORTED
2020.06.03 00:17:17 3: TCM TCM310_0 set maturity 01
2020.06.03 00:17:17 2: TCM TCM310_0 RESPONSE: OK
2020.06.03 00:17:17 2: TCM TCM310_0 maturity 01 restored
2020.06.03 00:17:17 2: TCM TCM310_0 initialized
2020.06.03 00:17:17 0: Featurelevel: 6
2020.06.03 00:17:17 0: Server started with 16 defined entities (fhem.pl:21056/2020-01-26 perl:5.028001 os:linux user:fhem pid:510)
2020.06.03 00:19:04 2: AttrTemplates: got 127 entries
2020.06.03 00:19:21 3: Forbidden command define for WEB_192.168.1.32_56694
2020.06.03 00:19:21 1: stacktrace:
2020.06.03 00:19:21 1:     main::allowed_Authorize             called by fhem.pl (3763)
2020.06.03 00:19:21 1:     main::CallFn                        called by fhem.pl (5582)
2020.06.03 00:19:21 1:     main::Authorized                    called by fhem.pl (1233)
2020.06.03 00:19:21 1:     main::AnalyzeCommand                called by fhem.pl (1098)
2020.06.03 00:19:21 1:     main::AnalyzeCommandChain           called by ./FHEM/01_FHEMWEB.pm (2688)
2020.06.03 00:19:21 1:     main::FW_fC                         called by ./FHEM/01_FHEMWEB.pm (957)
2020.06.03 00:19:21 1:     main::FW_answerCall                 called by ./FHEM/01_FHEMWEB.pm (583)
2020.06.03 00:19:21 1:     main::FW_Read                       called by fhem.pl (3763)
2020.06.03 00:19:21 1:     main::CallFn                        called by fhem.pl (755)


MQTT_GENERIC_BRIDGE
even if I have not succeeded to define MQTT_GENERIC_BRIDGE the command line ls -l /opt/fhem/FHEM/lib/Net/MQTT shows me that results
total 24
-rw-rw-rw- 1 fhem dialout 6307 janv. 26 14:14 Constants.pm
drwxrwxrwx 2 fhem dialout 4096 mai   30 18:10 Message
-rw-rw-rw- 1 fhem dialout 5874 janv. 26 14:14 Message.pm
-rw-rw-rw- 1 fhem dialout 2264 janv. 26 14:14 TopicStore.pm


I thank you again for your help






Beta-User

Zitat von: Christian1 am 03 Juni 2020, 00:33:28
MQTT2_CLIENT:
I have added these code lines directly by editing the fhem.cfg (at the end of the file)
Two remarks:
- (besides some very rare emergency cases) NEVER edit the fhem.cfg directly, always use FHEMWEB options instead (see "RAW" code editing here: https://wiki.fhem.de/wiki/Import_von_Code_Snippets)
- as already mentionned, I was wrong when pointing to "allowed" in MQTT2_CLIENT context. For this interface module, there are other credential configuration options available, see the last three Attributes in the section before "Perl specials" here: https://fhem.de/commandref_modular.html#MQTT2_CLIENT
Zitattotal 24
-rw-rw-rw- 1 fhem dialout 6307 janv. 26 14:14 Constants.pm
drwxrwxrwx 2 fhem dialout 4096 mai   30 18:10 Message
-rw-rw-rw- 1 fhem dialout 5874 janv. 26 14:14 Message.pm
-rw-rw-rw- 1 fhem dialout 2264 janv. 26 14:14 TopicStore.pm

The rights themselves and especially the timestamp of the Message folder imo is suspicious. In my installation, it's identical to the others, but more restricted...usr@machine:/opt/fhem/FHEM/lib/Net/MQTT$ ls -l
insgesamt 24
-rw-r--r-- 1 fhem dialout 6307 Jul 30  2019 Constants.pm
drwxr-xr-x 2 fhem dialout 4096 Jul 30  2019 Message
-rw-r--r-- 1 fhem dialout 5874 Jul 30  2019 Message.pm
-rw-r--r-- 1 fhem dialout 2264 Jul 30  2019 TopicStore.pm
usr@machine:/opt/fhem/FHEM/lib/Net/MQTT/Message$ ls -l
insgesamt 64
-rw-r--r-- 1 fhem dialout 2025 Jul 30  2019 ConnAck.pm
-rw-r--r-- 1 fhem dialout 6218 Jul 30  2019 Connect.pm
-rw-r--r-- 1 fhem dialout  960 Jul 30  2019 Disconnect.pm
-rw-r--r-- 1 fhem dialout 1520 Jul 30  2019 JustMessageId.pm
-rw-r--r-- 1 fhem dialout  931 Jul 30  2019 PingReq.pm
-rw-r--r-- 1 fhem dialout  937 Jul 30  2019 PingResp.pm
-rw-r--r-- 1 fhem dialout 1102 Jul 30  2019 PubAck.pm
-rw-r--r-- 1 fhem dialout 1093 Jul 30  2019 PubComp.pm
-rw-r--r-- 1 fhem dialout 1996 Jul 30  2019 Publish.pm
-rw-r--r-- 1 fhem dialout 1088 Jul 30  2019 PubRec.pm
-rw-r--r-- 1 fhem dialout 1133 Jul 30  2019 PubRel.pm
-rw-r--r-- 1 fhem dialout 1962 Jul 30  2019 SubAck.pm
-rw-r--r-- 1 fhem dialout 2223 Jul 30  2019 Subscribe.pm
-rw-r--r-- 1 fhem dialout 1121 Jul 30  2019 UnsubAck.pm
-rw-r--r-- 1 fhem dialout 1966 Jul 30  2019 Unsubscribe.pm
Most likely Message.pm requires loading files from that subdirectory also, so make sure, they are also accessible and check their integrity.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

Christian1

Hello Beta-user,

1- So after reading your recommandation, I have decided to re-install FHEM, and have tried to be as "proper" as possible using only the command line available at the top of the web page.
My code lines were :

attr WEB editConfig 1
define allowedWEB allowed
attr allowedWEB validFor WEB,WEBphone,WEBtablet
attr allowedWEB basicAuth { "myuser:mypassword" }

define allowedTelnet allowed
attr allowedTelnet validFor telnetPort
attr allowedTelnet password secret

define examplemqtt MQTT2_CLIENT 192.168.1.32:1883
attr examplemqtt SSL
attr examplemqtt sslargs
attr examplemqtt username myusername
set examplemqtt password mypassword value

defmod mqttGeneric MQTT_GENERIC_BRIDGE
attr mqttGeneric IODev examplemqtt


It is better and better ;-) no error on webpage and no blocking point to save my config but... I see this status and logfile, I think Something is still going wrong, isn't it ?

MQTT2_CLIENT
examplemqtt              disconnected

MQTT_GENERIC_BRIDGE
mqttGeneric                ???


2020.06.03 21:04:32 3: Opening examplemqtt device 192.168.1.32:1883
2020.06.03 21:04:32 3: examplemqtt device opened
2020.06.03 21:04:32 1: examplemqtt: Connection refused, not authorized
2020.06.03 21:04:32 1: 192.168.1.32:1883 disconnected, waiting to reappear (examplemqtt)
2020.06.03 21:15:38 1: PERL WARNING: Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through in regex; marked by <-- HERE in m/^(.*)({ <-- HERE .*})(.*)$/ at ./FHEM/10_MQTT_GENERIC_BRIDGE.pm line 1358.


I have check again MQTT folders and have (except the less restritive rights on Messafe folder) same files than your list :

pi@raspberrypi:~ $ ls -l /opt/fhem/FHEM/lib/Net/MQTT
total 24
-rw-rw-rw- 1 fhem dialout 6307 janv. 26 14:14 Constants.pm
drwxrwxrwx 2 fhem dialout 4096 juin   3 07:38 Message
-rw-rw-rw- 1 fhem dialout 5874 janv. 26 14:14 Message.pm
-rw-rw-rw- 1 fhem dialout 2264 janv. 26 14:14 TopicStore.pm
pi@raspberrypi:~ $ ls -l /opt/fhem/FHEM/lib/Net/MQTT/Message
total 64
-rw-rw-rw- 1 fhem dialout 2025 janv. 26 14:14 ConnAck.pm
-rw-rw-rw- 1 fhem dialout 6218 janv. 26 14:14 Connect.pm
-rw-rw-rw- 1 fhem dialout  960 janv. 26 14:14 Disconnect.pm
-rw-rw-rw- 1 fhem dialout 1520 janv. 26 14:14 JustMessageId.pm
-rw-rw-rw- 1 fhem dialout  931 janv. 26 14:14 PingReq.pm
-rw-rw-rw- 1 fhem dialout  937 janv. 26 14:14 PingResp.pm
-rw-rw-rw- 1 fhem dialout 1102 janv. 26 14:14 PubAck.pm
-rw-rw-rw- 1 fhem dialout 1093 janv. 26 14:14 PubComp.pm
-rw-rw-rw- 1 fhem dialout 1996 janv. 26 14:14 Publish.pm
-rw-rw-rw- 1 fhem dialout 1088 janv. 26 14:14 PubRec.pm
-rw-rw-rw- 1 fhem dialout 1133 janv. 26 14:14 PubRel.pm
-rw-rw-rw- 1 fhem dialout 1962 janv. 26 14:14 SubAck.pm
-rw-rw-rw- 1 fhem dialout 2223 janv. 26 14:14 Subscribe.pm
-rw-rw-rw- 1 fhem dialout 1121 janv. 26 14:14 UnsubAck.pm
-rw-rw-rw- 1 fhem dialout 1966 janv. 26 14:14 Unsubscribe.pm


2- Eventually I have thought about another possibility maybe to send a command from Home Assistant to FHEM (for opening roller shutters) : isn't there any possibility of http executable command such as "http://192.168.1.32:8083/fhem?cmd=set EnO_switch1_FSB61 closes" ?
I have tested it doesn't work, but maybe some configurations have to be done ?.

3- I have found another things about restAPI but I don't know in which it consists ? seems as complex as MQTT ;-)



Beta-User

Zitat von: Beta-User am 03 Juni 2020, 05:51:16
- (besides some very rare emergency cases) NEVER edit the fhem.cfg directly, always use FHEMWEB options instead (see "RAW" code editing here: https://wiki.fhem.de/wiki/Import_von_Code_Snippets)
Why are you ignoring this very essential recommendation?

Really: Imo the "disconnected" state of your IO devices is a direct consequece of you tryning to use fhem.cfg as input mode for code meant to be entered in commandline, especially the "set" command for password.

Just use the "green plus" for entering all commands and give up editig fhem.cfg! It is neither necessary nor recommended!
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

Christian1

I am sorry Beta-user I didn't catch this recommandation; all these configurations are not easy for me even after reading all the recommanded documentations.

Now, after re-installing , and configuring using only "+", I have :

- no MQTT error in the logfile, only this warning :
2020.06.05 16:07:26 1: PERL WARNING: Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through in regex; marked by <-- HERE in m/^(.*)({ <-- HERE .*})(.*)$/ at ./FHEM/10_MQTT_GENERIC_BRIDGE.pm line 1358, <$fh> line 46.


- what seems to be positive is these publications when I switch from "closes" to "stop" (in the log file)
2020.06.05 22:31:39 3: EnOcean set EnO_switch1_FSB61 closed
2020.06.05 22:31:39 5: MQTT_GENERIC_BRIDGE:DEBUG:> [mqttGeneric] publish: enocean/EnO_switch1_FSB61/state => down (qos: 0, retain: 0)
2020.06.05 22:31:40 5: MQTT_GENERIC_BRIDGE:DEBUG:> [mqttGeneric] publish: enocean/EnO_switch1_FSB61/state => stop (qos: 0, retain: 0)
2020.06.05 22:31:40 3: EnOcean set EnO_switch1_FSB61 stop


- But I don't see any message from FHEM in a MQTT.Fx software installed on a PC, which detects my messages from Home Assistant (HA and Mosquitto are installed on a docker on Rpi but I have checked that the 1883, 1884, 8883 and 8884 are exposed by docker) and from mosquitto_pub. I don't know what's going wrong : maybe the "???" of STATE of mqttGeneric ? :-(

- these are the attibutes of my switch (actuator Eltako) :

Attributes
IODev             TCM310_0                                                                     deleteattr
comMode         confirm                                                                        deleteattr
eep                  A5-3F-7F                                                                     deleteattr
manufID          00D                                                                              deleteattr
model              Eltako_FSB61                                                               deleteattr
mqttDefaults    base={"/enocean/EnO_switch1_FSB61"}                        deleteattr
mqttPublish      state:topic={"enocean/EnO_switch1_FSB61/state"}         deleteattr
mqttSubscribe  state:stopic={"enocean/EnO_switch1_FSB61/set"}          deleteattr
room               EnOcean                                                                       deleteattr
subDef            FFA5E401                                                                      deleteattr
subType          manufProfile                                                                  deleteattr
webCmd         opens:stop:closes                                                           deleteattr


- and the Internals and attributes of mqttexample and mqttGeneric:
Internals
DEF                192.168.1.32:1883
DeviceName     192.168.1.32:1883
FUUID              5ed81673-f33f-2658-365c-1aa59406f5de470a
NAME               examplemqtt
NEXT_OPEN      1591399027
NR                   18
PARTIAL
SSL                  1
STATE              disconnected
TYPE                MQTT2_CLIENT
clientId            examplemqtt
connecting       1
nextOpenDelay 5

Attributes
SSL                  1                                            deleteattr
sslargs              1                                           deleteattr
subscriptions     #                                           deleteattr
username          Christian1                              deleteattr

Internals
FUUID               5ed817b2-f33f-2658-54e5-b261b1a54cd1178f
IODev               examplemqtt
NAME                mqttGeneric
NR                    19
NTFY_ORDER     50-mqttGeneric
STATE               ???
TYPE                 MQTT_GENERIC_BRIDGE
devspec             .*
prefix                mqtt

Attributes
IODev              examplemqtt                        deleteattr
verbose            5                                         deleteattr



Beta-User

...getting into FHEM isn't easy, and you didn't choose the easiest setup to start with...

First: Do an update. There had been some changes to underlaying infrastructure modules that may have some impact to your setup (especially when using update the last two days, prior than 8:00 o'clock this morning).

Then: When MQTT2_CLIENT states "disconnected", there will be no traffic at all from and to your mosquitto. So first fix that. That seems to be some problem that might either be related to misunderstandings in how to configure that or some deeper issue related to the specific way you secured mosquitto.

In latter case, Rudi has to have a look at that, but will neen some more info about
- verbose 5 log entries related to MQTT2_CLIENT (so change related attribute at examplemqtt);
- credential settings on mosquitto side
Not sure, if he is aware of that thread, as it has been moved from somewhere else, so he isn't notified. So best way (after double-checking by yourself) would be to open up a new post with title like: "MQTT2_CLIENT+mosquitto: how to secure using ssl?" (you seem to use ssl? Or even provide more detailed info), add list of the MQTT2_CLIENT and the relevant log excerpt (e.g. after issuing a set ... password command).
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

Christian1

Hello Beta-user,

Trying to solve some "https: ... error" I have tried to suppress the attributes SSL and sslard of examplemqtt, and ... that works !! discussion between HA and FHEM works well, roller shutters controled !! :-)

I thank you again very much for your time, patience and persistence !

I will check carefully if my different attempts to configure that still cause some issues into the log... in order to have a more "clean" configuration :-)

Christian