Homebridge + NodeRed + MQTT + ESP8266 help

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:

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:

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

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:

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

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

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

2 Likes

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

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

1 Like

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

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

1 Like

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

1 Like

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