Hi all together,
thanks to your implementations I managed to get this working, too. As I’m moving to JSR223 and prefer the idea of metadata over naming conventions for items. For anyone interested, I’ll share the concept.
Rollershutter Dining_Rollershutter_Level "Level [%.0f %%]" <rollershutter> (HmIpBrollProxy) {Proxy='' [LevelItem="Dining_Rollershutter_Level_Actuator"]}
Rollershutter Dining_Rollershutter_Level_Actuator {channel="homematic:HmIP-BROLL:XXX:YYY:4#LEVEL"}
Rollershutter Dining_Rollershutter_Level_Status (HmIpBrollLevel) {channel="homematic:HmIP-BROLL:XXX:YYY:3#LEVEL", Proxy='' [ProxyItem="Dining_Rollershutter_Level"]}
As can be seen from the channels, I have HmIP-BROLL devices. They didn’t seem to like using channel :4#STOP
, but sending the stop command to :4#LEVEL
works fine as well.
This leads to a rule to control the channel via the proxy item:
from core.rules import rule
from core.triggers import when
from core.metadata import get_key_value
from core.utils import getItemValue
@rule('Set upper level of roller shutter', description = 'HmIP and OH use reverse logic for rollershutters. Limit value to 1/99.9, control via HmIP-channel 4.')
@when('Member of HmIpBrollProxy received command')
def send_command(event):
if (event.itemCommand == UP):
level_item_name = str(get_key_value(event.itemName,'Proxy','LevelItem'))
events.sendCommand(level_item_name, '1')
elif (event.itemCommand == DOWN):
level_item_name = str(get_key_value(event.itemName,'Proxy','LevelItem'))
events.sendCommand(level_item_name, '99.9')
elif (event.itemCommand == STOP):
stop_item_name = str(get_key_value(event.itemName,'Proxy','LevelItem'))
events.sendCommand(stop_item_name, 'STOP')
else:
send_command.log.info("Unknown command")
When writing this, the idea came up to replace the upper value 1 with 0.1. Will try that out.
It seems to me, that the CCU/the API/Homematic binding has problems with boundary values 0 and 100. In the logs I see weired level values when going all the way up or down. To handle this, the part of the rule to proxy the level status replaces them with 0.1 or 99.9:
@rule('Convert roller shutter level', description = 'Converts HmIP level to OpenHAB conventions')
@when('Member of HmIpBrollLevel received update')
def main_update(event):
proxy_item_name = str(get_key_value(event.itemName,'Proxy','ProxyItem'))
events.postUpdate(ir.getItem(proxy_item_name), QuantityType(str(min(99.9, max(0.1, float(str(event.itemState)))))))
This works like a charm and OH can display the level correctly (e.g. in Basic UI).
Further information:
Thanks again to @philissimo and @Knut1507, your concepts helped me developing this.