Hi.
I’ve got my own hardware* timer-switch which works this ways:
You’ve got a button and a light. If you push the button it turns on the light and starts a timer which will turn the light off automatically after it runs out. If you push it again it turns the light off. If you hold the switch while the light is on for a short time it stops the timer and leaves the light on indefinitely. This works completely independent of openhab2.
Currently I’m only using the turn light on/off functionallity in openhab2. But now I want to integrate it fully. This means I have not one state (on/off) but 4 of them:
(bool) ON/OFF
(bool) Timer Running
(int) Timer duration (persistent)
(int) Timer remaining (can be combined with Timer Running if it must)
I’ve quite a couple of this light/switch combinations (10 and counting) so it would make sense for me to invest some time and write me a component or so if this would make sense. What would be the nature of these? Are they “Things”? (Or is my board “the Thing” and the switches are channels?
What would be the best way to model these in OpenHAB2? (And how do I get some “nice” UI for them)
Best regards,
Florian
*) a ti tm4c1294 dev board, some optocouplers and some SSRs. This is connected to a beaglebone green vie ethernet using mosquitto and openhab2
Since it is a DIY device using MQTT make sure your device publishes and can parse the correct commands. Use multiple Items to represent the states of the Switch, one for each of the states. I see two Switches and two Numbers.
I don’t even think you need Rules in this case. Any command sent to the ON/OFF causes an ON/OFF command MQTT message to be sent to the device. Any change to the Timer duration Item gets published to the device and starts the Timer for that amount of time.
Any interactions at the switch itself get published to these Items so OH stays in sync with the state of the device.
I see no need for a new binding to manage this. That would probably be a lot of extra work.
One limitation you will have is the UIs in OH will not be able to support long press interactions. Short of writing a custom widget for HABPanel or making significant modifications to BasicUI, ClassicUI, and both phone apps you need to some up with some other interaction approach through the OH UIs, akin to what I describe above.
I don’t need no longclicks in the ui. That is for physical buttons only.
I can put the timer duration in a seperate configuration panel which is good style anyway.
But I would like to have on/off, timer running and remaining in one UI Component.
If it’s not possible to have more than one state on one channel I could map these three into values:
0: OFF
1…n: seconds remaining
-1: ON but timer off OR -1…-n seconds in timer remaining but timer stopped.
which would nicely map to 0: OFF / !=0: ON if needed.
But I still need a way to get my own custom UI Component in. I image this as some icon which on touch enlarges to some kind of clock/stopwatch.
So is there a way to get custom UI elements in SimpleUI? Does this work with the Android App? Or can this be done in Habpanel?
In that case you should implement it on the physical device and use a different message to tell OH what sort of press it was.
Then you will have to write a custom widget for HABPanel. There is no way to do this with the sitemap based UIs.
Do you mean BasicUI? The answer is not really. You could write your own webserver that implements the UI and interacts with OH through the REST API, and then put it on your sitemap using a Webview element, but that won’t work outside your LAN and I’m not certain it will work in the Android App.