[SOLVED] Problems with implementing lirc to control IR-devices

Hi community,

I’d like to control my receiver with my raspberry pi, what already works fine. I use the lirc tool like described in this tutorial: https://tutorials-raspberrypi.de/raspberry-pi-fernbedienung-infrarot-steuerung-lirc/ (there are lots of similar v=tutorials in the internet).

Up to now, I can control different buttons, e.g. with this command in the shell I turn off the receiver:

irsend SEND_ONCE harman-kardon KEY_POWER2

Now, I’d like to toggle the device with openhab 2. Unfortunately, I don’t know how. I tried something like this:

.items

Switch IR_Remote_Send { channel="exec:command:remote-irsend:run" }
String IR_Remote_Send_Args { channel="exec:command:remote-send:input"}
String IR_Remote_Send_Out { channel="exec:command:remote-send:output" }

.things

Thing exec:command:ir-send [
        command="irsend SEND_ONCE %2$s",
        interval=0,
        autorun=true]  

.rules

rule "Poweroutlet B1"
  when
    Item Reciever received command 
  then
     if(receivedCommand == ON){
        IR_Remote_Send_Args.sendCommand("harman-kardon KEY_POWER")


     }else{
       IR_Remote_Send_Args.sendCommand("harman-kardon KEY_POWER2")

     }
end

I oriented to the scrips of my wireless power sockets (433MHz).
The problem has to do with the Exec Binding, but I don’t know exactly where it is.



I am looking forward to find a solution with you !

Dominik

Check the think-name in the items
ir-send
remote-irsend
remote-send

Thanks for your answer, Harry.

Do you mean this:

Switch IR_Remote_Send { channel="exec:command:ir-send:run" }
String IR_Remote_Send_Args { channel="exec:command:remote-irsend:input"}
String IR_Remote_Send_Out { channel="exec:command:remote-send:output" }

This does not work, too, unfortunately.

Have you tried the lirc binding? https://docs.openhab.org/addons/bindings/lirc/readme.html i switched a little while ago, seems to work well.

1 Like

Hey and thank you for your answer, @chriscolden.

I haven’t, because I’m running 2.1.0 and the binding is available for 2.2.0 only, I think. But maybe it is the easier possibility to upgrade and use the binding. Could you be so kind to upload your code ?

Sure,

Item

Number		GF_Living_Remote			""										<none>					(gLounge)		{ autoupdate="false" }
String		Remote_technika32																							{ channel="lirc:remote:local:technika32:transmit" }
String 		Remote_VIRGINTIVO																							{ channel="lirc:remote:local:VIRGINTIVO:transmit" }
String 		Remote_hdmiswitch																							{ channel="lirc:remote:local:hdmiswitch:transmit" }

Sitemap

Switch item=GF_Living_Remote icon="switch" mappings=[10="TV", 11="Tivo"]
Switch item=GF_Living_Remote icon="soundvolume" mappings=[12="Vol ▲", 13="Vol ▼"]
Switch item=GF_Living_Remote mappings=[14="Chan ▲", 15="Chan ▼"]
Switch item=GF_Living_Remote mappings=[1="1", 2="2", 3="3"]
Switch item=GF_Living_Remote mappings=[4="4", 5="5", 6="6"]
Switch item=GF_Living_Remote mappings=[7="7", 8="8", 9="9"]
Switch item=GF_Living_Remote mappings=[0="0"]

Rule

import org.eclipse.xtext.xbase.lib.Functions

val logName = "Media"

val Functions$Function3<String, String, String, Boolean> lirc= [ r, k, ln |
	logInfo(ln, "LIRC Send " + r + " " + k)

	sendCommand("Remote_" + r, k)
    true
]

rule "TV Remote"

when
	Item GF_Living_Remote received command
then
	if (receivedCommand >= 0 && receivedCommand <= 9)
	{	
		lirc.apply("VIRGINTIVO", "KEY_" + receivedCommand, logName)
	}		
	else if (receivedCommand == 10)
	{
		lirc.apply("technika32", "KEY_POWER", logName)
	}
	else if (receivedCommand == 11)
	{
		lirc.apply("VIRGINTIVO", "KEY_POWER", logName)
	}
	else if (receivedCommand == 12)
	{
		lirc.apply("technika32", "KEY_VOLUMEUP", logName)
	}
	else if (receivedCommand == 13)
	{
		lirc.apply("technika32", "KEY_VOLUMEDOWN", logName)
	}
	else if (receivedCommand == 14)
	{
		lirc.apply("VIRGINTIVO", "KEY_CHANNELUP", logName)
	}
	else if (receivedCommand == 15)
	{
		lirc.apply("VIRGINTIVO", "KEY_CHANNELDOWN", logName)
	}
end

Got there in the end. haha

Edit: added some missing items

1 Like

Thanks you guy, this looks really understanding :slight_smile:

I will easily copy this and modify it a bit, that’s the simplest solution :smiley:

Thanks !

1 Like

fyi - I’m running the unstable branch. i get the odd problem every now and then, but generally its ok. That said, 2.2 has been pushed into stable as far as i know.

I take the risk :smiley: All for controlling my receiver… But sooner or later, I upgrade OH anyway, there are some nice features I want so test :slight_smile:

Hey again, I tried the binding today but I can’t make the remote working. Are you also using a rpi with a IR-LED ?

I am yes. It’s got an energine hat on it.

Do you have lirc working without openhab? and if so, is lirc set to listening mode?

Great, lirc is working on my pi, this means if I enter

irsend SEND_ONCE harman-kardon KEY_F4

or something like this, my receiver reacts. My /usr/lib/systemd/system/lirc.service file was empty, so I copied the content of the example form OH:

[Unit]
Description=Linux Infrared Remote Control
After=network.target

[Service]
RuntimeDirectory=lirc
ExecStart=/usr/sbin/lircd --nodaemon --driver=default --device=/dev/lirc0 --listen

[Install]
WantedBy=multi-user.target

Is this right as far ? Further, I am unsure with the IP addresses in .things: Do I have to insert the IP of my PI and the port 9001 or what would be right here?

service looks right. It’s the ip of the lirc and port 8765 i think is the default. add an lirc server thing, and then add the remotes.

you can test if your server is listening using netcat

echo “SEND_ONCE harman-kardon KEY_F4” | nc localhost 8765

ok, here’s my .thing:

Bridge lirc:bridge:local [ host="192.168.1.187", port="8765" ] {
    Thing remote harman-kardon [ remote="Harman-Kardon" ]
}

.rules

rule "TV Remote"

when
	Item GF_Living_Remote received command
then
	if (receivedCommand == 1)
	{
		lirc.apply("harman-kardon", "KEY_POWER", logName)
	}
	else 
	{
		lirc.apply("harman-kardon", "KEY_POWER2", logName)
	}
	
end

.items


Number		GF_Living_Remote			""										<none>					(gLounge)		{ autoupdate="false" }
String		Remote_harman_kardon																						{ channel="lirc:remote:local:harman-kardon:transmit" }

I modified the rule a bit to see if it works. Unfortunately, it doesn’t so far…

Sorry, I use this the first time. Do I easily have to insert this into shell?

echo “SEND_ONCE harman-kardon KEY_F4” | nc localhost 8765

Yeah straight from your bash shell.

There’s no reaction from the receiver, there must be a problem with my lirc server. Can I check in any file, if my remote harman-kardon is detected by the server correctly?

Have you got the lirc function in the rule?

If not you can cut that out using the below

rule "TV Remote"
when
	Item GF_Living_Remote received command
then
	if (receivedCommand == 1)
	{
         sendCommand("Remote_harman_kardon", "KEY_POWER")
	}
         sendCommand("Remote_harman_kardon", "KEY_POWER2)
	}
end

Actually,

Sorry for being all over the place i’ve spotted it.

You need to make sure you have the function parts from my rule.

and then the following

change

lirc.apply("harman-kardon", "KEY_POWER", logName)

to

lirc.apply("harman_kardon", "KEY_POWER", logName)