NodeMCU + mqtt + window blinds

Can someone help mqtt noob to get my project working :slight_smile:

I have two window blinds and want to drive them with mqtt (homeassistant and MQtt server).

Homeassistant, mqtt server etc are ok and working.

Problem is find any good tutorial/easy example how i get arduino code that mqtt client.

I think something so easy like send mqtt command: 0-180

And thats it. If i send command 180 my homeassistant arduino get that 180number and move that directly my servo sketch and drive servos 180degrees position. (or if sen 132 sketch drive servos 132degreees position.

I have working sketch to drive servos (Use analog0 and potentiometer to test curtains, but that of course replace mqtt message info)

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo
Servo myservo3;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int sensorValue = 0;    // variable to store the servo position
int sensorValue2 = 0;

void setup() {
  myservo.attach(5);  // attaches the servo on pin 9 to the servo object

void loop() {
  sensorValue = analogRead(A0);
  sensorValue = map(sensorValue, 0, 1023, 0, 160);


    myservo.write(sensorValue);              // tell servo to go to position in variable 'pos'

Of course if is easy to get update what position curtains are example every 10minutes or something that very nice. That can be same like number back to mqtt broker.

Of course if easier messages can be example: open, close, half open

But i think that give more options to control blinds with homeassistant software when you only give exact position where blinds drive.

I am very thankfull any tips and hints.

  • I would NOT use the range values of 0-180.. most servos can NOT travel that full range.. I would try somewhere between 15-165 and test your limits from there.

  • You mention MQTT server.. but what one? Are you using an on-line free service or something? (not familiar with what home assistant is.. and you have not provided any links to anything)..

So is this a free, on-line service somewhere?
Are you rolling your own MQTT server? Like using a Raspberry Pi configured as an MQTT server or something?

Homeassistant, mqtt server etc are ok and working.

How do you know?

Of course test right limits that servos, because that i have potentiometer test code there.

mqtt server working ok, thats not problem and homeassistant is home automation system what works raspberry pi.

My homeautomation system working ok (includes mqtt server, home automation software etc)

Now i just want do mqtt device what controls my blinds. Allready try find examples on google, but they all what i find are little different and quite complicated systems.

I just need mqtt device what understand example 134 command and give that info to servo move command. And maybe get info back to mqtt server what is servo state after that. Or maybe device can update servo state every 10minutes or something like that.

Homeassistant, mqtt server etc are ok and working.

How do you know?

Because my home automation system works fine and every mqtt devices work ok.