-
-
Notifications
You must be signed in to change notification settings - Fork 461
Description
For OH3, I think we should take a serious look at how states / commands are defined. We've had the legacy system for 10 years now, and I personally think it's creaking at the seems and limiting the way we can run the system.
Currently, we have a single dimension in the state - e.g. ON/OFF, a single value, etc. This is fine for basic information that goes to a user or UI, however, in many cases further information is required (or at least, is provided from the device sending the state) to fully describe an event. While this information may not be of primary concern, and may not be used in a UI, it is useful for triggering rules/scenes and I feel it would be useful to think if this could be attached to the state event.
A few use cases -:
- A ZigBee light can provide a transition time - ie the amount of time required to move from ON to OFF. We want to be able to define this attribute, along with the state.
- Z-Wave scene controller can can send a scene 'command' - this usually has a number of attributes - the scene number, but also the keypress type (KEY-DOWN, KEY-UP, etc), and sometimes a time is also provided. This is currently handled by defining a number - (scene number).(type) - e.g. 6.3 might be used for scene 6, keydown - we ignore the time so the device can not be fully utilised.
- An alarm can have a type, and a state. Instead of implementing 25 channels for 25 different alarms, each with an on/off condition, it might be more convenient to provide a single Alarm channel with on/off state and alarm type attribute. The UI can show there's an alarm (i.e. showing the channel and it's state - as we now have) but a rule would be able to look at the attribute and decide exactly what alarm type this is and act with the appropriate response.
- A smoke alarm can go into alarm - we want to show this on the UI, however the notification rule that rings the fire brigade probably doesn't want to do this if it's a test - we could add the "Test=true" attribute so that the system can work around this.
- A door lock can have the state ON or OFF (LOCKED or UNLOCKED) but this can have attributes such as the reason it changed state (eg the user who opened the door).
Of course there are always ways around this with the current system - we can concatenate data together(e.g. alarm type number x 100 + alarm value), or we can use two channels, but then the rule has to resynchronise these two streams. Or we can use json strings to hold multiple bits of data which has been the recommendation so far.
I'd like to propose an extension to State updates to hold attributes - ie secondary data that provides context to the primary state.
Currently, we have -:
updateState(channelUID, state)
I believe (following an extremely quick look at the code!) that this could be extended with another parameter containing an object / attribute map. eg
updateState(channelUID, state, object)
eg in pseudo code.
updateState("channel.uid", OnOffState.ON, {"keypress":"down", "time":25})
Likewise in rules, we could have -:
Light.sendCommand(ON, {"duration", "10S"}),
A similar extension to rules would be required to read the attributes. The idea is not to impact the framework - all the generic information required to be system agnostic is still there, but it allows the framework to support the more advanced features that may be provided by systems like Z-Wave (and many more I'm sure).
I've also seen people talking about having things with 1500 channels - I've not looked at why this is, but I do wonder if the above suggest might in some cases allow better channel definition, and possibly reduction in channels (??).
This was originally proposed in ESH but not discussed - it seems to me that OH3.0 should take a good look at improving the command/state/items and I think something along these lines could significantly improve the system.