Autor Thema: Using Fhem via MQTT  (Gelesen 7908 mal)

Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Using Fhem via MQTT
« am: 11 November 2014, 14:40:42 »
Hello,
I would like to use Fhem via MQTT, so I installed the required modules. By the way here is a short description of what need to be done, after having updated fhem.
First download net-mqtt wich is required to run MQTT and MQTTBridge modules.
Unpack it in a directory, do to it with your terminal and do :
perl Makefile.PL
make
make test
make install

Ok then restart fhem, MQTT modules should load.

Here is my question now, I entered the following lines at the end of fhem.cfg :
define localMQTT MQTT 127.0.0.1:1883
define button_Salon MQTT_BRIDGE EnO_switch_002842C2
attr button_Salon IODev localMQTT

and I get a mosquitto server running on the Raspberry (wich of course also runb fhem). When I press the switch, I get no notification. I used clients on Android and windows to publish and subscribe. When I publish from one of these clients, others received the message (they all listen to #) but when I press the button nothing happen (I see the logs in the fhem webpage so fhem is aware that the switch was perssed/released).

Did I misconfigured something ?

Offline ntruchsess

  • Developer
  • Hero Member
  • ****
  • Beiträge: 1123
    • My code on github...
Antw:Using Fhem via MQTT
« Antwort #1 am: 11 November 2014, 15:19:36 »
MQTT_BRIDGE needs further configuration. You have to specify which reading is going to be published to what topic (and vice versa). Therefor you might want to add:

attr button_Salon publishState /fhem/button_Salon

to publish EnO_switch_002842C2s state to topic /fhem/button_Salon

you might also use attribute publishReading_<reading> <topic> to publish other readings. Don't know much about EnOcean so I cannot recommend anything special, depends on the reading your EnOthean-device produces.

The way back from mqtt to fhem goes by using the attributes 'subscribeState' and 'subscribeReading_<reading>'

see commandref.html for details.

- Norbert
while (!asleep()) {sheep++};

Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Antw:Using Fhem via MQTT
« Antwort #2 am: 11 November 2014, 16:47:23 »
Hello,
I still get nothing :
define localMQTT MQTT 127.0.0.1:1883
define buttonSalon MQTT_BRIDGE EnO_switch_002842C2
attr buttonSalon IODev localMQTT
attr buttonSalon publishState /fhem/button/EnO_switch_002842C2/State
attr buttonSalon publishReading_buttons /fhem/button/EnO_switch_002842C2/State
attr buttonSalon publishReading_channelA /fhem/button/EnO_switch_002842C2/channelA
attr buttonSalon publishReading_channelB /fhem/button/EnO_switch_002842C2/channelB
attr buttonSalon publishReading_state /fhem/button/EnO_switch_002842C2/state

As you see I also pulish readings changes. Here is the description of the switch :
fhem> list EnO_switch_002842C2
Internals:
   DEF        002842C2
   IODev      TCM310_0
   LASTInputDev TCM310_0
   MSGCNT     58
   NAME       EnO_switch_002842C2
   NOTIFYDEV  global
   NR         35
   NTFY_ORDER 50-EnO_switch_002842C2
   STATE      A0 B0
   TCM310_0_DestinationID FFFFFFFF
   TCM310_0_MSGCNT 58
   TCM310_0_PacketType 1
   TCM310_0_RSSI -77
   TCM310_0_ReceivingQuality good
   TCM310_0_RepeatingCounter 0
   TCM310_0_SubTelNum 5
   TCM310_0_TIME 2014-11-11 15:45:16
   TYPE       EnOcean
   Readings:
     2014-11-11 15:45:16   buttons         released
     2014-11-11 15:45:15   channelA        A0
     2014-11-11 15:45:15   channelB        B0
     2014-11-11 15:45:15   state           A0 B0
Attributes:
   IODev      TCM310_0
   room       EnOcean
   subType    switch


Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Antw:Using Fhem via MQTT
« Antwort #3 am: 11 November 2014, 16:57:04 »
I forgot to say that in the fhem weblog I get :
2014-11-11 15:55:29 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:29 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:29 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:29 EnOcean EnO_switch_002842C2 buttons: pressed
2014-11-11 15:55:29 EnOcean EnO_switch_002842C2 channelB: BI
2014-11-11 15:55:29 EnOcean EnO_switch_002842C2 BI
2014-11-11 15:55:29 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:29 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:29 EnOcean EnO_switch_002842C2 buttons: released
2014-11-11 15:55:29 EnOcean EnO_switch_002842C2 buttons: released
2014-11-11 15:55:48 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:48 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:48 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:48 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:48 EnOcean EnO_switch_002842C2 buttons: pressed
2014-11-11 15:55:48 EnOcean EnO_switch_002842C2 channelA: AI
2014-11-11 15:55:48 EnOcean EnO_switch_002842C2 channelB: BI
2014-11-11 15:55:48 EnOcean EnO_switch_002842C2 AI BI
2014-11-11 15:55:48 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:48 MQTT_BRIDGE buttonSalon transmission-state: outgoing publish sent
2014-11-11 15:55:48 EnOcean EnO_switch_002842C2 buttons: released
2014-11-11 15:55:48 EnOcean EnO_switch_002842C2 buttons: released

Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Antw:Using Fhem via MQTT
« Antwort #4 am: 11 November 2014, 17:01:18 »
My fault :
attr buttonSalon publishReading_state /fhem/button/EnO_switch_002842C2/state[code]
to
attr buttonSalon publishReading_state fhem/button/EnO_switch_002842C2/state[/code]

Offline ntruchsess

  • Developer
  • Hero Member
  • ****
  • Beiträge: 1123
    • My code on github...
Antw:Using Fhem via MQTT
« Antwort #5 am: 11 November 2014, 17:40:36 »
does that mean it works now?
while (!asleep()) {sheep++};

Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Antw:Using Fhem via MQTT
« Antwort #6 am: 11 November 2014, 17:47:33 »
yes, at least for the switch :)
I'm going to test piloting plugs now. ^_^

Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Antw:Using Fhem via MQTT
« Antwort #7 am: 11 November 2014, 17:58:18 »
It also works like a charm for piloting plugs :
define MQTB_EnO_UTE_008770A0 MQTT_BRIDGE EnO_UTE_008770A0
attr MQTB_EnO_UTE_008770A0 IODev localMQTT
attr MQTB_EnO_UTE_008770A0 subscribeSet fhem/plug/EnO_UTE_008770A0/command

then publish with MQTT :
channel : fhem/plug/EnO_UTE_008770A0/command
message : on 0   (or : off 0)

THANKS :)

Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Antw:Using Fhem via MQTT
« Antwort #8 am: 18 November 2014, 09:50:17 »
Hello,
in the case of smart Plugs, I would like to retrieve energy consumption via MQTT. However, the Fhem command to do that is a "get ...." and it does not seem possible to trigger such a command via MQTT. I am wrong? Would it be possible to add such a command ?
In a same vein, would it be possible to trigger more general command (i.e. not associated to a specific device) via MQTT, such as listing all MQTT_devices ?

     Alex.

Offline ntruchsess

  • Developer
  • Hero Member
  • ****
  • Beiträge: 1123
    • My code on github...
Antw:Using Fhem via MQTT
« Antwort #9 am: 23 November 2014, 21:58:31 »
executing a get-command from the mqtt-interface is not supported (yet). I'll take that into account for an update, but have to do some brainstorming about the semantics as mqtt is not designed to do synchronous method calls.

Most devices do put relevant values in state or readings so you most likely don't need to trigger the get-command, but configure that a change to state (or the reading in question) is being published to mqtt whenever it changes. Use attriutes publishState and/or publishReading_<reading> to do that.

- Norbert
« Letzte Änderung: 23 November 2014, 22:04:06 von ntruchsess »
while (!asleep()) {sheep++};

Offline AlxDmr

  • Jr. Member
  • **
  • Beiträge: 59
Antw:Using Fhem via MQTT
« Antwort #10 am: 25 November 2014, 17:45:14 »
I do agree with you,
actually the problem only appear for a very particular case : a specific smart plug for which you have to interrogate to get the consumption. I can understand that it may not be a hot topic.
I guess a workaround for me would be to add a script on Fhem side so that it regularly interrogate the smartplug.

Regards,
    Alex.

Offline ntruchsess

  • Developer
  • Hero Member
  • ****
  • Beiträge: 1123
    • My code on github...
Antw:Using Fhem via MQTT
« Antwort #11 am: 25 November 2014, 18:20:47 »
best would be to change the smart-plug module such that it reports the value in regular intervals.
while (!asleep()) {sheep++};