WiFi Door/Window Sensor

Good morning,
I have a WiFi door/windows sensor that is exposed via the Smart Life app. It is compatible with Google Home and Amazon: from there I can check the status and know if the contact is Open or Closed. The contact connects to the WiFi only to transmit the status change, it does not remain connected continuously. On the home router, however, I have assigned a fixed IP.
I would like to integrate it into openHab, but I can’t. Can you give me some suggestions please?
Thank you
Matteo

Have a look in this thread: Newbie, info on Wifi Switches

1 Like

Hi Wolfgang_S,
I tried the first method, tuya-mqtt.js by AgentK. I have the IP address of the sensor, the ID and the Key.
I have to fill in the MQTT topics: what kind of device should I put in place of ?
Should I also enter the MQTT topic “command” or only the “state” topic?
And then, in the configuration of the items, what type should I put? Contact?
Thank you
Matteo

I looked into this about a year ago, so my information may be slightly out of date…

At the time, the battery-powered Window/Door sensors that use SmartLife/Tuya also have an extra chip inside them, which is what allows for the low power mode. This chip monitors the sensor, and then causes the WiFi chip to wake up. Because of this, it was not possible to use the same process as the permanently-powered devices.

However, I did find a bit of a workaround, utilising Alexa. You need to expose a Switchable Item from openHAB to Alexa, and then set up two Routines - one for when the Smart Life sensor reports “Open”, and another when it reports “Close”, which will change the state of this openHAB Item.

Reaction time wasn’t too bad - generally within a second or so of the status changing in SmartLife, it also reported in openHAB.

But, it does rely on the cloud for, SmartLife, Alexa AND openHAB to all be functioning, and performant.

1 Like

Thanks for the tips.
Could you please send me an example of how to write the item?
I tried with this
Contact Tuya_Door "Door" <door> {alexa="Tuya_Door.detectionState"}
but I don’t see any item change.
And also, how do I write the routine to edit the item?
Sorry, but I can’t set it up.

Thank you
Matteo

Hi all,
I installed the bind for Alexa.
The Alexa app sees all connected devices (Legrand, Netatmo, Xiaomi, Roborock and SmartLife), but from openHAB the door contact exposed by SmartLife is not visible. I don’t understand: is it a problem with SmartLife or with the contact itself? Can you help me please?
Thank you
Matteo

You can’t grab an item that only Alexa knows about in that way.

You need to expose an Item within openHAB to Alexa. I used a Switch, with the tag of ["Switchable"] or the Alexa channel of {alexa="ToggleController.toggleState"}.

For example, this is how I configured mine:

Switch Tuya_Door "Tuya Door Sensor Test[%s]" <door> ["Switchable"]

but you could also use:

Switch Tuya_Door "Tuya Door Sensor Test [%s]" <door> {alexa="ToggleController.toggleState"}

Then, you can set up a Routine within the Alexa app to set the state of this to ON or OFF if your Tuya sensor is OPEN or CLOSED

Then another Routine with the opposite (open > on).

I’ve just given this a try with a Contact item, and it didn’t work, as the Contact item can’t be set by Alexa, only read from openHAB.

1 Like

Hi Confused,
I tried to configure items as suggested, but i can’t expose from openHAB to Alexa. If I scan from Alexa it doesn’t find the configured one. I’ve tried both of the ways shown, but nothing.
On myopenhab configuration I tried both to expose the item and not to indicate any.
The only thing that comes to mind, I have nginx that exposes my dashboards with Let’s Encrypt: do I have to do some particular configuration?
Any suggestions?
Thank you
Matteo

Please share your Item configuration.

I’m assuming here that myopenhab works (ie you can access your items via the openHAB iOS/Android app) and and you’ve successfully linked Alexa to openHAB.

I have try with:
Switch Tuya_Door "Tuya Door Sensor Test [%s]" <door> {alexa="ToggleController.toggleState"}
and also with:
Switch Tuya_Door "Tuya Door Sensor Test[%s]" <door> ["Switchable"]
Into “Configuration>Services” of openHAB, I have this settings:
Mode: Notifications & Remote Access
Item to Expose: nothing (but I have tried with Tuya_Door)
Base URL: https://myopenhab.org

In myopenhab I don’t access any items! But through the openHAB iOS app I see all items exposed in my item/sitemap files.

I have the dashboard exposed to https://mysite.org through nginx

You don’t need to “expose” items to myopenHAB, and you won’t see a list on the myopenHAB website.

In the openHAB app, have you set the “Remote” server, and do you see the sitemap when you are NOT connected to the same network as your openHAB server?

Have you set up the openHAB Skill in the Alexa app?

Yes, I have done all the steps you indicated, but I am still at the same point. If I scan devices from Alexa, I get this log:
[WARN] [io.openhabcloud.internal.CloudClient] - Jetty request 9760960 failed: null
[WARN] [io.openhabcloud.internal.CloudClient] - Response Failure: null
Is this something related to openHAB Cloud service?

I also tried with Google Home and I entered an item
Switch Tuya_Door "Tuya Door Sensor Test [% s]" <door> {ga = "Switch"}
but even in this case I don’t see the item exposed (in this case on Google Home).

I’m not sure what else to suggest, really, I’m afraid.

To confirm my previous comments are totally accurate, I’ve just added an Item, using exactly this syntax in my .items file:

Switch Tuya_Test "Tuya Door Sensor Test [%s]" <door> {alexa="ToggleController.toggleState"}
I saved the .items file.

In the Alexa app on my phone, I went to Devices, then tapped +, then Add Device, then Other, then Discover Devices.

45 seconds later, it has found a new item - my Switch item, which I can toggle on and off from the Alexa app.

I can then create a Routine.

My only guess is that Alexa and openHAB aren’t communicating properly, or your openHAB installation isn’t talking to openHAB cloud properly, which is why you’re experiencing issues?

You’ve not confirmed that you can successfully access your Sitemap from the openHAB app when NOT connected to your home network.

I confirm that I correctly access my Sitemap from the openHAB app when I am not connected to my home network.
News of the day: I tried to uninstall the openHAB skill from Alexa and reconnect it. Scanning still nothing. But then doing it the second time it saw the item and I was able to create the routines!!!
As a test, I entered another openHAB configuration item and retried scanning from Alexa app. The item was not found, even on the second scan. Disconnecting the skill and reconnecting it, the second scan found the “old” and “new” item. It is as if everything is not synchronized in real time. But at least with this workaround it works and I got my WiFi door/window sensor working.
Thank you!

1 Like

I’m glad you’ve managed to get it working! :smiley:

Not sure why you need to keep disconnecting and reconnecting the skill, but, if it works when you need to add a new item, you know what to do! :slight_smile: