How to mimic a IR remote control in GUI, and command via MQTT?

Tags: #<Tag:0x00007f616c9a7368> #<Tag:0x00007f616c9a7228> #<Tag:0x00007f616c9a7160>

Hi,

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?

I created a map file for codes:

10985849=brighter
11012744=dimmer
10999304=off
11026184=on
11029544=flash
11032889=strobe
11027977=fade
11034697=smooth
10992584=red
10989224=red1
10995944=red2
10987642=red3
10994377=red4
11019464=green
11016104=green1
11022824=green2
11014537=green3
11021257=green4
11006024=blue1
11002664=blue
11009384=blue2
11001097=blue3
11007817=blue4

OK, On/Off could be a switch look alike.

And I started drafting an item like this:

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

Yep, should work.

1 Like

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).

This is described here:

http://docs.openhab.org/configuration/sitemaps.html#element-type-switch

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.

1 Like

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)]

This is how it renders Switch wrong:

This is from the above sitemap, surrounded by Frame

   Frame label="valopallo1" {
	    Switch item=livarnolux mappings=[16187647="BRIGHTER", 16220287="DIMMER", 16203967="OFF", 16236607="ON", 16240687="FLASH", 16248847="STROBE", 16238647="FADE", 16246807="SMOOTH", 16195807="RED", 16191727="RED1", 16199887="RED2", 16189687="RED3", 16197847="RED4", 16228447="GREEN", 16224367="GREEN1", 16232527="GREEN2", 16222327="GREEN3", 16230487="GREEN4", 16212127="BLUE1", 16208047="BLUE", 16216207="BLUE2", 16206007="BLUE3", 16214167="BLUE4" ]
	}

Selection would render it correctly into one list, but it’s not very handy for pressing same button several times, like brightness.

Frame label="valopallo1" {
	    Switch item=livarnolux mappings=[16187647="BRIGHTER", 16220287="DIMMER", 6203967="OFF", 16236607="ON" ]
            Switch item=livarnolux mappings=[16240687="FLASH", 16248847="STROBE", 16238647="FADE", 16246807="SMOOTH", 16195807="RED" ]
           Switch item=livarnolux mappings=[, 16191727="RED1", 16199887="RED2", 16189687="RED3", 16197847="RED4", 16228447="GREEN", 16224367="GREEN1", 16232527="GREEN2", 16222327="GREEN3", 16230487="GREEN4", 16212127="BLUE1", 16208047="BLUE", 16216207="BLUE2", 16206007="BLUE3", 16214167="BLUE4"]
	}

and so on. you can use the same switch n times, just with a different mapping in each line.

1 Like

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.

this is now the best I could come up with the options:

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.

No, there will be only one highlighted value; the one you selected last. It is the same switch all the time and it can only have one value.

I disagree :slight_smile:

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…

1 Like