How to publish command for FHEM

Begonnen von fl1p, 02 April 2021, 20:13:55

Vorheriges Thema - Nächstes Thema

fl1p

Hi!
I tried a lot of things, but I can't get FHEM to execute a command I sent trough MQTT (from Loxone, to Loxberry MQTT gateway). I can send it from Loxone to the MQTT gateway, where the command received is:
OK: UDP IN: Miniserver (192.168.1.10): /fhem/cmd set velux_0 pct 50
Publishing: '/fhem/cmd'='set velux_0 pct 50'

That code (set velux_0 pct 50) works perfectly when I manually input it to FHEM, but it doesn't seem to work when it comens from MQTT. What am I doing wrong? Did I forget to install something, and how do I install and configure it then?

I have already the lb_mosquitto installed and the MQTT_generic_bridge. But for the bridge, the state is "???"

rudolfkoenig

Since you didnt mentioned it: is there an MQTT2_CLIENT defined?
For a simple setup you could do with "attr MQTT2_CLIENT rawEvents + notify" instead of the more advanced MQTT_GENERIC_BRIDGE.

fl1p

Yes, I tried that, but it stays disconnected. That's why I did not mention it :)
I can't find how to connect it?

Beta-User

Hi and welcome!

(Just in case the MQTT_GENERIC_BRIDGE  solution is still an option)

Imo the way the FHEM integration to loxone is described in the Loxone Wiki is not really the way one should interact with FHEM in MQTT. We had this topic several times the recent months, unfortunately, there's no final explanation in English available.

Basically, Loxone should send in a more MQTT-like format as follows:
fhem/set/velux_0/pct 50
Then, you have to configure the target device (velux_0) with options provided by MQTT_GENERIC_BRIDGE to react on that command. Perhaps this is a good introduction: https://forum.fhem.de/index.php/topic,115279.0.html
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

fl1p

Thanks for the help already!

Is this a good start in attachment?

Beta-User

Imo clearly not:
- set different $base for subscribe and publish (suggestion: use the attrTemplate for the MGB itself)
- delete globalPublish, use MQTT-attributes provided by MGB only on the desired devices instead.
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

fl1p

The only part I fully understood is delete the globalPublish :p
What is MGB? Where do I find the attributes? Is it like (example found in another topic): switch:
  - platform: mqtt
    name: demoswitch
    command_topic: "fhem/demoswitch/set"
    state_topic: "fhem/demoswitch/state"
    payload_on: "on"
    payload_off: "off"
    state_on: "on"
    state_off: "off"
    #availability_topic: "fhem/connection/status"
    #payload_available: "connected"
    #payload_not_available: "disconnected"

Beta-User

MGB is short for MQTT_GENERIC_BRIDGE, and we are only talking about attributes in FHEM. MGB provides additional options to "normal" FHEM devices, so you have to configure additional settings to e.g. velux_0 (see MGB commandref)
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

fl1p

I just read the commandref for the MGB.
I think I need mqttSubscribe, but I'm not sure, and how to configure that...

For example, I have the velux_0 topic (am I right with the name "topic"?) where I can set the attribute pct (percent) to let's say 50, so the window would be half open.

In the MQTT gateway (on loxberry), I can see the attribute as follow:
fhemforloxberry/velux_0/pct=100
So... Help me :p I'm (still) a noob in FHEM.

Beta-User

First: attributes and readings are different categories in FHEM.

Then I'd recommend to not immediately try to also make the bridgeing to loxone but first inspect  the MQTT traffic itself  Use a toolset like mosquitto-clients for that (mosquitto_sub (and mosquitto_pub for test-publishing)) to get an impression how the data has to be formatted properly.

Last, FHEM has to be up to date.
If that's the case, there should "set attrTemplate" be available on the MGB itself. Use "base_settings_to..." to configure the MGB to send and receive to different $base topics. You may addopt the result to your needs, but make sure, sub and pub arguments are different.

The attributes on the target device itself then should be set. Unfortunately, I don't hav no Velux TYPE device, this is appropriate to CUL_HM:
attr Rollladen_WZ_SSW mqttPublish state:topic={"$base/$device"} pct|motor:topic={"$base/$device/$name"} motor:expression={$value=~m,([^:]+)?,?$1:undef}
attr Rollladen_WZ_SSW mqttSubscribe state:stopic={"$base/$device"} pct:stopic={"$base/$device/$name"}
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