please point me to right direction on how to implement IR remote control UI in OpenHab.
I have an el-cheapo IR controllable led light ball, which I want to command via OpenHab.
I created a MySensor radio network based arduino code with IR TX led. I can now send messages to it over MQTT, and it converts the code into IR signals. All works already, code is here: https://github.com/ikke-t/livarnoluxball-remote
Now I would like to setup GUI into OpenHab with 16 buttons as there is in remote. The button presses should send integer values into MQTT channel. Not switches, as I can not read back the state, but buttons, just like in remote. How to do that?
Switch livarnolux "Led Lamp tila state [MAP(livarnoluxball.map):%s]" <light> (lights) { mqtt=">[mosquitto:MySensorsGW/in/7/1/1/0/32:command:*:default], <[mosuqitto:MySensorsGW/out/7/1/1/0/32:state:default]" }```
which should them be made to send the given value from map table once some gui button is pressed. The device echoes back the same command, so I can keep track of the set state. Of course if IR link won't work, one can't trust the state. Anyhow, let's assume it works. I haven't yet figured out the "command:*default" conversions I should do.
So how do I now create 4x6 GUI with buttons as in MAP file so, that each button press calls the MQTT item with given code? I'd like to color the buttons to reflect the led lamp colors.
Any help welcome,
ikke
I would create a proxy switch and send the commands via a rule.
Item:
Switch MyRemote ""
sitemap:
Switch item= MyRemote mappings=[1="Red", 2="Red1",3="Red2",4="red3"]
Switch item= MyRemote mappings=[5="green",6="green1",7="green2",8="green3"]
//You could spice up the sitemap by using unicode instead of text: đź’ˇ
Switch item= MyRemote mappings=[9="đź’ˇ",10="đź’ˇ",11="đź’ˇ",12="đź’ˇ"]
//there is a labelcolor and valuecolor setting so you could color it:
//http://docs.openhab.org/configuration/sitemaps.html
//and so on..same switch, just raise the numbers
rule:
rule "remote control"
when
Item MyRemote received command
then
switch (receivedCommand){
case 1: sendCommand(livarnolux,YOUR-COMMAND-HERE)
case 2: sendCommand(livarnolux,ANOTHER-COMMAND-HERE)
case 3: sendCommand(livarnolux,DIFFERENT-COMMAND-HERE)
//etc. until you have your 16 cases
}
end
First of all, I think you should use a pure item definition, without any of the UI presentation stuff in there. IMO, it is better to put the UI presentation stuff solely in the sitemap. Now, you probably want (need) to define your item as a Number item, like this:
Number livarnolux { mqtt=">[mosquitto:MySensorsGW/in/7/1/1/0/32:command:*:default], <[mosuqitto:MySensorsGW/out/7/1/1/0/32:state:default]" }
With this, any number (e.g. 11007817) that you send to your item (using sendCommand()) will be sent to your Arduino device, and any number received from your Arduino device will update your item.
So far, so good. Now the only thing that remains is the UI - and unfortunately that is probably going to be the hardest part to get right.
By using a Switch element on the sitemap, it is possible to use so-called mappings to associate a button on the screen sporting a human-readable name (e.g. “Blue”) with a number value of the underlying item (e.g. 11002664).
With this in place, you can push the “Blue” button and the command “11002664” will be sent, and conversely if you receive the number “11002664” the “Blue” button will be highlighted.
Now, about the layout, it is unfortunately so that the OpenHAB UI (Classic/Basic) is rather restricted. As far as I can tell, there is really no good way to realize a 4x6 button layout.
Thanks guys, good ideas. I also did something else in the meanwhile, which failed. The change from Switch item to Number item was brilliant, works well and no conversions needed.
The Switch element is problematic, as it renders incorrectly at least on Chrome. As I have 16 options, it draws long line of 16 buttons, and doesn’t scale the row based on browser size. E.g. if window is narrow, you see four buttons, and rest of the buttons continue past the window border, but there is no scroll bar for that. Which is a bug from my understanding.
I could also split it into several Switches, e.g. 6 switches with four buttons on each. If I put them in separate frames, it looks ok. But now the problem is that it looks like each row has one button selected. Which is not how remotes work, only on button should be selected. Perhaps some group magic could be done to get passed that?
This is where I’m at now:
sitemap:
items:
I have also made map files both ways, name=number and another file with number=name, so I should be able to convert the values to names based on those. How can I use MAP(livarnolux-in.map) instead of having all values in sitemap with mappints=[number=name,…*16]?
e.g, how would the above work like this (…which is wrong): Switch item=livarnolux mappings=[MAP(livarnolux-in.map)]
That’s what I meant, it renders nicely, but it leaves one of each row selected. So looking at it you see that it has several colours selected simultaneously, one on each Switch. Thus it’s no good.
It allows me to push some of the buttons repeatedly, and all the colour modes are in selection list. Good enough. Some other night I make it prettier by coloring the color list if possible, and probbly remove the colour names all together.
I’m perplexed…I’m using the same trick for a 3x3 button array and there is always only one button highlighted: the one last pressed. Only difference: I’m using HabDroid and Classic UI, not Basic UI. Maybe Basic UI behaves different…