Det finns redan en tråd om hur man integrera mot Verisure, men eftersom den koncentrerar sig på hårdvarulösningar med smartplugs och reläer så skapar jag en ny. Den här tråden berättar hur man får in status (alarm-status och klimatdata) från Verisures "My Pages". Under setupen så hittade jag ett antal personer som har försökt att få till det men inte lyckats på diverse olika forum, så det kan ju vara intressant för nån att veta hur man gör.
Texten är på engelska, så att andra än svenskar kan googla fram den.
How to get Verisure "My Pages" to integrate into OpenHAB
The below tells you step by step how to get the Verisure "My Pages" alarm status and climate data into OpenHAB. Nothing stops you from using the same modules to integrate into other home automation systems, but I can only give exact details for OpenHAB.
My setup is running on Windows. Adapt paths and similar to your OS.
1. Download and install the Node.js javascript engine for your OS.
2. Download the verisure-api Javascript API from
https://github.com/suhajdab/verisure-api
3. Put the verisure-api.js file into the configurations\scripts subdirectory below the OpenHAB runtime directory.
4. cd to the configurations\scripts directory in a DOS prompt and install three node.js modules:
npm install request
npm install object-assign
npm install es6-promise
5. Create two instantiation files for the Verisure API object:
configurations\scripts\verisure-alarm.js contents:
var config = {
username: 'your@email',
password: 'YourPassword'
};
var verisureApi = require('./verisure-api').setup( config );
// alarm state changes
verisureApi.on( 'alarmChange', log );
function log ( data ) {
console.log( data );
process.exit(1);
}
configurations\scripts\verisure-climate.js contents:
var config = {
username: 'your@emailr',
password: 'YourPassword'
};
var verisureApi = require('./verisure-api').setup( config );
// alarm state changes
verisureApi.on( 'climateChange', log );
function log ( data ) {
console.log( data );
process.exit(1);
}
Yes - the password is in cleartext in a text file on the disk. Paranoid people are free to implement encryption or other security measurements (and share the solution with us).
6. Create two batch files to start the javascript files. I know it's redundant and shouldn't be needed, but I couldn't get it to work without the bounce - it just gave me 0xDEADBEEF error codes.
configurations\scripts\verisure-alarm.bat contents:
@node configurations\scripts\verisure-alarm.js
configurations\scripts\verisure-climate.bat contents:
@node configurations\scripts\verisure-climate.js
7. Make sure to have the exec binding in the OpenHAB addons directory: org.openhab.binding.exec-1.7.1.jar (restart of OpenHAB needed)
8. Create the exec items in your favorite items file:
String verisure_climate "Verisure climate data" <w> (other, persist_everychange) {exec="<[\"C:\\Program Files (x86)\\OpenHAB\\Server\\configurations\\scripts\\verisure-climate.bat\":3600000:]"}
Number verisure_temperature_kitchen "Kitchen Verisure temperature [%.1f°C]" <temperature> (environment_ground, persist_temperature, rooms_kitchen)
Number verisure_temperature_dogroom "Dog room Verisure temperature [%.1f°C]" <temperature> (environment_basement, persist_temperature, rooms_dogroom)
Number verisure_temperature_gameroom "Game room Verisure temperature [%.1f°C]" <temperature> (environment_basement, persist_temperature, rooms_gameroom)
Number verisure_temperature_bedroom "Bedroom Verisure temperature [%.1f°C]" <temperature> (environment_ground, persist_temperature, rooms_bedroom)
Number verisure_temperature_livingroom "Living room Verisure temperature [%.1f°C]" <temperature> (environment_ground, persist_temperature, rooms_livingroom)
Number verisure_temperature_nimsisland "Nim's Island Verisure temperature [%.1f°C]" <temperature> (environment_ground, persist_temperature, rooms_nimsisland)
Number verisure_humidity_dogroom "Dog room Verisure humidity [%.1f %%]" <humidity> (environment_humidities, persist_humidities, rooms_dogroom)
Number verisure_humidity_gameroom "Game room Verisure humidity [%.1f %%]" <humidity> (environment_humidities, persist_humidities, rooms_gameroom)
Number verisure_humidity_bedroom "Bedroom Verisure humidity [%.1f %%]" <humidity> (environment_humidities, persist_humidities, rooms_bedroom)
Number verisure_humidity_livingroom "Living room Verisure humidity [%.1f %%]" <humidity> (environment_humidities, persist_humidities, rooms_livingroom)
Number verisure_humidity_nimsisland "Nim's Island Verisure humidity [%.1f %%]" <humidity> (environment_humidities, persist_humidities, rooms_nimsisland)
String verisure_alarm "Verisure alarm status [MAP(verisure-alarm.map):%s]" <siren> (sensors_alarm, persist_everychange) {exec="<[\"C:\\Program Files (x86)\\OpenHAB\\Server\\configurations\\scripts\\verisure-alarm.bat\":300000:JSONPATH($.status)]"}
Note that only verisure_climate and verisure_alarm have exec statements. We could have exec statements on all the others as well, but let's be nice to Verisure and collect the data once for all the rooms. We will use the verisure_climate item to save all climate data, and then populate the items for the temperature and humidity of the rooms using a rule.
We are checking the climate data once every hour (3600000 ms) and alarm status once every five minutes (300000 ms). You could argue that you would want to check the temperature more often - but the "My Pages" climate data does not get updated that very often, so it wouldn't make things better.
The items above contain my personal groups etc. Put your own groups within the () or use your sitemap to display the items. Also name your items according to your room names, unless you have a room called "Nim's Island".
9. Create the population rule in your favorite rules file:
rule "Set verisure climate items"
when Item verisure_climate received update
then
var String temp_string = transform("JSONPATH", "$.[?(@.location=='Kitchen')][0].temperature", verisure_climate.state.toString())
var String[] temperature = temp_string.split('&')
postUpdate(verisure_temperature_kitchen, temperature.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Dog room')][0].temperature", verisure_climate.state.toString())
temperature = temp_string.split('&')
postUpdate(verisure_temperature_dogroom, temperature.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Game room')][0].temperature", verisure_climate.state.toString())
temperature = temp_string.split('&')
postUpdate(verisure_temperature_gameroom, temperature.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Bedroom')][0].temperature", verisure_climate.state.toString())
temperature = temp_string.split('&')
postUpdate(verisure_temperature_bedroom, temperature.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Living room')][0].temperature", verisure_climate.state.toString())
temperature = temp_string.split('&')
postUpdate(verisure_temperature_livingroom, temperature.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Nim\'s Island')][0].temperature", verisure_climate.state.toString())
temperature = temp_string.split('&')
postUpdate(verisure_temperature_nimsisland, temperature.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Dog room')][0].humidity", verisure_climate.state.toString())
var String[] humidity = temp_string.split('%')
postUpdate(verisure_humidity_dogroom, humidity.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Game room')][0].humidity", verisure_climate.state.toString())
humidity = temp_string.split('%')
postUpdate(verisure_humidity_gameroom, humidity.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Bedroom')][0].humidity", verisure_climate.state.toString())
humidity = temp_string.split('%')
postUpdate(verisure_humidity_bedroom, humidity.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Living room')][0].humidity", verisure_climate.state.toString())
humidity = temp_string.split('%')
postUpdate(verisure_humidity_livingroom, humidity.get(0).replace(',', '.'))
temp_string = transform("JSONPATH", "$.[?(@.location=='Nim\'s Island')][0].humidity", verisure_climate.state.toString())
humidity = temp_string.split('%')
postUpdate(verisure_humidity_nimsisland, humidity.get(0).replace(',', '.'))
end
The Verisure API javascript is nice enough to give us a JSON, so we kan use JSONPATH to get the data - but we still need to get rid of some degree signs and percent signs, and replace decimal commas with decimal points.
Note: Remember to replace my room names with your own - both in the JSONPATH definitions and the item names.
If you want to harass Verisure and their web servers, you can use the same JSONPATH definitions directly in the items file (see the verisure_alarm item for how), eliminating the need for this rule. Every such item will cause its own connection to the Verisure "My Pages" web server.
10. Create a verisure-alarm.map file to add some human readability to the alarm status:
configurations\transform\verisure-alarm.map contents:
unarmed=Unarmed
armedhome=Armed (home)
armedaway=Armed (away)
-=Unknown status
That's it folks.
/P