LightwaveRF Binding Updated

Thanks. I’ll give it a try and report back.
Appreciate the work you’ve put into this, you’re years ahead of where I would have been by now.

I’ve made a few changes to my files which ill replicate back to the setup file when i get a minute and upload:

  • Changed Power and Energy to Number rather than string in rule and items and corrected Kwh value
  • Added units to items
  • Created a Group Structure for combined usage / energy
    • Added Groups To Items
  • Added default icons and groups to items

Other Changes To Implement:

  • Log KwH Historical Usage to Item/File/Persistence so monthly usage can be monitored
  • Add Rule/Switch to reset Historical Usage (user definable Daily/weekly/monthly/yearly (i will log them all and just have the reset as user definable)

Ive also sent a request to Lightwave regarding limits on api calls as i had a few issues (when really hammering the service whilst debugging) where i got 500 server errors (it blocked me) and a few json responses saying too many requests
I’ve been running without errors for about 10 hours now Update Had my rule terminating on a null value, I’m adding some error handling in as if the value returned is null/another error for any reason it stops the rule from firing in the loop.

i was using cron timers in rules and it kept crashing. I was calling rules (2 of) every 10 seconds and the rules were fairly long so i think it just run out of threads and locked it up until reboot. Which may be the case also for the binding. Where is the cron being used your talking about? directly in the binding or are you calling the binding from cron rules?

Probably makes sense for me to wait until you’ve posted the updated files with your changes. Give me a shout when they’re ready and I’ll give them a go. The authentication is still working though, the logs say it refreshed my token a few hours ago.

Also re your earlier comment I can give you whatever you need from the system this end but I’m not familiar with postman:

could you do a get request through postman for /structures ( take out your personal details) and post it to me

Could you point me to some info?

Postman is just a windows application that allows you to send http requests (post/get etc) with headers and a body that cannot normally be integrated in a url in a browser. If you look at my send command line arguments in the rules (forget the backslashes and @@ signs) you will get an understanding. So and thing that follows an -H is a header (for instance, content-type is the header and the information relating to that header is application/json. Postman allows you to specify the headers, and also the body (-d). I’ve only just learnt all this myself but it gives a clear understanding to you then what my rules are accomplishing.
It doesn’t matter about waiting as in my setup rule it will delete the existing files before re creating them (I done this purposely to make it easy for people to add my changes).

Having monitored it today there is definitely a request limit to light waves servers but they do not specify it anywhere I can find, which annoys me slightly in the fact that there is no function within the api to get the status of all features with one call, instead having to query every item, which if you had 20 double sockets and just wanted the 3 statuses I have integrated is 120 calls( each double socket is 2 items x 20 = 40 x 3 features). Do that every 10 seconds to keep everything in sync and the data is mounting up.

I’m learning myself (I’m a refrigeration engineer by trade) so I’ll probably find a better approach. I see from the api that web hooks can be created so if a device status changes it will send the data to an endpoint, however I don’t know much about webhooks at present and don’t see how it can send data to the normal person with a dynamic IP address/ no domain without knowing when it changes. I’m happy I’ve got so far and if I can just get the few little niggles ironed out it’s a building block for me to take further.

Right I’ve done some more research and I can now successfully get all values from a single poll of the api.
This is going to drastically improve things and make life a lot easier.
I don’t know when I’m going to get a chance to implement but hopefully at some point this weekend/bank holiday Monday.

haven’t done a lot of testing but seems more stable.
1 request to lightwaves servers now so shouldn’t hit api limits which they still haven’t advised.
also added costs (current and historical)
going to attempt to move this over to exec binding this week so it executes cleaner
Lightwave_Setup.rules.txt (9.6 KB)

** UPDATE** Use this file instead:

Tried it again with your latest file this evening. Everything seems to work but then it stops, different error this time:

2019-05-07 20:13:36.531 [INFO ] [clipse.smarthome.model.script.Exec11] -
2019-05-07 20:13:42.635 [INFO ] [clipse.smarthome.model.script.Exec12] -
2019-05-07 20:13:42.893 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘LightWave_Rules_Authentication.rules’
2019-05-07 20:13:44.393 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘LightWave_Rules_Authentication.rules’
2019-05-07 20:13:47.697 [INFO ] [clipse.smarthome.model.script.Exec13] -
2019-05-07 20:13:53.760 [INFO ] [clipse.smarthome.model.script.Exec14] -
2019-05-07 20:13:54.173 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘LightWave_Rules_Structures.rules’
2019-05-07 20:13:55.536 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘LightWave_Rules_Structures.rules’
2019-05-07 20:14:04.231 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Lightwave_Setup’: For input string: “{nullHub”,“gen”:2}]}"

That’s as far as it goes. Still just the same two items files like before.

Maybe my LWRF setup is different to yours in some way? I have Gen 1 plug-in relay sockets, a Gen 1 3-way relay, Gen 2 double sockets and Gen 2 dimmers both one and two gang. What diagnostic info from my system would help you?

I get the same, but i have a gen 1 hub, which i guessed was why

There’s already a Lightwave RF binding for the Gen 1 hub in OpenHAB:
[https://www.openhab.org/addons/bindings/lightwaverf1/]
You might want to try that if your setup is all Gen 1

You did put your username and password back in the rules file at the top yeah, just to rule out the basic

Looking at your log above that’s an old file, the exec’s run in order now, 1,2,3,4,5
use this one and don’t forget to put email and password at the top before running
if it errors out i need the logentry for “f” - should be a json ( check theres no email/password/access_token in there before posting)

Lightwave_Setup_2019-05-07_2200.rules.txt (9.8 KB)

should run through exec’ 1-10. if you get any errors post them up, have modified my files directly and integrated back to this but havnt tested so hopefully no errors.
Been up and running for 7 hours now with no errors, just had to tinker with the timeouts.
costs live and working also

and at present its a no go with the exec binding, theres a bug i cant find a workaround for

Yup

ill be about for about half hour if your good to test now, otherwise will look 2mora.
we will get you there tho

Might have a bit of time Thursday evening

No problem, just make sure you use the latest file. What time zone are you in, i think we are probably about the same, i’m UK GMT.

Same, UK GMT here too.
FYI I’m using OpenHABian on a Raspberry PI and have the OpenHAB cloud access set up plus I have a VPN into the home network.
I’m using the latest file. I’ll try to add some logging to capture what’s going on but at first glance it looks like something unexpected is coming back from my structure and breaking the JSONPATH transformation which is why we get the ‘null’ in the log entry.

the log you posted up yesterday was an old file
I’m also openhabian
Also have cloud setup
And also using a VPN
:joy:

OK my bad, lose track of the threads on here sometimes. I’ll get your latest file and try it Thursday

I added a date to the filename so you can see it above and we can track changes easier
if it doesn’t work then i just need the json loginfo output from this line

val deviceresults = executeCommandLine("curl@@-g@@-XGET@@https://publicapi.lightwaverf.com/v1/Structure/" + Structure.state.toString + "@@-H@@Authorization:bearer " + Access_Token,5000)

should look something like this:

{
"name": "My Group",
"groupId": "5c7d64783c570522afb151b5-5c7d64783c570522afb151b6",
"devices": [
    {
        "deviceId": "5c7d64783c570522afb151b5-2-3157331848+1",
        "name": "Kitchen Socket",
        "productCode": "L42",
        "featureSets": [
            {
                "featureSetId": "5c7d64783c570522afb151b5-5c7d72a83c570522afb15275",
                "name": "Kettle",
                "features": [
                    {
                        "featureId": "5c7d64783c570522afb151b5-24-3157331848+1",
                        "type": "switch",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-25-3157331848+1",
                        "type": "outletInUse",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-26-3157331848+1",
                        "type": "protection",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-27-3157331848+1",
                        "type": "power",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-28-3157331848+1",
                        "type": "energy",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-17-3157331848+1",
                        "type": "identify",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-18-3157331848+1",
                        "type": "reset",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-19-3157331848+1",
                        "type": "upgrade",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-20-3157331848+1",
                        "type": "diagnostics",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-21-3157331848+1",
                        "type": "periodOfBroadcast",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-22-3157331848+1",
                        "type": "rgbColor",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-23-3157331848+1",
                        "type": "voltage",
                        "writable": false
                    }
                ]
            },
            {
                "featureSetId": "5c7d64783c570522afb151b5-5c7d72a83c570522afb15276",
                "name": "Kitchen Socket 2",
                "features": [
                    {
                        "featureId": "5c7d64783c570522afb151b5-29-3157331848+1",
                        "type": "switch",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-30-3157331848+1",
                        "type": "outletInUse",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-31-3157331848+1",
                        "type": "protection",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-32-3157331848+1",
                        "type": "power",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-33-3157331848+1",
                        "type": "energy",
                        "writable": false
                    }
                ]
            }
        ],
        "product": "L42",
        "device": "socket",
        "desc": "Smart Socket",
        "type": "lwrfTwoWay_v2",
        "cat": "Power",
        "gen": 2
    },
    {
        "deviceId": "5c7d64783c570522afb151b5-3-3157331848+1",
        "name": "Washing Machine",
        "productCode": "L42",
        "featureSets": [
            {
                "featureSetId": "5c7d64783c570522afb151b5-5c8bfe4973160a538b988943",
                "name": "Washing Machine",
                "features": [
                    {
                        "featureId": "5c7d64783c570522afb151b5-41-3157331848+1",
                        "type": "switch",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-42-3157331848+1",
                        "type": "outletInUse",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-43-3157331848+1",
                        "type": "protection",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-44-3157331848+1",
                        "type": "power",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-45-3157331848+1",
                        "type": "energy",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-34-3157331848+1",
                        "type": "identify",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-35-3157331848+1",
                        "type": "reset",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-36-3157331848+1",
                        "type": "upgrade",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-37-3157331848+1",
                        "type": "diagnostics",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-38-3157331848+1",
                        "type": "periodOfBroadcast",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-39-3157331848+1",
                        "type": "rgbColor",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-40-3157331848+1",
                        "type": "voltage",
                        "writable": false
                    }
                ]
            },
            {
                "featureSetId": "5c7d64783c570522afb151b5-5c8bfe4973160a538b988944",
                "name": "Oven",
                "features": [
                    {
                        "featureId": "5c7d64783c570522afb151b5-46-3157331848+1",
                        "type": "switch",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-47-3157331848+1",
                        "type": "outletInUse",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-48-3157331848+1",
                        "type": "protection",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-49-3157331848+1",
                        "type": "power",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-50-3157331848+1",
                        "type": "energy",
                        "writable": false
                    }
                ]
            }
        ],
        "product": "L42",
        "device": "socket",
        "desc": "Smart Socket",
        "type": "lwrfTwoWay_v2",
        "cat": "Power",
        "gen": 2
    },
    {
        "deviceId": "5c7d64783c570522afb151b5-4-3157331848+1",
        "name": "Toaster",
        "productCode": "L42",
        "featureSets": [
            {
                "featureSetId": "5c7d64783c570522afb151b5-5c8bff3973160a538b988948",
                "name": "Toaster",
                "features": [
                    {
                        "featureId": "5c7d64783c570522afb151b5-58-3157331848+1",
                        "type": "switch",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-59-3157331848+1",
                        "type": "outletInUse",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-60-3157331848+1",
                        "type": "protection",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-61-3157331848+1",
                        "type": "power",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-62-3157331848+1",
                        "type": "energy",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-51-3157331848+1",
                        "type": "identify",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-52-3157331848+1",
                        "type": "reset",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-53-3157331848+1",
                        "type": "upgrade",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-54-3157331848+1",
                        "type": "diagnostics",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-55-3157331848+1",
                        "type": "periodOfBroadcast",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-56-3157331848+1",
                        "type": "rgbColor",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-57-3157331848+1",
                        "type": "voltage",
                        "writable": false
                    }
                ]
            },
            {
                "featureSetId": "5c7d64783c570522afb151b5-5c8bff3973160a538b988949",
                "name": "Tumble Drier",
                "features": [
                    {
                        "featureId": "5c7d64783c570522afb151b5-63-3157331848+1",
                        "type": "switch",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-64-3157331848+1",
                        "type": "outletInUse",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-65-3157331848+1",
                        "type": "protection",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-66-3157331848+1",
                        "type": "power",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-67-3157331848+1",
                        "type": "energy",
                        "writable": false
                    }
                ]
            }
        ],
        "product": "L42",
        "device": "socket",
        "desc": "Smart Socket",
        "type": "lwrfTwoWay_v2",
        "cat": "Power",
        "gen": 2
    },
    {
        "deviceId": "5c7d64783c570522afb151b5-1-3157331848+1",
        "name": "LinkPlus",
        "productCode": "L2",
        "featureSets": [
            {
                "featureSetId": "5c7d64783c570522afb151b5-5c7d64793c570522afb151bd",
                "name": "LinkPlus",
                "features": [
                    {
                        "featureId": "5c7d64783c570522afb151b5-1-3157331848+1",
                        "type": "currentTime",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-2-3157331848+1",
                        "type": "buttonPress",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-3-3157331848+1",
                        "type": "time",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-4-3157331848+1",
                        "type": "date",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-5-3157331848+1",
                        "type": "monthArray",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-6-3157331848+1",
                        "type": "weekdayArray",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-7-3157331848+1",
                        "type": "timeZone",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-8-3157331848+1",
                        "type": "locationLongitude",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-9-3157331848+1",
                        "type": "locationLatitude",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-10-3157331848+1",
                        "type": "duskTime",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-11-3157331848+1",
                        "type": "dawnTime",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-12-3157331848+1",
                        "type": "rgbColor",
                        "writable": true
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-13-3157331848+1",
                        "type": "day",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-14-3157331848+1",
                        "type": "month",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-15-3157331848+1",
                        "type": "year",
                        "writable": false
                    },
                    {
                        "featureId": "5c7d64783c570522afb151b5-16-3157331848+1",
                        "type": "weekday",
                        "writable": false
                    }
                ]
            }
        ],
        "product": "L2",
        "device": "LinkPlus",
        "desc": "Central Hub",
        "type": "lwrfTwoWay_v2",
        "cat": "Hub",
        "gen": 2
    }
]

}

1 Like