bwssytems / ha-bridge

Home automation bridge that emulates a Philips Hue light system and can control other systems such as a Vera, Harmony Hub, Nest, MiLight bulbs or any other system that has an http/https/tcp/udp interface. This is a compact impl to run on small format computers. This is impl started from this project https://github.com/armzilla/amazon-echo-ha-bridge.
Apache License 2.0
1.45k stars 198 forks source link

Turning on X10 devices thru HA Bridge with a PC batch file. #908

Closed mikelhall closed 6 years ago

mikelhall commented 6 years ago

Hi guys. The HA Bridge is a great project and the ability to use Alexa to turn on my X10 devices just tops it. My question is, do I have the ability to access the HA Bridge to have it turn on devices thru a batch file from a PC. The reason I asked this is when something other than Alexa performs this action, it would be great for this to show up in the Alexa app as being turned on or off in the status screen. Window 10 Home Alex10 Ihouse home automation program

tuicemen commented 6 years ago

Do you mean if you send the command via RF remote or via another program. Alex10 will change the status in the bridge which shows the status change in Alexa but it no longer uses batch files. I thought I had coded for a RF signal to change status but it appears I may have overlooked that.

Bruce-Crozier commented 6 years ago

Mike, sounds like you have been successful using the ha-bridge to control your x10 modules. Would you be willing to lend me some guidance to accomplish same? So far, I have been totally unsuccessful getting past a problem that is probably simple to solve. Tuicemen offered some help but I'm still stuck. Here's what I tried: Current configuration: x10 commander on Windows 10 PC >>> CM19a >>> TM751, etc. Planned configuration: Alexa dot >>> WiFi >>> ha-bridge >>> x10 commander >>> CM19a >>> TM751, etc.

X10 commander is running on my Windows 10 PC, and it can successfully control my x10 modules such as TM751 via the USB interfaced CM19a.

I am now trying to use ha-bridge-5.1.0.jar to interface the alexa dot to x10 commander, and can't seem to define a bridge device correctly. The commnd strings http://192.168.1.130:8086/?x10command=DEVICE~sendrf~%22A1%20ON%22%27 and http://192.168.1.130:8086/?x10command=DEVICE~sendrf~%22A1%20OFF%22%27 work correctly when pasted into a web browser, controlling the TM751 On and Off, respectively.

ha-bridge appears to start corretly under java 8, and I can successfully access its configuration tool at localhost:8091 and can create bridge devices, such as:

Name = test-lamp Device Type = custom On items.target item = http://192.168.1.130:8086/?x10command=DEVICE~sendrf~%22A1%20ON%22%27 On items.Http Verb = GET Off items.target item = http://192.168.1.130:8086/?x10command=DEVICE~sendrf~%22A1%20OFF%22%27 Off items.Http Verb = GET

The 'add bridge device' works and the new bridge device is listed as: on=false,bri=false,hue=0,sat=0,effect=none,ct=153,alert=none,colormode=xy,reachable=true,XYList=[0.3146,0.3303]

Then, the alexa app on my cell phone successfully 'discovers' the new device ... However, the 'Test On' and 'Test Off' buttons in ha-bridge both fail, with a message like:

Request Error. Please look in your habridge log: error {"type"."3","address":"/lights/1","description"."Could not find url.","method_name":"/lights/1"}

My assumption is that I am somehow incorrectly configuring the bridge device, but I have tried a lot of variations with no success, and am now hoping that someone in this forum might be able to help me identify and fix the error.

Thanks, Bruce Crozier

tuicemen commented 6 years ago

Your using a HTTP command not sending a batch file which was Mikes issue. If X10commander will accept Window Commands then the process is much simpler. For your HTTP sends try removing the http verb I believe I had to do that when I had a Sonoff setup.

Bruce-Crozier commented 6 years ago

Thanks tuicemen. Mike, have you looked into IFTTT as a way to get alexa to do what you need?

tuicemen commented 6 years ago

@Bruce-Crozier Do you have the Map type (Legacy) set to HTTP Device ? I've just tested a http call using the 5.2.0rc20 build and it does work thought HA-Bridge says it failed. that may be a bug as I never got that before I also may not have everything set just right yet.

mikelhall commented 6 years ago

First, thanks for the response to my question. Second, what I am looking for, is a way to maybe accessing the HA Bridge test buttons thru some command so the status would appear in the Alexa app. If I use a x-10 remote to turn on a light, I would like to create a batch file or executable to also use the HA Bridge to turn the light on, much like Alexa. This will give the Alexa app that this light was issued an on command. This status would give me an indication that timers or macros have fired properly.

tuicemen commented 6 years ago

I believe it may be possible to create a batch file to trigger ha-bridge following the readme info. As I can trigger devices that are not X10 from Alex10 using codes from the readme. This may be a bit involved for a simple batch file but since your using iHouse you might try doing it with AutoHotkey. I'll see about getting Alex10 to sync RF received commands to the HA-Bridge as it looks like you may also be using it. this would then display the info in the Alexa app.

mikelhall commented 6 years ago

Hi @Bruce-Crozier. I used Tuicemen's Alex10 to get me started in the right direction. Looking at the Bridge configuration after setting up with Alex10, I was able to see how it worked (Thanks Tuicemen). I went from Tuicemen's activation to a batch file, then changed to AutoHotKey to hide command windows popping up on my screen. I currently using a program called Ihouse. I use macros to turn my lights on/off/dim. I'm not using the HTTP. I am going thru the C:\Program Files\AHSDK\bin\ahcmd.exe command to achieve this. Alex10 by Tuicemen, is great for the initial setup and restarting the Bridge. I also had to deal with the Anti-virus program and had to make the files I am using exclusive.

mikelhall commented 6 years ago

Wow Tuicemen! Thanks! Is the readme.info located in the HA Bridge program, or the Alex10 program? I'm not at the computer the program is on.

tuicemen commented 6 years ago

Glad I was able to get you pointed in the right direction with Alex10. the readme is here: https://github.com/bwssytems/ha-bridge/blob/master/README.md

tuicemen commented 6 years ago

The AHP SDK has some limitations with reporting commands sent from other programs which use the SDK or from AHP itself. Hopefully that doesn't prevent you from accomplishing what you want.

mikelhall commented 6 years ago

I guess https://127.0.0.1:8080 shows a way to activate the on/off/dim thru the bridge itself, like Alex? Does Alex10 activate thru the bridge or by way of ahcmd.exe?

tuicemen commented 6 years ago

For none X10 Alex10 uses the bridge for X10 it uses the ahscript.dll which is what the AHCMD.exe uses The bridge can't call x10 directly.

mikelhall commented 6 years ago

Right. I'm sorry. What I should have typed is, When you use Alex10 on/off switch on the console, does this switch send a command to the HA Bridge, which in turns send the command thru Alex10 ahscript.dll to turn on/off/dim an x10 device, or does Alex10 turn the x10 device on/off/dim directly?

tuicemen commented 6 years ago

Alex10 turns on/off/dims the x10 device directly it then sends the device update info to the bridge. with the bridge device status updated Alexa sees the status change. https://github.com/bwssytems/ha-bridge/blob/master/README.md#update-a-device

mikelhall commented 6 years ago

Okay. I found this. PUT http://host:port/api//lights//bridgeupdatestate I assume this is in Python, but I figure maybe this is how it should look (somewhat) http://my computer ip and port used/api/the long numbers/device description/the number to the left of the device description/bridgeupdatestate { "on" : true,}

mikelhall commented 6 years ago

Hi @Bruce-Crozier. There is a Youtube video that shows how to set up the X10Commander with the HA Bridge. https://youtu.be/Kj5SxV2616U

mikelhall commented 6 years ago

Okay. I tried a curl -H "Content-Type: application/json" -X PUT -d "{"on":true}" http://localhost:8080/api/user/lights/23/state. This appears to have activated the on script in HA Bridge. I see the x10 Front lobby light ON status in Ihouse and Alex10, but no status change in the Alexa app on my Iphone. I tried bridgeupdatestate, but no action ocurred. I'm at a loss here.

tuicemen commented 6 years ago

Did you try closing and reopening the Alexa app to see if it refreshed correctly. I don't have to do that but there were some issues with AWS experienced Friday that affected older devices.

mikelhall commented 6 years ago

I believe I'm missing something, Tuicemen, as that the state did not change in the Alex10 active status box. It did show up in the bottom box of Alex10. The curl file I posted above is the only command I ran in the Command Prompt. I did not receive a success status after the command ran. Only these symbols [ ].

tuicemen commented 6 years ago

I'm not sure why the state wouldn't change if Alex10 detected the command and turned off or on the device. What version of the bridge are you running?

mikelhall commented 6 years ago

Its the one that came with Alex10, which I believe is 5.1.

tuicemen commented 6 years ago

If you change the device state with Alexa does that get reflected in Alex10?

mikelhall commented 6 years ago

Yes. Alex10 works great. Just an issue on my end. I had to change from bridgeupdatestate to state only to get the curl program to talk to HA Bridge. Is this an issue?

mikelhall commented 6 years ago

Okay. Got it working by adding the bri and level into the equation. That got the curl program working. Now, since curl works in the command prompt, how does one implement it outside the command prompt? Figured it out. Found an equivalent AHK program to the curl. Works perfectly.

mikelhall commented 6 years ago

WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1") ;~ WinHTTP.SetProxy(0) WinHTTP.Open("PUT", "http://localhost:8080/api/user/lights/33/state") WinHTTP.SetCredentials("", "x", 0) WinHTTP.SetRequestHeader("Content-Type", "application/json") Body := "{'on':false, 'bri':0}" WinHTTP.Send(Body)

mikep809 commented 6 years ago

Hi New 5.2 bridge works fine, but will not discover new devices. Java is allowed traffic. Brudge test works fine. I has all my x10 devices working fine prior, any ideas? Do i need the phillps hue skill running ? The new version will not work without a bridge. Appreciate your help.

Thxs

mikelhall commented 6 years ago

Hi mikep809. I am currently using version 5.1.0 with Tuicemen's Alex10. This has so far done really well for me. I have not upgraded to 5.2 until Tuicemen mentions it in his forum. I program by examples where Tuicemen's skills are much higher than mine will ever be.