rooi / homebridge-lightwaverf

LightwaveRF plugin for HomeBridge
9 stars 7 forks source link

Can this be made to work with the new manager.lightwaverf.com web portal? #5

Closed Cardo1 closed 8 years ago

Cardo1 commented 8 years ago

Those of us that are new to LightwaveRF have new accounts that don't work with the old lightwaverfhost.co.uk web app, instead we have to use the new manager.lightwaverf.com portal. Can the plugin be updated to work with this?

rooi commented 8 years ago

Yes, probably. I don't have an account, though. Perhaps you can help? I'll be back from vacation in about 2 weeks, so then I've time to look into it.

Cardo1 commented 8 years ago

I'll help in any way I can. Give me a shout when you're back from holiday. In the meantime, enjoy your holiday!

gizbod commented 8 years ago

Any update on this? I'd be willing to help too but my knowledge in This is very limited. Thanks

rooi commented 8 years ago

Hi,

Could you try if this project works till some extent?

https://github.com/ollieparsley/node-lightwaverf

Particularly if the udp broadcast is supported on the new link, meaning that you can turn on/off lights using room and device id's as integer. If this works it should be possible to fully support the new link (but your help is still needed since I've got the old version).

gizbod commented 8 years ago

Thanks for responding rooi, I've looked at the link you posted but unfortunately I don't know enough about how all this works to understand how to set it up. (I've just started learning) i don't know what file to write the code in and I have just installed homebridge, not sure if node is something different? Sorry I'm really new to this.

gizbod commented 8 years ago

Actually I did install node.js so I'm assuming that is what it means.

Cardo1 commented 8 years ago

Rooi, I also have the new Lightwaverf link. I'll have a look at that package and let you know how I get on.

Cardo1 commented 8 years ago

I have been struggling somewhat with the package above and the pauly one linked from that page, though I suspect it's a config issue. I have however managed to control my lights from the CLI using the commands from http://lightwaverfcommunity.org.uk/forums/topic/udp-from-linux-command-line-with-2-91/

I first had to register my machine, I think this is the command that finally did it: echo -ne "001,!F*p\r" | nc -u -w1 192.168.2.189 9760

I am now able to turn lights on and off using: echo -ne "001,!R1D1F1\r" | nc -u -w1 192.168.2.189 9760 and changing the R, D and F* to suit.

Hope this helps.

rooi commented 8 years ago

@Cardo1 Thanks, that sounds promising.

The only step that is get the device list from the new lightwaverf site. Perhaps you are willing to share your login details so I can try to hook it up (email?). Alternatively you can try to get the page's source after you login so we can see if it lists all devices and rooms.

Hopefully there still is an easy way to get de device list, but otherwise it is always possible to add the mapping to the homebridge configuration file manually

Cardo1 commented 8 years ago

I've had a look at the page source and there is some info there, but to be honest I'm not sure what specific items you're looking for, so if you let me know an email address I'll provide you with my login details so you can have a look yourself.

rooi commented 8 years ago

@Cardo1 you can email me at roy.arents@gmail.com I'm not sure if I can work on this tonight, but perhaps later this week. I'll try not to turn your lights on/off by accident ;)

gizbod commented 8 years ago

Hey rooi, have you had any time to look at this?

JangoBritt commented 8 years ago

Watching this thread eagerly too. I have a bit of coding experience, so can help with any debugging required.

Cardo1 commented 8 years ago

The good news is the new web manager has been updated and now provides the room IDs in the page source, so Roy should be able to parse that to build a config file.

gizbod commented 8 years ago

That is good news. I noticed the new web manager went fully live yesterday. Didn't realise it was only a beta up until now. The old one may go offline now?

rooi commented 8 years ago

I just pushed a new version to git. Could you please test it? I’ve quickly updated the realm, but perhaps you can clarify it a bit using you clean setup?

Update the plugin using:

sudo npm install git://github.com/rooi/homebridge-lightwaverf.git

You should use something like this in your config.json

"platforms": [ { "platform" : "LightWaveRF", "name" : "LightWaveRF", "ip_address": "10.0.1.30", "devices": [ { "roomId": 1, "roomName": "LivingRoom", "deviceId": 1, "deviceName": "MyLight", "deviceType": "D" }, { "roomId": 1, "roomName": "LivingRoom", "deviceId": 2, "deviceName": "MyLight", "deviceType": "D" } ] } ]

Start homebridge.

gizbod commented 8 years ago

Nice one Rooi. Tested and working. Now have control of my lights through Siri.

tramapoline commented 8 years ago

Hi - I tried a fresh install today - when I configure the devices (I have a new Link) it errors as follows:

[5/23/2016, 4:11:55 PM] [LightWaveRF] Fetching LightWaveRF switches and dimmers... module.js:338 throw err; ^

Error: Cannot find module 'prompt' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:286:25) at Module.require (module.js:365:17) at require (module.js:384:17) at getLights (/usr/local/lib/node_modules/homebridge-lightwaverf/index.js:81:24) at Object.LightWaveRFPlatform.accessories (/usr/local/lib/node_modules/homebridge-lightwaverf/index.js:118:5) at Server._loadPlatformAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:333:20) at Server._loadPlatforms (/usr/local/lib/node_modules/homebridge/lib/server.js:277:16) at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:71:36) at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)

If I stick in an email and pin, it doesn't error but clearly doesn't pull in the devices ..

rooi commented 8 years ago

@tramapoline could you please post your config.json (remember to erase passwords and such)? Thanks!

tramapoline commented 8 years ago

Sure:

{ "bridge": { "name": "Homebridge", "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-199" },

"description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",

"platforms": [ { "platform": "LightWaveRF", "name": "LightWaveRF", "ip_address": "192.168.1.191", "devices": [ { "roomId": 6, "roomName": "Office", "deviceId": 1, "deviceName": "Office Lights", "deviceType": "D" }, { "roomId": 7, "roomName": "Tom's Bedroom", "deviceId": 1, "deviceName": "Tom Bedroom Lights", "deviceType": "D" } ] }
] }

rooi commented 8 years ago

@tramapoline I cannot reproduce the problem when I use your config.json and it seems to be correct indeed. Can you post the rest of your console output as well? Perhaps I can derive something from that.

What's your nodejs version by the way?

tramapoline commented 8 years ago

Console output as follows - my node version is 4.0.0.

Thanks!

pi@raspberrypi ~ $ homebridge start * WARNING * The program 'node' uses the Apple Bonjour compatibility layer of Avahi. * WARNING * Please fix your application to use the native API of Avahi! * WARNING * For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node * WARNING * The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi. * WARNING * Please fix your application to use the native API of Avahi! * WARNING * For more information see http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister [5/23/2016, 4:57:52 PM] Loaded plugin: homebridge-lightwaverf [5/23/2016, 4:57:52 PM] Registering platform 'homebridge-lightwaverf.LightWaveRF' [5/23/2016, 4:57:52 PM] --- [5/23/2016, 4:57:52 PM] Loaded config.json with 0 accessories and 1 platforms. [5/23/2016, 4:57:52 PM] --- [5/23/2016, 4:57:53 PM] Loading 1 platforms... [5/23/2016, 4:57:53 PM] [LightWaveRF] Initializing LightWaveRF platform... [5/23/2016, 4:57:53 PM] [LightWaveRF] LightWaveRF Platform Plugin Version 0.0.4 [5/23/2016, 4:57:53 PM] [LightWaveRF] Fetching LightWaveRF switches and dimmers... module.js:338 throw err; ^

Error: Cannot find module 'prompt' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:286:25) at Module.require (module.js:365:17) at require (module.js:384:17) at getLights (/usr/local/lib/node_modules/homebridge-lightwaverf/index.js:81:24) at Object.LightWaveRFPlatform.accessories (/usr/local/lib/node_modules/homebridge-lightwaverf/index.js:118:5) at Server._loadPlatformAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:333:20) at Server._loadPlatforms (/usr/local/lib/node_modules/homebridge/lib/server.js:277:16) at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:71:36) at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)

rooi commented 8 years ago

Just tried on my raspberry pi using the same setup (same nodejs version) and still no problems over here.

Are you sure you've edited the correct config.json? It seems to crash a line 118 which only should be reached when an email is specified but the pin is missing (if I'm correct).

Perhaps you can add some console logs to at the end of function LightWaveRFPlatform(log, config) and at the start of the getLights = function()

that.devices should be defined and it should not be able to reach line 118

Otherwise try to stop homebridge, delete the persist folder, remove homekit configuration on your devices and such?

tramapoline commented 8 years ago

I am pretty sure - if I add in an email and pin that error doesn't happen so it looks like the right file.

Not sure what you mean by add some console logs - do you mean put in extra lines to show progress or something more specific?

I tried your last suggestion as well but no good - it still is looking for the prompt module.

gizbod commented 8 years ago

I have now set up all my lights with this set up using the new link. For me it went pretty straight forward. I updated the plugin as per readme and updated my config file. I encountered one error where the lights showed as accessories in HomeKit and commands were sent but no lights on. This was later found to be that the room id's were not correct in the config file. They are not in order as they appear on your app. I believe they are in order they were created and if you have deleted rooms that number will no longer exist.

Also I found when updating the plugin it installed a new one in another location to my original plugin and the old one was overriding the new one. So I had to go into the directory where my other plugins were by using cd command. Then update the plugin from there. This may have just been from my set up but just in case other find this issue.

rooi commented 8 years ago

@tramapoline very strange. Your right I meant clone the repository and add some more debug output to figure out what is going on. Have you seen the comment of @gizbod about the other location, perhaps something like that is happening with your setup?

tramapoline commented 8 years ago

I worked it out .. when I ran the plugin install I had missed the -g from the install .. so it wasn't installing correctly as gizbod suggested .. thanks both for your help .. this is very good!

rooi commented 8 years ago

Great! Have fun

gizbod commented 8 years ago

👍🏽No problem

gizbod commented 8 years ago

Update for anyone interested. This is confirmed working for Lightwaverf plug sockets as well as dimmers

JangoBritt commented 8 years ago

"No email or pin specified. The server configuration (rooms, devices, etc.) cannot be obtained"

Hello, the above config.json doesn't work... there's no section for entering email & PIN, can you advise the syntax?

Also, the LighWaveRF Web App doesn't use a PIN, I assume that's for Password? I tried just adding an "email" and "PIN" line in the JSON file, and that didn't do the trick.

Also, DeviceType "D" I assume means Dimmers... what's the switch for Sockets? "S"? Heating? Energy Monitor?

Cheers!

tramapoline commented 8 years ago

You might want to post your config.json - if you are using a new link you need this in the config only:

"platforms": [ { "platform": "LightWaveRF", "name": "LightWaveRF", "ip_address": "10.1.1.1", "devices": [

This means rather than discovering devices you have to explicitly define the devices .. and then the code is firing commands at the link unit not the web interface.

JangoBritt commented 8 years ago

So the error message "No email or pin specified. The server configuration (rooms, devices, etc.) cannot be obtained" doesn't necessarily mean that it's borked, just that you have to specify the devices manually?

When I run a command on my phone, using the Eve app, my homebridge reports the line:

Sending message: 001,!R67717D199375FdP32|

This should be sending On to my Office Lights, but no joy. The app reports "HomeKit reported a communication failure. Please try again"

here's my config.json:

{ "platform": "LightWaveRF", "name": "LightWaveRF", "ip_address": "192.168.1.124", "devices": [ { "roomId": 67719, "roomName": "Thomas", "deviceId": 200235, "deviceName": "Lights", "deviceType": "D" }, { "roomId": 67719, "roomName": "Thomas", "deviceId": 193790, "deviceName": "Monitor", "deviceType": "S" }, { "roomId": 67717, "roomName": "Office", "deviceId": 191659, "deviceName": "LEGO Street", "deviceType": "S" }, { "roomId": 67717, "roomName": "Office", "deviceId": 199375, "deviceName": "Lights", "deviceType": "D" }, { "roomId": 67717, "roomName": "Office", "deviceId": 191657, "deviceName": "Display", "deviceType": "S" }, { "roomId": 67718, "roomName": "Nursery", "deviceId": 191661, "deviceName": "Lights", "deviceType": "D" } ] }

tramapoline commented 8 years ago

OK - I don't think Rooi has got it talking to the actual web interface yet, the code is poking the commands at the link device. This means you have to use the 'old school' device numbers not the ones referenced in the new manager .. so if you look at my config for a room:

"roomId": 6, "roomName": "Office", "deviceId": 1, "deviceName": "Lights", "deviceType": "D"

You see it is more basic in numbers - I had to manually send the codes to work out what these were .. normally they will be in the order you add the rooms but not necessarily so it is a bit trial and error.

See if you can work out one of the rooms and see if this works and then go from there. But I think it means your config is correctly sending, just the wrong device and room ID.

JangoBritt commented 8 years ago

flippin'eck... so I have to kinda guess the room and device id?

Is there any way to find those? How would the Link even know about rooms, if not for the Web interface?

Cardo1 commented 8 years ago

The room ID can be seen in the source of the individual room pages in manager.lightwaverf.com.
You're looking for this line: a data-mac="**" data-room_number="3" data-zone_id="11111" data-room_id="11111" id="room_all_off" title="Switch All off" class="btn btn-red">All off</a

The data-room_number- is the number you're after. In the above case, the room ID is 3.

The device IDs are sequential and are in order on the room pages.

JangoBritt commented 8 years ago

aah I see... from the source code, not from the actual device HREF link.

JangoBritt commented 8 years ago

How would I go about checking this manually, rather than having to commit a new config.json and restart homebridge each time?

tramapoline commented 8 years ago

If you have a windows machine, https://packetsender.com/ can let you send the packets before you commit it to the config. You set it up to send to the link device on 9671 and set it to listen for the replies on port 9671.

If you are running it from the *nix box then this post is the most helpful:

http://lightwaverfcommunity.org.uk/forums/topic/udp-messages-in-bash/

You will need to register your Windows machine first by sending 001,!F*p and hitting the button the link device when it flashes. It looks like you are already registered on the box running Homebridge so you shouldn't have to do it.

After that you can send commands pretty much the same way the Homebridge is:

006,!R5D2F0

The number before the comma is just a sequential id so id doesn't matter what it is - the other parts are R for Room, D for Device, F for Function (0 is off, 1 is on) .. if it is a dimmer the Homebridge sends ON commands as

001,!R5D1FdP32

32 = 100% 24 = 75% etc.

gizbod commented 8 years ago

I found with the device type ni matter what I put in there HomeKit thinks the device is a dimmer. Had to set them in different rooms and use different names etc otherwise when I say turn living room lights off the TV turns off.

rooi commented 8 years ago

@JangoBritt you can also try this package to send the udp messages and find out which ids belong to your lights: https://github.com/rooi/node-lightwaverf I still want to add homebridge api 2.0 functionality to streamline the setup procedure.

@gizbod I think this an error in siri/homekit. I've noticed that it is very picky about the words you use. On missing or misunderstood word can cause it to do nothing or switch of everything. Could you try: "Turn of all the lights in the living room for example" (I have siri in Dutch so I don't know the exact phrase)

JangoBritt commented 8 years ago

@Tramapoline may have hit on something there. I am using a Mac... As this has never worked before, I suspect I need to pair with the link still

JangoBritt commented 8 years ago

That's done it!

in a new Terminal screen, I ran echo -ne '100,!F*p.' | nc -u 192.168.1.124 9760 which started the link LED flashing. Having then approved the link, I was able to send commands from my Eve App.

Now final hurdle: with the "deviceType": "D", everything appears as a Dimmer.

Does anyone know what the other deviceType codes are?

tramapoline commented 8 years ago

I have a few plug in Lightwave Switches .. the device ID that works seems to be 'S' - which may be for Socket. The only difference I have seen watching the log for homebridge (which on my RaspberryPi is /var/logs/homebridge.log) is that Dimmers will send on commands as percentages as I described earlier, while Switch/Sockets send just F1 for On ..

I don't have any heating stuff so can't comment if this is a different device type ..

JangoBritt commented 8 years ago

it seems that anything other than D will work for a non-dimmer... see my new thread on the topic

gizbod commented 8 years ago

@rooi any phrase I try treats them as lights. On eve it shows the switches as lights and has a percentage with them, although it has no function. I've found a work around with the room set up etc so no real problem for me.

JangoBritt commented 8 years ago

@gizbod I raised a thread relating to that: https://github.com/rooi/homebridge-lightwaverf/issues/7

gizbod commented 8 years ago

@JangoBritt I shall keep an eye on it. Nice one

rooi commented 8 years ago

I've added more deviceTypes in a new commit, please test it. Regarding the setup, I still want to create a setup that uses the homebridge API 2.0 'setup wizard' functionality, but this is a couple of hours work probably. Or... if the new web manager add the deviceId besides the roomId, setup is as easy as the old link and will stay in sync as you add new lightwaverf devices...

JangoBritt commented 8 years ago

I think this one can be marked as closed? 😊