Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


MQTT Broker implementation


JCM

Recommended Posts

I have a working solution by using a scene to send MQTT commands to a Node-Red HTTP(S) node, which publish it to a MQTT broker, also installed on the RasPi. That way I communicate with several other IoT devices, like the Athom Homey.

Please login or register to see this image.

/monthly_2018_06/654607458_HC2--Node-RedHTTPS--MQTT.png.fcda053a2cf94b81edfed9b9ca3d1092.png" />

 

The problem is, I didn't figured out a way to receive any data from the MQTT broker to the HC2.

 

Does anyone has an idea how to get that accomplished? An encrypted solution should be preferred. If we have to wait for Fibaro it will never be done.

 

If anyone is interested I could post the scene code.

Edited by Lambik
Link to comment
Share on other sites

15 hours ago, Lambik said:

I have a working solution by using a scene to send MQTT commands to a Node-Red HTTP(S) node, which publish it to a MQTT broker, also installed on the RasPi. That way I communicate with several other IoT devices, like the Athom Homey.

Please login or register to see this link.

 

The problem is, I didn't figured out a way to receive any data from the MQTT broker to the HC2.

 

Does anyone has an idea how to get that accomplished? An encrypted solution should be preferred. If we have to wait for Fibaro it will never be done.

 

If anyone is interested I could post the scene code.

wow! please share it!

Link to comment
Share on other sites

  • Topic Author
  • On 6/2/2018 at 3:30 PM, Lambik said:

    I have a working solution by using a scene to send MQTT commands to a Node-Red HTTP(S) node, which publish it to a MQTT broker, also installed on the RasPi. That way I communicate with several other IoT devices, like the Athom Homey.

    Please login or register to see this link.

     

    The problem is, I didn't figured out a way to receive any data from the MQTT broker to the HC2.

     

    Does anyone has an idea how to get that accomplished? An encrypted solution should be preferred. If we have to wait for Fibaro it will never be done.

     

    If anyone is interested I could post the scene code.

     

    Wow! Sounds interesting. It would be great if you shared the code. I am also trying around with Node-RED and mosquitto .. this sounds like a good first step for me with HC2 onto the MQTT stage.. :-)

    Edited by JCM
    Link to comment
    Share on other sites

    Christ, you're so bloody naive!

    Actually, I was going to leave this community ...

    yeah...

    Instead of asking from Fibaro this function, you are trying to find workarounds... 

     

    so, MQTT bridge for 5 mins

     

    1.  pi@rpi:~ $ sudo apt-get install mosquitto-clients
    2. Please login or register to see this code.

      3. 

      Please login or register to see this code.

      4. run

               5. Voila!

     

    Please login or register to see this image.

     

     

    bye!

     

     

    Link to comment
    Share on other sites

    I'm not naive @10der. I used this to gradually dismantle my HC2 configuration, which is large after building it  since 2013. I use it solely as Z-Wave gateway at the moment with some core (own written) lua Virtual Devices. All other is done by other IoT devices/gateway/services.

     

    For @korniza and @JCM hereby my Scene code used:

     

    Please login or register to see this code.

    To get started, make 5 global variables:

    'SC_MQTT_Topic'        -- Name of topic (trigger!)
    'SC_MQTT_VarVal'         -- Value of topic
    'SC_MQTT_Retain'     -- Retain message (true/false)
    'SC_MQTT_QoS'            -- QoS of message (0,1,2)
    'SC_MQTT_VarLog '    -- Logmessage to send

     

    to send MQTT command, write a value to 'SC_MQTT_VarVal' and the Topic to 'SC_MQTT_Topic'. When a string is written to 'SC_MQTT_Topic' the scene is triggered and a API command is constructed which communicates with the Node-Red http(s)-node. The root topic  = 'hc2/mqtt'

     

    If no values are written to 'SC_MQTT_Retain', 'SC_MQTT_QoS' and 'SC_MQTT_VarLog' there will be default values written to them:

    'SC_MQTT_Retain' default value is false, 'SC_MQTT_QoS'  default is 0 and 'SC_MQTT_VarLog'  default is <date> <time> <hc2/mqtt/MQTT-Topic> --> <Mqtt-Value>

     

    In Node-Red all values are stored as 'payload' so you need to move the values with a function node containing (msg.payload --> msg):

    Please login or register to see this code.

    After being moved you can strip the log-content to store to a log-file (msg.log)

    Please login or register to see this image.

    /monthly_2018_06/968946960_StripLogData.png.e8efb2ff347fad2cb91b405559758a7a.png" />

     

    The MQTT data is send to the MQTT-node, containing msg.topic, msg.retain, msg.qos and msg.payload.

     

    The respond is done by constructing msg.payload containing {"status":"OK"} which is send to the http-node output. This will be send to the HC2 scene to confirm the command is received:

    1631672827_RespondwithOK.png.f9e133b3898cbe18fae60a9042270baf.png

     

     

     

    You can watch the Scene debug window to monitor what is happening.

     

    In short, if you want send value TEST to topic /hc2/mqtt/MYTOPIC with QoS=2 and retain=true then you write to HC2 global variables, for example with a VD-button:

    Please login or register to see this code.

    Enjoy!

     

     

     

    Edited by Lambik
    typo
    • Thanks 2
    Link to comment
    Share on other sites

    Now I can control my wemo lamps!! @Lambik you are one of my heros here!

    I already use MQTT to send notifications on Google Home but the code was messy. You provide a general way to bridge what ever I want!

    I think now everyone imagination is the limit!

    Link to comment
    Share on other sites

    @korniza You're welcome! I'm pleased to see my modest contribution suits your needs. ;D

     

    BTW, here is some additional info:

    EDIT: I see you already knew that topic.... :oops:

    Edited by Lambik
    Added a link to another topic containing addditional info
    Link to comment
    Share on other sites

    • 2 weeks later...

    Hereby some modest contribution to the Fibaro forum community. (You absolutely rock!) ;D

     

    When posting variables in a small time range, the scene I posted before could be 'stressed'. To resend values without overflow the MQTT-send scene I wrote a scene to prevent that for being happening.

     

    When the MQTT-send scene is busy, it will wait to become ready again. Also it will not (re)send values when they are the same (optionLastValue = true).

     

    Note: A extra global variable is needed for every monitored global variable, in the example below this is the 'SC_PD2MQTT_LV'.

    Note: I used a logValue = 'NO' to prevent it from being stored in my log file. This is done by my Node-Red flows (red function node):

    1194274704_20180617Node-RedFlowLOGBlock.png.e35107a5c118c94d7e9e7ed88efeac1c.png

    Please login or register to see this code.

     

    In the below example I monitor the

    Please login or register to see this link.

    global variable (VD_PD_Status534) and send the value to the MQTT-send scene. You could change the code in the Custom code-header to your needs (pdValue).

     

    Please login or register to see this code.

     

    Succes!

     

    Some Icons I made...

     

    Enjoy!

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Edited by Lambik
    Link to comment
    Share on other sites

    • 3 weeks later...

    JFYI:

     

    simple MQTT <=HC2=> Bridge based on Node-Red

     

    Please login or register to see this image.

    attach HC2.json

     

    notice: do not forget setup 

    a) address from MQTT server

    b) HC2 basic auth credentials

     

    and simple how to use

     

    aLx8qJBrS7.png

    attach sample.json

     

     

    notice: supported commands:

    true / false  ===> simple turn on / off

    any numeric 0 .. 99 ===> Dimming

    string startwith # ===> RGB

    string startwith $ ===> RGB-white channel dimming.

     

     

     

     

     

     

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    On 7/5/2018 at 8:56 AM, 10der said:

    JFYI:

     

    simple MQTT <=HC2=> Bridge based on Node-Red

     

    Thank you @10der!!

     

    I did some tweaking and testing and this is working like a charm!! Thumbs Up!!

     

    With Androids

    Please login or register to see this link.

    app I now can easily monitor and control the HC2 by MQTT. A nice solution for a wall-mounted tablet!

    Edited by Lambik
    • Thanks 1
    Link to comment
    Share on other sites

    3 hours ago, Lambik said:

    Androids

    Please login or register to see this link.

    app

    Wow! Thank you!

    Link to comment
    Share on other sites

    6 minutes ago, 10der said:

    Wow! Thank you!

    You're very welcome! I'm glad to return a favour to your highly appreciated solution. Keep up the  good work!

    Link to comment
    Share on other sites

    UPD:

     

    Please login or register to see this image.

     

     

    PvZ4M6er1B.png

     

     

    HXv60HOvjj.png

     

    + some minor fixes

    Please login or register to see this attachment.

    Edited by 10der
    • Thanks 1
    Link to comment
    Share on other sites

    UPD V3

     

    1) init action, so now you can get messages on flow start

    2) some minor changes / improvements / optimisations

    3) payload now is "typed" : string / bool / float

     

    bug free :)

     

    example:

     

    U1Qou8ez50.png

     

     

    XMDK4jCTRr.png

    Please login or register to see this attachment.

    Edited by 10der
    • Like 1
    Link to comment
    Share on other sites

    @10der working like a charm. Nice!

     

    Even when you changes HC2 Device (ID), only the device description has to be modified, which is easy to do. Also the devices MQTT path are adjusted. Brilliant!

     

    One question though, is it possible to read/write HC2 global variables?

    Link to comment
    Share on other sites

    draft

     

    get / set global value

     

    so, you can putt to MQTT:

    home/global/GlobalName

    and asp payload = VALUE

     

    and node-red change your global value in HC2

     

     

    Please login or register to see this attachment.

    Please login or register to see this image.

    9YkB0KlI1F.png

    btw. last flow you can save as sub-flow and use.... 

    check this!

     

    Hqfp9c75R3.png

    sub flow

    uDY6MJnB7z.png

     

    and result

     

    Llw2DIlRjJ.png

     

    cool!

     

    • Like 1
    Link to comment
    Share on other sites

    2 hours ago, 10der said:

    cool!

    Indeed! ;D

     

    Just a remark, to write a value to the HC2 global variable you need a HC2 account with administrator privileges. Due to the lack of the HC2 to get/put encrypted API commands, this could be a real vulnerability.....;(

     

    • Like 1
    Link to comment
    Share on other sites

    @Lambik Hi!

     

    now I wrote node-red module... nodejs\node-red-contrib-fibaro-hc2

    and configuration should be very easy.  

    Please login or register to see this image.

     

    so, I'll post a link on npm module here when I'll have done

    • Like 1
    Link to comment
    Share on other sites

    Wow! Way over my head to code a Node Red module... o.O

    Respect!

     

    BTW, with the new 4.503-beta version I noticed some messages about API changes, so aren't you afraid that a lot of coding could be obsolete?

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...