arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
467 stars 104 forks source link

GarageDoorOpener Current Door State #217

Open ThiloOS opened 4 years ago

ThiloOS commented 4 years ago

Hey,

I'm trying to use the mqttthing plugin to control my garagedoor. It works almost perfectly except for one little thing: I can't set the current door state to "Opening". Each time I publish "Opening" by my mosquitto broker, it returns me Closing in the Homekit App.

Even in the log of Homebridge it sets the current door state to "Closing".

This is my config:

{
            "accessory": "mqttthing",
            "type": "garageDoorOpener",
            "name": "DevGarage",
            "url": "",
            "username": "",
            "password": "",
            "caption": "",
            "logMqtt": "true",
            "topics": {
                "setTargetDoorState": "test/garage/target",
                "getTargetDoorState": "test/garage/current",
                "getCurrentDoorState": "test/garage/current",
                "setLockTargetState": "test/garagelock/target",
                "getLockTargetState": "test/garagelock/current",
                "getLockCurrentState": "test/garagelock/current",
                "getObstructionDetected": "test/garage/obstruction"
            },
            "doorValues": [
                "Open",
                "Closed",
                "Opening",
                "Closing",
                "Stopped"
            ],
            "lockValues": [
                "Unsecured",
                "Secured",
                "Jammed",
                "Unknown"
            ]
        }

This is the Homebridge log while closing the door:

[3/3/2020, 11:45:44] [DevGarage] Publishing MQTT: test/garage/target = Closed
[3/3/2020, 11:45:44] [DevGarage] Received MQTT: test/garage/current = Closing
[3/3/2020, 11:45:44] [DevGarage] State doortar is now: 3
[3/3/2020, 11:45:44] [DevGarage] State doorcur is now: 3
[3/3/2020, 11:45:54] [DevGarage] Received MQTT: test/garage/current = Closed
[3/3/2020, 11:45:54] [DevGarage] State doortar is now: 1
[3/3/2020, 11:45:54] [DevGarage] State doorcur is now: 1

And this while opening

[3/3/2020, 11:47:38] [DevGarage] Publishing MQTT: test/garage/target = Open
[3/3/2020, 11:47:38] [DevGarage] Received MQTT: test/garage/current = Opening
[3/3/2020, 11:47:38] [DevGarage] State doortar is now: 2
[3/3/2020, 11:47:38] [DevGarage] State doorcur is now: 2
[3/3/2020, 11:47:48] [DevGarage] Received MQTT: test/garage/current = Open
[3/3/2020, 11:47:48] [DevGarage] State doortar is now: 0
[3/3/2020, 11:47:48] [DevGarage] State doorcur is now: 0

I have no idea why it gives me "Closing" in the homekit app when changing door state from close to open.

matbor commented 4 years ago

@ThiloOS did you work it out? having the same problem. thx.

arachnetech commented 4 years ago

I’m not in front of a computer so I can’t easily check all the state values, but I believe you need to publish a target state of open when the door is opening due to an event external to homekit. Homekit always assumes that a garage door will be moving towards the target state that it knows about - so if homekit didn’t open the door and it’s not closed, homekit will assume that it’s closing. You can publish the getTargetState topic to fix this.

arachnetech commented 4 years ago

Looking at your config, I think you’re already trying to do this. You have getTarget and getCurrent topics set to the same.

However, there is no target state of ‘opening’ or ‘closing’ - so homekit won’t understand these and will assume the target to be closed or open until the door finishes opening or closing.

arachnetech commented 4 years ago

I think I could make this easier by tweaking mqttthing to treat a target state of opening as open and a target state of closing as closed. I’ll add it to my list!

ThiloOS commented 4 years ago

@matbor still facing the same problem, hoping to find a way to fix this soon.

hemant5400z commented 4 years ago

I think I could make this easier by tweaking mqttthing to treat a target state of opening as open and a target state of closing as closed. I’ll add it to my list!

Hi arachnetech,

Would it be an idea instead of opening/closing to use "running as a state? This way when using pluse switch in MQTT cmnd/xxxxxxxx/power 1 or toggle the door movement can be set to publush running and final stage to open or close.

This might solve my problem with having 1 read switch for bother open and close as i cannot detect opening and closing.

Hemant

EjvindHald commented 4 years ago

Hi I actually think Apple did a very good job when defining the garage door opener. Your intent is always to either open or close the door - this is target state. After that intent the door starts moving, and will in most cases end by being open or closed - this is current state. The Homekit app supports all this, and it is working really fine. You would like to reduce this to a simple open or close like a true/false. You could argue whether this is something your app should handle or the mqtt plugin should handle. If the mqtt plugin will be changed, then please still support current transparency, because that is really awesome. I can in realtime in the app see the opening and closing direction plus the end state. Also, I can see in the app if an obstruction is detected.

arachnetech commented 4 years ago

I've just added an alternative way to expose garage door opening/closing state. Instead of publishing to the getCurrentDoorState topic, you can now publish to getDoorMoving - publishing true if the door is moving or false if it has reached its final state (with the usual options for Boolean values). Mqttthing will work out the corresponding opening/closing/open/closed state in relation to the target state. This might make what you're doing easier.

If you have a reed switch detecting when the door is fully-closed, and another detecting when the door is fully-opened, you could set them both to publish true to the getDoorMoving topic when the door starts to move away from them, and false when the door comes to rest at the other position.

As an even simpler option it's possible to configure a getDoorMoving topic but never publish it. Homekit will then just toggle the garage door between open and closed.

hemant5400z commented 4 years ago

Hi,

Not sure if this results in what I want/need. So I have 1 reed switch which either detects op/close and a relay which toggles at pulse time.

With the new settings this always results in an incorrect state.

My rule:

rule2 on SWITCH1#state=0 do publish2 stat/relay/current C endon on SWITCH1#state=1 do publish2 stat/relay/current O endon on POWER1#state=1 do publish2 stat/relay/roldeur true endon on POWER1#state=0 do publish2 stat/relay/roldeur false endon

And the config:

"topics": { "setTargetDoorState": "cmnd/relay/Power1", "getCurrentDoorState": "stat/relay/current", "getDoorMoving": "stat/relay/roldeur", "getTargetDoorState": "stat/relay/current", "getObstructionDetected": "stat/relay/garage" }, "doorCurrentValues": [ "Open", "Closed", "Opening", "Closing", "Stopped" ], "doorTargetValues": [ "Toggle", "1" ]

While I receive: Received MQTT: stat/lctech/current = C; Homekit shows the door as Open.

Hemant

arachnetech commented 4 years ago

I don't think that's going to work directly with mqttthing. You need something implementing the logic of "open the door" / "close the door" MQTT topics - mqttthing can't just tell your door to move based on reed switch state. It expects the accessory to be 'smart'. You could always wrap up this logic in something like Node-RED, of course.

hemant5400z commented 4 years ago

Hi,

Why not, the reed switch should tell open or close status and the button should take the status from the reed as its state. When pushing the button it should toggle and get state back from the reed.

cursate: reed switch either open/close Set state: cmnd to toggle target state= not sure if I understand this one but currently same as currstate

Hemant

arachnetech commented 4 years ago

What MQTT messages exactly does your reed switch publish at what times?

What MQTT messages does your door motor need to receive at what times? MQTTThing can only publish one value to mean "open the door" and another to mean "close the door". Any other logic would need to be handled externally.

hemant5400z commented 4 years ago

My reed switch publishes Switchstate 1 = Open Switchstate 0 = Close

The open/close trigger is a cmnd command that is a momentary switch as the door needs to get a pulse cmnd/garage/power toggle.

SO my open/close command are actually Toggle which is always from 0 to 1 for 10 secs and back to 0.

The reed switch publishes on state change.

Hemant

hemant5400z commented 4 years ago

Also: "getCurrentDoorState": "stat/lctech/test" is currently: stat/lctech/Test O

Which should be Open, but Homekit still shows Closed, I use Publish2 so correct info should be coming from MQTT

Hemant

iondarie commented 4 years ago

@arachnetech i have a garage door with 2 reed sensors.

Rule1 on switch1#state=0 do publish2 %topic%/stat/garaj OPEN endon on switch1#state=1 do publish2 %topic%/stat/garaj CLOSING endon on switch1#state=1 do publish2 %topic%/target/garaj CLOSED endon

Rule2 on switch2#state=0 do publish2 %topic%/stat/garaj CLOSED endon on switch2#state=1 do publish2 %topic%/stat/garaj OPENING endon on switch2#state=1 do publish2 %topic%/target/garaj OPEN endon

The "logic" that is sent to mosquitto is pefect. Let's assume i have my garage door closed when i click open my tasmota sends the "OPENING" message to "getCurrentDoorState" and "OPEN" to "getTargetDoorState". All the messages are published using publish2 so the messages are being retained.

The main issue is that our garage motors are using pulse for example mine is configured from tasmota to give a short 2s activation impulse to the relay. For it to work it needs only "ON" to be published to "setTargetDoorState".

hemant5400z commented 4 years ago

Hi,

I should be able to achieve this with 1 reed switch as if not closed it is obviously open that is why I publish the reed topic with open and close.

I don't publish opening and closing is that required to get this working?

Hemant

hemant5400z commented 4 years ago

Hi Thanks,

I moved to anather garagedoor plugin which fixes the issue and provides the correct status.

Hemant

arachnetech commented 4 years ago

Glad you found a solution, @hemant5400z. Please do mention the garagedoor plugin that solved this here if it would help others. More specialist plugins can often be easier and more flexible to use for specific accessories than mqttthing.

If you ever want to try mqttthing again, @jdtsmith implemented some remarkable custom logic for garage doors in issue #225 which might help you. However, I suspect the other plugin you’ve found is a simpler solution.

@ThiloOS, @iondarie, are you still persevering with apply functions in mqttthing for your garage doors, or would @hemant5400z ’s solution be better for you?

hemant5400z commented 4 years ago

Hi, Yes mine is way more simple it has flexibility to use 1 or 2 reeds depending on your hardware. It exposes the door closed or open based on 1 reed and handels the rest both in and outside homekit.

I use the mqttgaragedoor from iomax look at the thread posted works perfect now.

I will try to post my config there.

Verstuurd vanaf mijn iPhone

Op 18 apr. 2020 om 10:35 heeft David Miller notifications@github.com het volgende geschreven:



Glad you found a solution, @hemant5400zhttps://github.com/hemant5400z. Please do mention the garagedoor plugin that solved this here if it would help others. More specialist plugins can often be easier and more flexible to use for specific accessories than mqttthing.

If you ever want to try mqttthing again, @jdtsmithhttps://github.com/jdtsmith implemented some remarkable custom logic for garage doors in issue #225https://github.com/arachnetech/homebridge-mqttthing/issues/225 which might help you. However, I suspect the other plugin you’ve found is a simpler solution.

@ThiloOShttps://github.com/ThiloOS, @iondariehttps://github.com/iondarie, are you still persevering with apply functions in mqttthing for your garage doors, or would @hemant5400zhttps://github.com/hemant5400z ’s solution be better for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/arachnetech/homebridge-mqttthing/issues/217#issuecomment-615764347, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEA6CKX6IHVG64LT7VA2SJLRNFQ6ZANCNFSM4LAHXN4Q.

jdtsmith commented 4 years ago

Hi, Yes mine is way more simple it has flexibility to use 1 or 2 reeds depending on your hardware.

Two sensors would be straightforward to support with MQTTThing if both report to the same topic, and your device publishes sensor updates periodically. Something like: