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


Connecting Fibaro HC2 to an ESP8266 - two tutorials


ianbren

Recommended Posts

Hi, I've had a few questions on how to use Fibaro HC2 to talk to ESP8266 devices.

 

If you're interested, the simple example over at

Please login or register to see this link.

can help.

 

there are two assumptions

- that you can create a Virtual Device in Fibaro and have used LUA before

- that you've got the Arduino environment to build and ESP8266 (of whatever flavour you want).

 

Basically, the solution has a Virtual Device with one button - press the button in Debug mode and the ESP8266 is called and returns with some JSON.

 

 

If there's interest, I'll expand the examples to include one for ESPEASY and a DHT11 - where you can build wifi-enabled temperture devices.

 

 

Cheers

 

Ian

 

Edited by ianbren
change of title
Link to comment
Share on other sites

  • Topic Author
  • 201 is also posted now at

    Please login or register to see this link.

     

    Shows how a Fibaro HC2 can poll an ESP8266 and receive JSON data back - then post it to a label.

     

    This is a work in progress and if there's interest I'll move on to ESPEASY - to monitor temperature.

     

     

    • Like 1
    • Thanks 1
    Link to comment
    Share on other sites

    JFYI:

     

    1) ESP8266 Serial ESP-12F Wi-Fi Witty Cloud Development Board + DHT22

    Please login or register to see this spoiler.

     

    2) Code TemperatureHumidity.ino (see attach file TemperatureHumidity.ino)

    3) FIBARO VD (see attach file Climate_ESP.vfib 

     

    lUfmYTZ2or.png

     

    lQb2w50hNa.png

     

     

     

     

     

    Please login or register to see this attachment.

     

    Please login or register to see this attachment.

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

    Guest pablo77

    Hi,

     

    On ESP8266 board You have Light sensor ( that thing in upper corner). Are You not using it in the skech ??

    Edited by pablo77
    Link to comment
    Share on other sites

    1 hour ago, pablo77 said:

    Hi,

     

    On ESP8266 board You have Light sensor ( that thing in upper corner). Are You not using it in the skech ??

     

    Please login or register to see this image.

     

    Please login or register to see this code.

    Perhaps you failed to pay attention to the arduino sketch file.

     

    notice:

    const char* WIFI_PASS = "id2891Sz500Qp";

     

    it's fake WiFi password :) but in any case - thank you and welcome to my home and Ukraine :)

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • I like the Code - some suggestions...

    (a) - you calculate Dewpoint - but don't return it in the HTML.

    (b) the calculation is deferred every 15 seconds (in the main loop) - perhaps pull the constant out to the top to make it clear what's happening.

    (c) you might want to consider starting up the DHT/reportreading  before calling the server.begin() - as it stands the HTML strings (humidityString etc) are empty and Fibaro may start polling before the first read.


    Oh, and I love the icon model.

    Oh, and I found the WITTY useful for the LDR, but getting access to the Digital pins is a pain for anything other than experimenting.

     

    Have a look at WEMOS D1 Mini - they're about the same price, the same form-factor but have Shields (only the DHT11 in this case) 

    Please login or register to see this link.

     

    Edited by ianbren
    strike through on (c)
    Link to comment
    Share on other sites

    20 minutes ago, ianbren said:

    I like the Code - some suggestions...

    (a) - you calculate Dewpoint - but don't return it in the HTML.

     

    (b) the calculation is deferred every 15 seconds (in the main loop) - perhaps pull the constant out to the top to make it clear what's happening.

    (c) you might want to consider starting up the DHT/reportreading  before calling the server.begin() - as it stands the HTML strings (humidityString etc) are empty and Fibaro may start polling before the first read.


    Oh, and I love the icon model.

    Oh, and I found the WITTY useful for the LDR, but getting access to the Digital pins is a pain for anything other than experimenting.

     

    Have a look at WEMOS D1 Mini - they're about the same price, the same form-factor but have Shields (only the DHT11 in this case) 

    Please login or register to see this link.

     

     

     

    a) yep! you're right. I was thinking later what it's useless :)

    b) yes. :)

    c) arduino does not start loop thread while setup() void not done :) + server.handleClient(); last command in loop - all requests from HC2 going to /dev/null :)

     

    Quote

    Oh, and I found the WITTY useful for the LDR, but getting access to the Digital pins is a pain for anything other than experimenting.

     

    but this sandwich pretty good! (IMHO)

     

    Quote

    Have a look at WEMOS D1 Mini - they're about the same price, the same form-factor but have Shields (only the DHT11 in this case) 

    Please login or register to see this link.

     

    yes, I know. 

    see also:

    WeMos D1 mini DHT11 shield
    WeMos D1 mini DHT22 shield
    WeMos D1 mini OLED 0.66 shield (

    Please login or register to see this link.

    )
    WeMos D1 mini TB6612FN (motor driver) shield
    WeMos D1 mini button shield
    WeMos D1 mini relay 5v shield
    WeMos D1 mini LED ws2812 controller shield


    :)

    Link to comment
    Share on other sites

  • Topic Author
  • 16 minutes ago, 10der said:

    arduino does not start loop thread while setup() void

    - good point - and the variables are populated before that.  So scrub (c)!!

    Link to comment
    Share on other sites

    as Another ideas...

     

    Arduino sketch

    Please login or register to see this spoiler.

     

    here are results:

     

    RQ5JoyMXtK.png

     

     

    so, now ESP poll FIBARO if events occurred

    ESP call fibaro scene and pass some parameters.

    pay attention: we can use one single scene for many external callers - a simple pass to the scene for example Id or action etc

     

     

     

    btw, in the scene we can pass a table as well:

    for example

     

    Please login or register to see this code.

    fibaro result:

    [DEBUG] 02:14:52: actions
    [DEBUG] 02:14:52: table: 0xa133818

     

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • I've seen this before - it does split the logic between the ESP and the Fibaro - but this approach pushes the FB-specific actions into the Scene.

     

     

    Link to comment
    Share on other sites

    • 6 months later...
    Guest DPKok
    On 20-9-2017 at 3:52 AM, ianbren said:

    201 is also posted now at

    Please login or register to see this link.

     

    Shows how a Fibaro HC2 can poll an ESP8266 and receive JSON data back - then post it to a label.

     

    This is a work in progress and if there's interest I'll move on to ESPEASY - to monitor temperature.

     

     

     

    Hi,

     

    First of, thanks for the info. It was realy helpfull thusfar. Perhaps you can help me a littlebit further.

     

    I'm building a touchscreen based on a Nextion display and a ESP8266 Nodemcu chip. I want to make a wall controller for my Homecenter 2. I can already send data from mij ESP8266 to HC2 to start a scene or switch a device. And i can send the GET command from my HC2 to the ESP in order to start a void there. (With your code) I was wondering, is there a way that i can send the status or brightness value from my HC2 to a int in the ESP? I'm trying to figure it out for a while now and can't seem to fin a good soulution.

     

    Greetings,

     

    Damien

     

    P.S. Sorry for my English, not my native language.

     

    Link to comment
    Share on other sites

  • Topic Author
  • well, the simplest way would be to pass it as a parameter.  If you have the ESP8266 libraries installed, there's an example called "advanced web server".  It shows how you can pass page requests to the ESP and have it break them down.  Look for 

     

     server.on ( "/inline", []() {
      server.send ( 200, "text/plain", "this works as well" );
     } );

     

    If you want to pass a parameter something like this for "i" and "s" --- http://someUrl/myPage?i=5&s=20 --- then it get's a little more complicated.

     

     

    use a line like 

     

     

     server.on ( "/myPage", handleMyPageHere)

     

    then have a function

    void handleMyPageHere(){

    int myVar1, myVar2;

      if (server.hasArg("i")) myVar1 = (server.arg("i").toInt());

      if (server.hasArg("s")) myVar2 = (server.arg("s").toInt());

    // do something interesting with your variables.

    }

     

    Obviously scope of the variables is important.

     

    Maybe the return string is the response that Fibaro is waiting for.

     

    Have fun!

    Link to comment
    Share on other sites

    • 3 weeks later...

    The topic has been moved from "

    Please login or register to see this link.

    " to "

    Please login or register to see this link.

    ".

     

    Temat został przeniesiony z "

    Please login or register to see this link.

    " do "

    Please login or register to see this link.

    ".

    • Like 1
    Link to comment
    Share on other sites

    • 3 months later...

    I want use esp8266 for 2 relays for my garden watering. With Raspberry Pi and Domoticz all working. But i want use these relays with Fibaro.  It is possible and how ?

    Link to comment
    Share on other sites

    insippo, I had some success using EasyESP and have a scene calling the EasyESP REST API.

     

    - Check the EasyESP docs for API, you will have to set up a task for this.

    - Here in the forum you find numerous examples how a Fibaro scene makes a call to a REST API.

     

    Cheers,

     

    jayrock

    Link to comment
    Share on other sites

    A little off topic perhaps...

    I have some d1 mini's flashed with Tasmota and it exposes a web interface... very easy to get it to interact (status/ control) with the hc2 with a vd.

     

    Only downside is that it is over http (not https) . It also exposes an mtqq interface which is more secure  but with no HC2 support I have not played with that part... ....yet

    Link to comment
    Share on other sites

    1 hour ago, AutoFrank said:

    A little off topic perhaps...

    I have some d1 mini's flashed with Tasmota and it exposes a web interface... very easy to get it to interact (status/ control) with the hc2 with a vd.

     

    Only downside is that it is over http (not https) . It also exposes an mtqq interface which is more secure  but with no HC2 support I have not played with that part... ....yet

     

    btw:

    about tasmota

     

    Please login or register to see this image.

    Please login or register to see this code.

     

     

    Please login or register to see this code.

    Please login or register to see this code.

     

    Edited by 10der
    Link to comment
    Share on other sites

    Hi there,

     

    I am trying to connect Weatherman (

    Please login or register to see this link.

    ).

    Nice weatherstation....

    Controller is based on ESP8266. Communication with browser is fine showing data.

    Try to get json with VD based on  

    Please login or register to see this link.

     .

    Got Status=200 and Error=0 but response (should content json) seems to be "empty", using Port 80.

    Any idea?

     

    Best regards

    Michael

     

     

    Link to comment
    Share on other sites

    @miwa ["Content-Type"] = "application/json",

    in headers

    also see: 

    Please login or register to see this code.

    ["Accept"] = 'application/json',

    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...