Does anyone has an idea for a better solution?
I do have 3 roller shutter in the living room. Each one is controlled by a NumberItems that can have the values 1,2,3 or 4. The values are mapped as follows: 1 = 0%, 2=40%, 3=60% and 4=100%.
The mapped values represent the closing state of the shutter.
Additionally I do have a SwitchItem for each of these roller shutters that are triggered ON/OFF depending on the Azimuth of the sun. These switches are grouped and trigger/indicate whether the
respective shutter is in a shading position (40% or 60%) or open (0%)
I have written the following simple rules to control the shading also depending on the today forecast temperature. Everything is working fine so far.
But, what displeases me a bit is the fact that the openhab-js library does not support reading the item that has fired the event. For this I need to import the runtime I had used with the integrated “old” javascript version. Did I miss anything? Is there a way to achieve this with openhab-js.
Or is this still not yet supported?
Any suggestion for improvement is highly welcome.
Here are my rules:
A switch in the group receives command ON:
var logger = log("LRShutterShade");
function shade(locationName) {
Object.assign(this, require('openhab'));
let shutterItem = items.getItem("LR_Shutter_"+locationName+"_Pos");
let shutterState = parseInt(shutterItem.state);
let tempForcastMax = parseFloat(items.getItem('LocalWeather_ForecastToday_Maxtemperature').state);
let shadePosition = (tempForcastMax > 24.0) ? 3 : 2;
logger.info("shutter {} ; current Pos = {} ; new Pos = {} ; current temperature = {} °C",
locationName, shutterState, shadePosition, tempForcastMax);
if (shutterState < shadePosition) {
logger.info("Autoshade active for shutter {}", locationName);
shutterItem.sendCommandIfDifferent(shadePosition);
} else {
logger.info("No move for shutter {} ; current Pos = {} ; current temperature = {} °C",
locationName, shutterState, tempForcastMax);
}
}
Object.assign(this, require('@runtime'));
var shadeItem = itemRegistry.getItem(event.itemName);
logger.info("Atomatic {} switched ON", shadeItem.label);
var locationName = event.itemName.split("_")[2];
shade(locationName);
A switch in the group receives command OFF:
var logger = log("LRShutterDeshade");
function deshade(locationName) {
Object.assign(this, require('openhab'));
let shutterItem = itemRegistry.getItem("LR_Shutter_"+locationName+"_Pos");
let shutterState = parseInt(shutterItem.state);
// open shutter only if not already open or completly closed
if (shutterState != 1 && shutterState != 4) {
logger.info("Autoshade inactive for shutter {}", locationName);
shutterItem.sendCommandIfDifferent(1);
}
}
Object.assign(this, require('@runtime'));
var shadeItem = itemRegistry.getItem(event.itemName);
logger.info("Atomatic {} switched OFF", shadeItem.label);
var locationName = event.itemName.split("_")[2];
deshade(locationName);