# Homebridge + NodeRed + MQTT + ESP8266 help

**URL:** https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053
**Category:** General
**Created:** [14 July 2020 12:28 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053 "2020-07-14T12:28:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Dragos](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Dragos](https://discourse.nodered.org/u/Dragos)
#### Post date: [14 July 2020 12:28 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053/1 "2020-07-14T12:28:27Z")

</div>

Hello. I'm quite new to NodeRed and to programming in general. I've done a few automations in my home using ESP8266+Blynk, but I'm trying to convert my Arduino devices to different apps like Homekit, Google Home or Home Assistant. I'm currently trying to control an LED lights state and intensity using Homebridge. Here is my flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01232c4e0e2501937029537955ec5898606f6ebf.png)

I blurred out those nodes as they're just for experimenting. So here is my problem: I am able to control the intensity of the LED using this arduino callback function:

```auto
void callback(char* topic, byte* payload, unsigned int length) {

  for (int i = 0; i < length; i++) {
    payload[length] = '\0';
    int pwmVal = atoi((char *)payload);
    Serial.println(pwmVal);
  
    if (strcmp(topic, "test/message") == 0){
        int y=map(pwmVal, 0, 100, 0, 1024);
        analogWrite(led, y);
        if((char)payload[0]=='1'){
            digitalWrite(led, HIGH);
        }
        else if((char)payload[0]=='0'){
            digitalWrite(led, LOW);
        }
    }
  }
}

```

And my 2 NodeRed functions look like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/36d60336ae36af586d38f67950c3ef379983b767.png)

DimmerFunc should control intensity slider in Homekit app, and PowerFunc should only control the button(On,Off). Ok, so the button works, I am able to control the On/Off state of the LED with 1/0. However, when I'm using the slider, after each value sent to the MQTT topic a "1" is also received, something like this:

```auto
0 //Off
1 //On, next I'll adjust the slider
50
1
46
1
41
1 //And so on

```

So the light always stays on without changing its intensity. I'm assuming the 2 functions are somehow conflicting with each other. I don't understand how though. How could I bind them together and use both the slider and the button to control the LED? I'll also like to remember the last slider value, so when push the "On" button, the LED gets the intensity it last had. Any help is greatly apreciated!

Dragos

---

<div class="post-metadata">

### Author: ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)
#### Post date: [14 July 2020 16:38 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053/2 "2020-07-14T16:38:27Z")

</div>

Hello! I’ve been doing docs for this contrib for a while, we have a pretty good wiki page at the github and have recently been hanging out on discord, you’re welcome to join in: [https://discord.gg/Af6fxex](https://discord.gg/Af6fxex)

Looking at your setup - I bet things will work better if you use only the first output of the HomeKit node. The second sends on true/fals every time you change the slider. First will send on true/false only when you actually change from on-\>off or off-\>on.

More examples and functions for light bulbs are [here](https://github.com/NRCHKB/node-red-contrib-homekit-bridged/wiki/Example-Bulb-Dimmer)

---

<div class="post-metadata">

### Author: ![Dragos](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Dragos](https://discourse.nodered.org/u/Dragos)
#### Post date: [14 July 2020 23:45 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053/3 "2020-07-14T23:45:17Z")

</div>

@crxporter I could have sworn I’ve done that... thanks, it works. Altough I still need to store the brightness value somehow so when I turn it on it’ll go to the last brightness value rathen than 1. But I might be able to work on the documentation you sent.

One more question though: am I able to control the HomeKit node over cellular? As soon as I disconnect from my network the node goes offline. Blynk nodes work fine both WiFi and Cellular.

---

<div class="post-metadata">

### Author: ![Shaquu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shaquu/32/9701_2.png) [@Shaquu](https://discourse.nodered.org/u/Shaquu)
#### Post date: [15 July 2020 04:33 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053/4 "2020-07-15T04:33:18Z")

</div>

In order to control your smart home via Cellular you need home hub [https://support.apple.com/en-us/HT207057](https://support.apple.com/en-us/HT207057)

---

<div class="post-metadata">

### Author: ![crxporter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crxporter/32/25734_2.png) [@crxporter](https://discourse.nodered.org/u/crxporter)
#### Post date: [15 July 2020 05:02 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053/5 "2020-07-15T05:02:06Z")

</div>

> [@Dragos](#):
>
> As soon as I disconnect from my network the node goes offline

HomeKit over cellular will only work if you have an Apple TV, HomePod, or iPad set up as a home hub. [Here is the Apple website explaining better](https://support.apple.com/en-us/HT207057)

Sounds like you've made some progress! Excellent! I'm planning to check these forums a bit more to see if anyone needs help so feel free to flag me if you need anything else

---

<div class="post-metadata">

### Author: ![Dragos](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Dragos](https://discourse.nodered.org/u/Dragos)
#### Post date: [15 July 2020 10:17 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053/6 "2020-07-15T10:17:59Z")

</div>

I set up my iPad as a home hub, thanks!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [13 September 2020 10:18 UTC](https://discourse.nodered.org/t/homebridge-nodered-mqtt-esp8266-help/30053/7 "2020-09-13T10:18:05Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
