genielabs / HomeGenie

HomeGenie, the programmable automation intelligence
https://homegenie.it
GNU General Public License v3.0
388 stars 154 forks source link

Virtual UPnP devices: WeMo emulation tests for Amazon Alexa/Google Home integration #355

Closed genemars closed 5 years ago

genemars commented 5 years ago

Continuing from thread from #353 .

genemars commented 5 years ago

@mralapete can you describe the procedure to add a device to Alexa? This might helping me figuring out what to do.

mralapete commented 5 years ago

ok.You can either log into your Amazon Alexa account and select Devices and Discover or request Alexa to discover a device using voice command.

Not sure if this will help but some work that a previous HG user did on the subject a while back

https://github.com/davidwallis3101/HomegenieEchoBridge

This might give you an idea what approach to take

mralapete commented 5 years ago

Also this is where it was left before the old forum was closed down http://old.homegenie.club:8080/www.homegenie.it/forum/index2513.html?topic=1715.0

genemars commented 5 years ago

I am now trying a command line tool (ouimeaux) that can discover and use WeMos. So I've been able to make the virtual UPnP device work with this utility. I hope it will also work with Alexa =) Use the new hgx attached here and HG v1.2-stable.32. 1000-UPnP_Test_for_Alexa_hgx.txt

tuicemen commented 5 years ago

I think I've started to get past the worse of this virus though it is still in my eyes. I'll attempt to update HG today and install the HGX test file. I have a few Berklin modules already being detected by Alexa so I cleared the discovered devices and disabled the wemo skill then told Alexa to rediscover I'm not sure why she is still seeing my wemo devices so I'll have to do some digging to get those so their not discovered be fore I get testing this or my tests will be flawed.

genemars commented 5 years ago

Ok @tuicemen I've got a better HGX to test. This one adds the UPnP Emulator option to the Options/Features dropdown of any switch or light module. Simply activate this flag for every switch and light that you want HG to make discoverable as stand-alone UPnP device (a fake Belkin WeMo type).

1000-UPnP_Emulator_v1r1.hgx.txt

tuicemen commented 5 years ago

@genemars ok this is causeing my brain to go back into a fog I started the program added a couple of devices and selected the alexa option when I attempted to add the alexa option to the second device the option wasn't there so I figured I'd just discover devices with Alexa nothing new was found so I went back to HG and the program wasn't activated so I reactivated it went to be sure the device I'd selected prior was alexa enabled and it wasn't so tried to check that option and it is no longer available

tuicemen commented 5 years ago

ok maybe My brain is still not fog free! Nope I'm sure it isn't now! missing all kinds of stuff that a 4 year old would have done. I've still not got Alexa to discover anything new but may be by days end things will start to comeback to me. So as of right now don't take my findings to serious. ;)

genemars commented 5 years ago

I've integrated this functionality in the new v1.2-stable.33 release. Open HG, open a module options (eg. the "Porch Light" in the demo dashboard) and then from the "features/options" list select "UPnP Emulation". Activate the "Emulate UPnP device" option and save.

tuicemen commented 5 years ago

Downloading now! is the 1000-UPnP_Emulator_v1r1.hgx still required? should I delete it?

genemars commented 5 years ago

@tuicemen you can delete it since it's already present in r33 (under Devices and Things category).

tuicemen commented 5 years ago

Ok updated changed one of my Zwave switches to emulate UPnP saved the info then opened my Alexa app to discover devices and still no new devices are seen am I missing a step? Is there a specific switch or light type this has to be applied to?

tuicemen commented 5 years ago

My HG is running on Port 8080 should it be on 80?

tuicemen commented 5 years ago

well that wasn't any help oh wait my UPnP isn't enabled,.... Well that (enabling didn't help) Maybe a reboot?

genemars commented 5 years ago

@tuicemen UPnP will work regardless of the port being used for the UI. I also tried Alexa app and it cannot find a thing not even my Hue Bridge, nor the Smart TV. Maybe using a Echo device gives a better result? Have you in any case succeed in using the Alexa app with something?

tuicemen commented 5 years ago

The Alexa app works and sees HA-Bridge configured devices and Broadlink RM devices. I also use the PC app https://alexa.amazon.com/spa/index.html#cards which works for discovering but doesn't have the options the phone app has. I also tried just asking alexa to discover devices with the same result.

genemars commented 5 years ago

@tuicemen no need to enable UPnP interface to use this feature. Anyway to verify that the UPnP devices are created you can use a tool like gupnp-universal-cp for linux (part of gupnp-tools). EDITED TEXT BELOW Ok... I'll have a look at how to make Alexa app work with HA Bridge so I can eventually figure out what to do to make this work.

tuicemen commented 5 years ago

you might want to look at https://github.com/davidwallis3101/HomegenieEchoBridge Too which @mralapete pointed to earlier. I had originaly thought of using it for Alexa but the bridge hand support for the Broadlink which allowed capturing and sending any IR or RF signal which enabled X10 security arming and disarming possible. davidwallis stated it was compile basically the same as HA-Bridge.

genemars commented 5 years ago

Ok @tuicemen I had a brief look at the HomegenieEchoBridge code and I think it has a similar approach and, correct me if I am wrong, this require a real Echo device connected to the local network. So maybe the new HG UPnP emulation will already work with a real Echo/Home device. If so I don't care about making it work with the Alexa app since this require the user to register or put everything in the cloud. There isn't a single Alexa Skill that do not require the user to register to some sort of cloud service.

tuicemen commented 5 years ago

I do not have hubs, just a couple of Amazon Dots and a Google Home mini which are connected to my wifi. the Alexa App needs to see the devices so the amazon devices can activate them. I can turn on /off X10 lights in the Alexa App or an Alexa Dot no extra skills required. if your looking at turning HG into an Alexa or Google Home device its self then I misunderstood your thinking. and we'd need to talk to HG I believe there are some projects for this on GitHub.

tuicemen commented 5 years ago

The devices showing up in the app lets you know if the Alexa devices can see them after initial discovery and connection the app will tell you if these devices are still on line if they're no seen as online Alexa devices can't control them. I've not done to much in the way of HA with my Google mini though I did manage to get it working with one of my old PC programs using the Samsung SmartThings developer portal. this could be done with HG as well however for most users it would be a bit much to setup.

genemars commented 5 years ago

@tuicemen I am just trying to follow same approach as HomegenieEchoBridge and HABridge (emulating UPnP devices like PhilipsHue bridge or Belkin WeMo devices). How did you make Alexa control your x10 devices? Is this still by using HABridge? Did you have to do some configuration of any sort in the Alexa app?

mralapete commented 5 years ago

The whole point of this exercise was to control devices without adding the overhead of the HA Bridge on the system. This was not about Broadlink nor the HA Bridge. The idea was to integrate this into HG.

Changing the chosen device settings in Features/Options to UPnP Emulation and saving but that setting is not being retained.It is reverting to the previous settings once you close and reopen the device settings. That may be one reason why Alexa is not discovering the device.

tuicemen commented 5 years ago

How did you make Alexa control your x10 devices? Is this still by using HABridge? Did you have to do some configuration of any sort in the Alexa app?

x10 control was done in HA-Bridge by pointing to the HG API for each device on/off/dim call. Nothing needed to be done in the Alexa app HA-Bridge told Amazon the devices configured then once a command was given to the Alexa app it forwarded the info to HA-Bridge so it could then tell HG what device to turn on/off/dim

@mralapete I believe the info is saved however when you open the device options it displays the first feature option even if nothing was saved for it. Maybe HG can handle more then one feature option for each device I've never tried that. this issue that your pointing to is the one simular referenced in #330 for security modules But I can indeed confirm the settings are saved for the security modules

mralapete commented 5 years ago

@tuicemen We’ve already done the HA Bridge thing in HG. The idea was to integrate the whole process into HG so HG users didn’t have to worry about installing a 3rd party software to achieve this.

Gene will need an Amazon Echo to test his concepts. He is trying to develop this concept in the dark.

I know why the settings are not being retained in the devices. We’ve come across this before. They need to be retained because they depend on the program they are assigned to

I just hope some of the more experienced programmers come back on board to help with the testing. HG really needs them.

You really should concentrate on recovering from your illness. HG is a marathon not a sprint. No quick fixes.

tuicemen commented 5 years ago

@mralapete I realize what Gene is attempting to do And I like his progress thus far and I'm not suggesting he look a HA-Bridge to implement it HomegenieEchoBridge and HABridge are eventually the same except HomegenieEchoBridge attempts to use HGs IP and Port integrating all HG devices. I believe Gene is on the right track. Sorry If you feel I'm a distraction. But you told me Alexa was merely a toy and you didn't use it. I on the other hand use it regularly and don't feel it is just a toy however it has a long way to go before it becomes main stream.

mralapete commented 5 years ago

@tuicemen while other HG users may not be commenting here they are following progress. I do understand exactly what Gene is trying to do. I'm also pointing out to him what progress had been made on this subject so he doesn't duplicate effort.

We need to keep the testing ordered as has been done in the past. It is then easier for others to follow what works and what doesn't so Gene can build on what does. The "best boy" in the class approach doesn't work for anyone.

My feelings on the Alexa is not relevant here. Why you even mentioned here is beyond me. Other HG users have requested this function to be integrated into HG in the past couple of years and others have even managed to make some progress on this. Hopefully Gene can use some of this work to develop a solution.

Remember this GitHub is purely about HG. There are other forums out there should you wish to discuss matters outside of this subject.

tuicemen commented 5 years ago

Gene asked how I was doing the X10 bit and how it was setup , I answered that? If you or others feel my answer was an attempt to side track Genes HG work then I obviously missed something. Your right your feelings on AI voice assistants has no barring on this, the fact that you don't use it does. What is written about things and how they actually work, 9 times out of 10 don't match up. Gene stated he didn't wish users to have to use the Alexa App or Skills and I agree with that which is I why I pointed to the web interface which many (even long time Alexa users) don't know exist. From now on I'll not comment unless specifically asked a question in the thread.

mralapete commented 5 years ago

@tuicemen best to keep this on topic,

integration of Alexa device control within HG without the need for an external server like HA Bridge. I'm sure Gene knows what approach to take with this and will do so in his own good time. The external HA Bridge approach has already been well documented and implemented and can be seen in the old homegenie forum.

mralapete commented 5 years ago

@genemars this is interesting. It looks like integration of Alexa in HG was already achieved.

Would this solution work in your current release.

https://homegenie.club/t/amazon-alexa/63/53

tuicemen commented 5 years ago

Ok @tuicemen I had a brief look at the HomegenieEchoBridge code and I think it has a similar approach and, correct me if I am wrong, this require a real Echo device connected to the local network

I decided to give this HomegenieEchoBridge another try, now that I have a little better understanding of how HG works and how to install interfaces and such. It does work and with out the need for a real hue hub on the network, as I suspected. It does take a couple of HG service restarts (and maybe even a reboot) before it actually kicks in. It detects all HG X10 and Zwave device modules (as well demo modules which I'm not fond of) so it still needs work there. Possibly your work with enabling Virtual UPnP devices and allowing to select which to use could be utilized there. The other drawback is this doesn't work with Google Home. However Google has decided to go the cloud route for there HA control eliminating local bridges. That may put a kink in your plans to include Google in HG.

mralapete commented 5 years ago

@tuicemen so what procedure did you carry out to get this enhancement to work. I'm assuming that there is no 3rd party software or hardware involved here. Maybe you could outline exactly what you did for the benefit of other users.

mralapete commented 5 years ago

@genemars just came across this GitHub using Fauxmo scripted in Python and proven to work with Alexa. When you get a moment coukd you have a look at it and see what you think. https://github.com/makermusings/fauxmo

tuicemen commented 5 years ago

@mralapete best to keep this on topic besides I'm still testing.

tuicemen commented 5 years ago

@mralapete this looks very simular to what Gene is working on https://hackaday.com/2015/07/16/how-to-make-amazon-echo-control-fake-wemo-devices/ However this is very old and much has changed with Amazon and Alexa since this article was published. The python script may have some usable info.

mralapete commented 5 years ago

@tuicemen we just need to know how you got Alexa to discover your HG devices using Genes recent addition to v34. There's many hacked versions of a solution out there but no single one seems to work for everyone. You mentioned you needed to reboot or restart the service a number of times for this to happen and again I'm assuming you're just testing with HG and an Alexa.

tuicemen commented 5 years ago

@mralapete please re read my reply to Gene. I didn't state I had Alexa working with Genes recent addition to v34. I used the HomegenieEchoBridge interface to test his theory of it requiring an external Alexa hardware device (Hue Hub, I assume was his meaning).

However it does work on Genes recent build but also worked on the build prior. I'm not convinced this is what Gene is looking for as it doesn't use Virtual UPnP devices. It would be cool to integrate that if possible strengthening it thought. The Philips hue integration has issues as many pointed out with HA-Bridge

genemars commented 5 years ago

It seems that the UPnP virtual devices (which emulates WeMo Switches) will only work with 1st generation Alexa. Also other approaches like Philips Hue Bridge emulations (eg. HomeGenieEchoBridge) will probably not work if Alexa 2nd generation is used.

They are purposedly forcing users to register with third party (vendors) service providers such as the WeMo website or the Philips Hue website. I believe that the user should be free to choose if routing smart devices activitity through the internet.

So I can consider this task closed because I am not going to create further hacking to achieve this... I'd rather create necessary services and Skills/App to make HomeGenie interoperate with Google or Amazone the official way.

However the fact that now HG can emulate and implement UPnP devices and services out of the box is a very good thing for all other non-Amazon and non-Google solutions that aim to create discoverable and interoperable services on a local network that not require the user to expose his smart devices to the internet.

tuicemen commented 5 years ago

@genmars Actually all my amazon devices are second gen. Which explains the issue for me with the UPnP. However the HomeGenieEchoBridge as I stated can and does work in HG. I feel your right though the skill most likely would be the best approach and less or no hacking of existing code.

mralapete commented 5 years ago

Yes the way SSDP is being handled by the 2nd generation of Echo seems to be the problem. I asked someone who owns a 1st generation Echo to run HG on a Pi to test your code. It looks like he succeeded but this will not be a solution going forward.

@genemars Still working on Fauxmo code as it seems there is a solution to the problem. I'll report back with results soon. Copy of GitHub issue and resolution on the following link. Looks like a change in ST definition may be the way foreword here. A bit of a hack in this case but it may work. https://github.com/n8henrie/fauxmo/issues/38

mralapete commented 5 years ago

@genemars in the meantime the HA Bridge server could be off loaded to a second Raspberry Pi for those looking for Alexa functionality working on that platform. Simplest and cheapest alternative all round.

mralapete commented 5 years ago

@genemars there was mention of introducing Broadlink RM hardware into HG but you are aware of GDPR issues under EU law that have caused a malfunction. https://vn-my.com/watchvideo/how-broadlink-were-almost-ruined-eWMiShhQL5s.html

tuicemen commented 5 years ago

@mralapete the issues with GDPR and Broadlink do not stop EU users from exploiting the Broadlink RM. there are several ways arround this but hopefully shortly (as your linked video points out) these issues will be resolved.

Also If users are just looking for simple Alexa control of already controllable devices in HG, then ha-bridge isn't needed so no extra Pi required. Simply install the HomegenieEchoBridge interface.

mralapete commented 5 years ago

@tuicemen not really bothered now that Gene has opened up the UPnP library in HG. Loads of easier options available now. Glad you got sorted.

mralapete commented 5 years ago

@genemars just to update on this thread. The HomeGenie EchoBridge is actually functioning correctly in your latest release v35 without the need for any 3rd party solutions like HA Bridge. It is discovering HG devices via Alexa and turning them on/off. You may want to include this in the stock HG install as HG doesn't restore user defined MIG programs which means every time you update and restore you need to reinstall HG EchoBridge.

genemars commented 5 years ago

HG restore functionality will restore MIG programs only if they are installed from the package repository (options->maintenance menu in HG UI). Submit HomeGenie EchoBrigdge package by making a pull request here: https://github.com/genielabs/homegenie-packages This way it can be installed from homegenie package manager and also restored correctly.

mralapete commented 5 years ago

@genemars I don’t have write permission for that

tuicemen commented 5 years ago

The latest update to 36 kept the HG echo bridge and I didn't need to re-install or re-enable. Nice! However I have one issue which I'm not sure is HG or the interface or both. If security is enabled on HG (passworded) the echo bridge stops working removing the password enables the echo bridge to work again

Bounz commented 5 years ago

This is because HGEchoBridge communicates with HG via HTTP API and doesn't use Basic Auth.

tuicemen commented 5 years ago

@Bounz thanks, looks like another enhancement for the Echo Bridge is needed, or users to run two instances of HG one with Echo Bridge one with security enabled (if they wish remote access).