Home Assistant Simple Motorised Roller Blind

Home Assistant Simple Motorised Roller Blind

This project was inspired by the excellent work of nidayand and their motor-on-roller-blind-ws project. Basically I stripped that project back to it’s bare bones and implemented WiFi AP mode so MQTT configuration can be done without need for code changes.

The initial parts for the project were printed from Motor on a roller blind by pgote. I then created a “better” enclosure to house the components here.

Setup

Instructions for full setup are available here: https://github.com/jampez77/motor_blind

Spoiler Images

Changelog

Version 2.1 - More config via HA

Created Reset Limits button that will remove stored values for Open and Closed limits so they can be changed. This button will only appear in HA once a limit has been set.

Created WiFi AP button that will reboot into a wireless access point so WiFi or MQTT details can be changed. Press Save in the WiFi Config page to reboot the device again and connect it back to HA.

Additionally:

I updated to these motor drivers as the smaller form factor allows the whole device to fit on a proto board in a custom enclosure.

THIS IS ENTIRELY OPTIONAL AS THE WIRING IS EXACTLY THE SAME. If you’re not bothered about fitting your device into a nice neat little box then you don’t need to pay any attention to this.

Version 2.0 - Created WiFi Access Point setup (Breaking Changes)

Moved MQTT topics so they’re defined in setup using the deviceId.

Added WiFiManager so project can be setup without code changes.

Renamed setup switches in HA to more descriptive names.

Breaking Changes
MQTT topics are now auto generated which means that topics produced manually in previous version will not carry across when updating from version 1.x.

Version 1.1 - Simplified process for having multiple project instances in HA

Created deviceName variable so only a single change is required to create a new device in HA.

Tweaked topics and devices names/IDs so each instance appears as separate device in HA.

Increase JSON memory allocation by 50 characters to allow for larger device names.

Updated variables for MQTT server to be more specific and allow port to be changed.

Version 1.0 - Initial Release

LED status indicator

  • Solid light = No WiFi connection
  • Flashing Light = no MQTT connection
  • No light = connection established

ArduinoOTA for wireless code updates.

Added MQTT config on boot to integrate seamlessly with Home Assistant.

7 Likes

Thanks for sharing! Will go on my todo list!

1 Like

Good luck. Hope you get on ok

Thank you for sharing :smile: . I was able to successfully integrate a motor into my Homeassistant.
But now I have the problem that I can not integrate another motor. The problem is that when I adjust the topic etc. in the helper file, HomeAssistant cannot find the device.
What am I doing wrong ? I have changed all names with “study blind”. Likewise I have adapted the Id’s etc…with a mqtt listener i looked at the packages. As soon as I change something the messages are truncated.Do you have any idea ?

Thanks for your help

Hmmm :thinking: is it possible for you to share your helper files for each of your blinds?

Hi Jamie,
no problem. I have already tried a lot. As soon as I change the names it doesn’t work anymore. If I put everything back into “study Blind” and the original names, the device is found immediately. I have tried many hours yesterday to find the problem. Unfortunately without success. Maybe I did not understand something correctly. I have not yet done so much with MQTT.

This is what e.g. Mqtt.fx shows me at the message for “max”. It looks like only a part is transferred. For whatever reason.

{
  "name": "EliaSet Max",
  "ic": "mdi:blinds",
  "cmd_t": "homeassistant/switch/middleFloor/eliaBlindMax/set",
  "stat_t": "homeassistant/switch/middleFloor/eliaBlindMax/state",
  "avty_t": "homeassistant/cover/middleFloor/eliaBlind/availability",
  "uniq_id": "EliaBlindsMax",
  "dev": {
    "name": "EliaBlinds",
    "mf": "NandPez",
    "mdl": "Node MCU D1 Roller Blind Motor",
    "sw": "1.0",
    "ids": [
      "EliaBlinds",
      "EliaRstBlinds",
      "EliaBlindsMin",
      "EliaBlindsMa

and here the My_Helper.h

#ifndef MY_HELPER_H
#define MY_HELPER_H

const char* ssid = "xxxx";
const char* password = "xxxxx";
const char* mqtt_user = "xxxxx";
const char* mqtt_password = "xxxxxxx";
const char* mqtt_server = "xxxxxxxxx";
const char* coverStateTopic = "homeassistant/cover/middleFloor/eliaBlind/state";
const char* coverDebugTopic = "homeassistant/cover/middleFloor/eliaBlind/debug";
const char* coverCommandTopic = "homeassistant/cover/middleFloor/eliaBlind/set";
const char* coverConfigTopic = "homeassistant/cover/middleFloor/eliaBlind/config";
const char* coverAvailabilityTopic = "homeassistant/cover/middleFloor/eliaBlind/availability";
String mqttCoverDeviceClientId = "EliaBlinds";
const char* mqttCoverDeviceName = "Elia Blinds";
const char* mqttCoverDeviceClass = "eliablind";

const char* resetCommandTopic = "homeassistant/switch/middleFloor/eliaBlind/set";
const char* resetStateTopic = "homeassistant/switch/middleFloor/eliaBlind/state";
const char* resetConfigTopic = "homeassistant/switch/middleFloor/eliaBlind/config";
String mqttResetDeviceClientId = "EliaRstBlinds";
const char* mqttResetDeviceName = "EliaReset";

const char* minCommandTopic = "homeassistant/switch/middleFloor/eliaBlindMin/set";
const char* minStateTopic = "homeassistant/switch/middleFloor/eliaBlindMin/state";
const char* minConfigTopic = "homeassistant/switch/middleFloor/eliaBlindMin/config";
String mqttMinDeviceClientId = "EliaBlindsMin";
const char* mqttMinDeviceName = "EliaSet Min";

const char* maxCommandTopic = "homeassistant/switch/middleFloor/eliaBlindMax/set";
const char* maxStateTopic = "homeassistant/switch/middleFloor/eliaBlindMax/state";
const char* maxConfigTopic = "homeassistant/switch/middleFloor/eliaBlindMax/config";
String mqttMaxDeviceClientId = "EliaBlindsMax";
const char* mqttMaxDeviceName = "EliaSet Max";

const char* doorStatus = "";
const char* prevDoorStatus = "";

const char* softwareVersion = "1.0";
const char* manufacturer = "NandPez";
const char* model = "Node MCU D1 Roller Blind Motor";
boolean configDetailsSent = false;

long currentPosition = 0;  
long minPosition = -1;  
long maxPosition = -1;  

int CLOSE = 1;
int OPEN = 0;
int STOP = -1;
int motorDirection = STOP;
const int ledPin = LED_BUILTIN;

//Statuses
const char* opened = "open";
const char* closed = "closed";
const char* closing = "closing";
const char* opening = "opening";
const char* stopped = "stopped";

//pay loads
const char* payloadOpen = "OPEN";
const char* payloadClose = "CLOSE";
const char* payloadStop = "STOP";
const char* payloadAvailable = "online";
const char* payloadNotAvailable = "offline";

#endif

Try this, change this line:

	const char* mqttCoverDeviceClass = "eliablind";

to this

	const char* mqttCoverDeviceClass = "blind";

ok, that was not bad :slight_smile: . Now a new device appears. But min, max and reset is not displayed. Thanks for the patience.
Bildschirmfoto 2021-02-14 um 18.36.40

hmmm :thinking: Do you get any logs about it at all?

is the same problem as before, the messages are not transmitted completely. Here is a picture of Mqtt.fx . In HA the messages are not displayed. ( max, min and reset) . Only the cover message and the status arrives.

Ah ok, I know what’s going on here!

TLDR: Your device client ID’s are too long.

Detail:
The JSONDocuments have to be a predetermined length, which I set to the minimum I could get away with based on the existing names.

Options:

  1. Increase allocated memory for config JSONDocuments so full JSON is sent.
  2. Only change the names in the MQTT topics /studyBlind/ in the code. Then change the entity names in HA.
  3. Update to latest release. This simplifies the process for having multiple instances of the project. You will need only to change one variable mqttName and the rest should be done in HA. Note: This is as yet untested and you would be the guinea pig :smiley:

Thank you very much, here I like to play the guinea pig :slight_smile: . Unfortunately, however, this does not solve the problem for me. If I now give the mqtt name HA finds a new device. But as soon as I add another device with a different name, HA does not create a new entity. I.e. only one device is found. The mqtt messages look ok to me at first. The messages are no longer truncated. If I delete the entity of the first device, then it finds the second device.
Maybe it has something to do with the topics ?
I hope I am not annoying.

So it’s late and I’ve not looked into this but I’ve just potentially had an epiphany with this.

I think mqttCoverDeviceClientId needs to be unique for each device too. I will try it out tomorrow and let you know.

Not in the slightest, I very much enjoy this kind of stuff :slight_smile: plus I use this project myself and have been thinking of adding another one so we both benefit.

I tried that, but it doesn’t seem to solve the problem either.
I have done the following in the My_Helper.h:

const String mqttCoverDeviceClientId = mqttName;
const char* mqttCoverDeviceName = mqttName.c_str();

The problem is then it finds the first device, displays the name correctly and then the second device again does not work. There must be something else wrong in the topics. At least when another device is created.

First I changed only the mqttCoverDeviceClientId. If I then change the mqttCoverDeviceClass, then HA no longer finds a device

OK, so I dare say I may have solved this issue now haha

I’ve put out a new release and even tested it myself.

The problem was that I hadn’t quite got the topics and devices names quite right in order to create a separate instance for each device in HA.

I increased the memory allocation for the JSONDocuments so you can have longer device names. Try to keep them below 20 characters to be on the safe side though.

I also realised that the mqtt_server const was misleading as I was entering a full http url when it just needs to be an IP address. So the variable has been changed to mqtt_server_ip for the sake of clarity. There is also now an option to change the MQTT port number.

One thing I noted during testing was that if a device name from the previous broken instance was used it would remain broken. I think the details of that device are cached in HA. What this means for you I think, is that you will probably have to choose a different name than eliaBlind.

Good luck, hope this finally works. Let me know how you get on. :crossed_fingers: :smiley:

1 Like

great, that seems to work. Two entities are now found. There was still a small error in my_helper.h

change
const char* mqtt_server_port = 1883;
to

int mqtt_server_port = 1883

thank you very much. I will now test a little and add more devices. What is apparently not allowed in the name is a space. Then HA does not find any device.

I will contact you as soon as I notice more things. Thanks a lot, it was a lot of fun until here.

Woohoo finally some good progress! :laughing:

I’ll implement the change to int and it will be in the next release. Thanks for all your help :slight_smile:

1 Like

Thanks for your work on this. I’m 3d printing the parts as we speak. Find this overall to be better then TheHookUp solution.

1 Like

Thanks man, I shall be taking that compliment to the bank! Hope it works out well.