Window Blinds - MQTT / Nodemcu problems

So the problem is on the hass site, not the nodemcu code site?

If i restart the hass with the mqtt server on, should it work?

No. If it is a message retained by the broker, it is in the broker’s database. It won’t get cleared unless you either send it a message like I said, or delete and recreate the broker’s database.

But first you should establish if a message is actually being sent by looking at the output of your script to see if a message is actually being sent. There may be another reason for the behaviour.

How can i run this`?

I receive this when i try.

Connection Refused: not authorised.
Error: The connection was refused.

Sorry, I should have noticed that you are using a username and password for your broker, so you will need those as well.

try

mosquitto_pub -t /troomblinds1/command -r -n -u mqtt_user -P mqtt_password

You can get help for mosquitto_pub with

mosquitto_pub --help
1 Like

I think this code helped me, but now is the servo running really short at startup, like 0,5 sec forward and 0,5 backwards.

Do you know why?

This sounds like it is more to do with the electronics than the software. I assume that the 0.5s is different from either of the times set by the spintime variable?

When i mount the blinds its working fine, so no worries.

Do you know something about sonoff and the retain flag with mqtt also?

When my sonoff switch are on, when i restart my hass the state becomes to off insteaf of the last know state.

Can you help me with that?

The servo needs more power to open the blinds, than closing it.
Thats the reason the different spintime.

When i change the power from my pc hub to a normal wall adapter, the spin forward and backwards fast is gone.

So meaby some power issues on my pc.

This seems more likely to be something in HA sending the message than anything in the broker. Perhaps an automation that runs at startup, or maybe the switch defaulting to off (although I don’t remember seeing that myself).

How should I implement this fix, do I have to use ssh?

You can use many methods to send the MQTT message. Windows, Android and Ios all have MQTT clients that can send messages to the broker.

But if you don’t have one of those already installed its easiest to ssh on to your machine and use mosquitto_pub.

really weird… If try this code using ssh and hit enter:

mosquitto_pub -t /blind/bc/command -r -n -u myusername -P mypassword

or this one:

mosquitto_pub -t /blind/bc/command -r -n

and If I disconnect the nodemcu and plug it back in the servo keeps running to the same direction, mmmm I would appreciate any help.

Do either of these commands give any errors?

What happens when you do

mosquitto_sub -v -t /blind/bc/command 

(add your username and password if necessary)

I apologize for the delay but Im still having a hard time trying to figure this out… If I type mosquitto_sub -v -t /blind/bc/command

I get this in terminal:
/blind/bc/command STOP

But even when I use the other commands, I don’t get any response in terminal and the servo keeps running when I unplug it and plug it back in. I have HASS installed.

I appreciate any help.

You need to set the mqtt to be retained.

But how can I do that? The above commands won’t do anything

You are not really giving enough information to allow anyone to help. For instance, is the nodemcu receiving commands and not responding, or not receiving them at all?

I had this issue alot, but i need to send you the MQTT command.

Hi mate, I’ve just got around to looking at this project again, did you ever figure out how to add the retain flag to messages sent and received using the sketch?

Would you be able to provide a copy of your whole sketch?

Thanks in advance!

Hi Simo, sure, i at work, so later this week :slight_smile: