MQTT cover with unknown state (always)

Hi!

I am using the command line cover to control my roller blinds. I have a command line script which connects to an arduino over serial (for now, will go ethernet later!!) which transmits the 433MHz signal to activate the blind. It works ok and the command line cover component is happy without a “state” command and just keeps the state as “unknown”. This works well as it never can know the state given someone in the house may just use the remote control that came with the blind to change the state.

I’ve just switched one of my blinds over to MQTT, as I cannot automate multiple blinds at once - with my setup the command line cover cannot be executed many times for many blinds - only one instance of the script can connect to the arduino at any given time. MQTT will allow me to run the script as a daemon that subscribes to many cover topics (e.g. home/+/blind/set) and sends the command to the arduino. I can then configure each cover as MQTT in home assistant with command topics like home/kitchen/blind/set, home/bedroom/blind/set.

This is working well for the one blind I changed over, except for the state. I have not specified a state topic for the MQTT cover, however it is not behaving like the command line cover which always assumed the state is “unknown”. Initially it does, but once I click “open”, the state is set to open and I can no longer click “open” again, only close. This won’t work for me, as someone may press the blind’s remote control and close the blind, which home assistant won’t know about and I won’t be able to open the blind again from home assistant.

Have I got something wrong in my config, or is this a bug/feature!?

Config:

cover:
- platform: mqtt
  name: "Family room blind"
  command_topic: home/family-room/blind/set
  optimistic: false
  payload_open: "up"
  payload_close: "down"
  payload_stop: "stop"

Thanks in advance if anyone can help :slight_smile:

Its possibly a little late but in case anyone else is interested, try adding

state_topic: "home/family-room/blind/state"

And in your code

/** @const string node property for the sensor */
const char * NODE_PROPERTY_SENSOR = "state";

const char * NODE_SENSOR_STATE_OPEN = "open";
const char * NODE_SENSOR_STATE_CLOSED = "closed";
...
int sensorRawValue = digitalRead(PIN_SENSOR);
if (sensorRawValue != lastSensorRawValue) 
{
    Serial.print("Sensor raw value changed from ");
    Serial.print(lastSensorRawValue);
    Serial.print(" to ");
    Serial.print(sensorRawValue);
    Serial.print(" -> ");
    Serial.println((sensorRawValue == HIGH)? NODE_SENSOR_STATE_OPEN : NODE_SENSOR_STATE_CLOSED);

    if (Homie.setNodeProperty(sensorNode, NODE_PROPERTY_SENSOR,
                          (sensorRawValue == HIGH)? NODE_SENSOR_STATE_OPEN : NODE_SENSOR_STATE_CLOSED,
                          true)) 
    {
       lastSensorRawValue = sensorRawValue;
    }
    else
    {
       Serial.println("setNodeProperty failed!");
    }
1 Like