Awesome, Da Flex! No chance i would guess this.
You're the King!
Awesome, Da Flex! No chance i would guess this.
You're the King!
Hi guys,
LibreELEC:~ # python
Python 2.7.16 (default, Nov 23 2019, 02:28:55)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named RPi.GPIO
>>>
Search in forum shows that people encountered the problem above resolved it with installing "Raspberry Pi Tools" add-on.
Tried even download the latest tar.gz from RPi.GPIO · PyPI and install it manually => failed on missing compilers and dependencies...
Tried to uninstall the "Raspberry Pi Tools" add-on and install it again.
Tried to install "System tools" too... maybe dependecies... No luck.
Running LE 9.2.0 + Kodi 18.5. Log.
I noticed, when installing add-on, it reports on dependency of LE 9.1, not 9.2. Can be this a root cause of poor installation of RPi.GPIO?
Is it possible to manage packages from command line(shell, bash)? How?
I might try to install pigpio or RPIO...
Thank you, guys, for your patience! Your vast knowledge made my project working.
In addition to the "Controlling LibreELEC with LG TV IR remote guide" my contribution to the forum back is:
The guide of IR command translation with LibreELEC.
Purpose: Make additional IR device (LED strip in this case) to be controlled from TV remote. So TV + Kodi + Additional device are controlled with one IR RC. In this case, The TV remote turns TV and LED strip on/off + navigates in Kodi.
High level explanation: The IR signal from TV IR RC is parsed by LIRC in RasPi and passed to Kodi as key_name pressed. Kodi applies proper action per each key_name. For navigation internal Kodi actions used. For LED control additional LIRC channel used as lirc_tx. Kodi runs stateful python script which runs shell command ir-ctl.
Steps:
1. As Hias advised above, connect IR receiver to GPIO17, powered by 3.3V. And connect the transmitting IR LED 940nm via simple transistor amplifier to GPIO18. Expose IR receiver towards you, and IR transmitter towards the IR LED controller. Done with the hardware!
2. As advised here with minor mods:
mount -oremount,rw /flash
nano /flash/config.txt
#add these lines above section [all]
dtoverlay=gpio-ir,gpio_pin=17
dtoverlay=pwm-ir-tx,gpio_pin=18
#Ctrl+X -> Y -> Enter
mount -oremount,ro /flash
3. Configure udev rules:
nano /storage/.config/udev.rules.d/71-lirc.rules
#add these lines
ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="gpio_ir_recv", SYMLINK+="lirc-rx"
ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="gpio-ir-tx", SYMLINK+="lirc-tx"
ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="pwm-ir-tx", SYMLINK+="lirc-tx"
#Ctrl+X -> Y -> Enter
4. Configure LIRC options for both RX and TX channels.
cp /etc/lirc/lirc_options.conf /storage/.config/
cd $_
cp lirc_options.conf lirc_tx_options.conf
nano lirc_options.conf
#set proper parameters, avoid duplication thus
device = /dev/lirc-rx
listen = 0.0.0.0:8766
#Ctrl+X -> Y -> Enter
nano lirc_tx_options.conf
#set proper parameters, avoid duplication thus
device = /dev/lirc-tx
output = /var/run/lirc/lircd-tx
pidfile = /var/run/lirc/lircd-tx.pid
listen = 0.0.0.0:8765
connect = 127.0.0.1:8766
#Ctrl+X -> Y -> Enter
Display More
5. Create LIRC TX service:
cd /storage/.config/system.d/
mkdir system
cd system/
systemctl cat lircd > lircd-tx.service
nano lircd-tx.service
#make sure these lines are unique:
[Unit]
Documentation=man:lircd(8)
Documentation=http://lirc.org/html/configure.html
Description=Second lircd, the transmitter
Wants=lircd-setup.service
After=network.target lircd-setup.service lircd.service
[Service]
Type=simple
ExecStart=/usr/sbin/lircd --nodaemon --options-file /etc/lirc/lirc_tx_options.conf
# Do not alter [Install] section
#Ctrl+X -> Y -> Enter
systemctl cat lircd.socket > lircd-tx.socket
nano lircd-tx.socket
#make sure these lines are unique:
[Socket]
ListenStream=/run/lirc/lircd-tx
[Install]
WantedBy=sockets.target
Also=lircd-tx.service
#Ctrl+X -> Y -> Enter
Display More
6. As Da Flex advised, create keymap file /storage/.kodi/userdata/keymaps/remote.xml and paste into it:
<keymap>
<global>
<remote>
<power>RunScript(/storage/toggle_led.py)</power>
</remote>
</global>
</keymap>
7. Map Power key to action in /storage/.kodi/userdata/Lircmap.xml:
<lircmap>
...
<!-- Place your RC name here as stated in lircd.conf -->
<remote device="LG_AKB72915207">
...
<power>KEY_POWER</power>
...
</remote>
...
</lircmap>
At this step I commented out all <power> actions from other devices in Lircmap: I don't want any chance that something will shut the LE off.
8. Place the LED toggling script in /storage/toggle_led.py:
#!/usr/bin/env python
import os
indicator = '/tmp/led_on'
command = '0xef03'
if os.path.isfile(indicator):
os.remove(indicator)
command = '0xef02'
else:
open(indicator, 'a').close()
os.system('ir-ctl -S necx:' + command)
Display More
Just in case, make the script executable: chmod a+x /storage/toggle_led.py
How did I get the IR codes? Hias explained above ir-ctl -r
9. reboot
After reboot you might test the LED work from the script by running it manually from bash.
That's it.
Yoohoo! Thank you Iridium... messed remount with nolock...
The additional overlay made lirc0 transmitting!
And LEDs are on/off with ir-ctl. Trying to make it working end-to-end.
Update:
As Hias said: lirc0 and lirc1 created with 2 overlays in random order.
I found another discussion about configuring udev rules for lirc.
/storage/.config/udev.rules.d can keep the rules.
However, i don't see how to keep other files like:
/etc/lirc/lirc_options.conf
/etc/lirc/lirc_tx_options.conf
/etc/systemd/system/lircd-tx.service
And how to tell LE that lirc0 now is lirc-rx?
Yes, I was puzzling how to get RPi.GPIO lib couple days ago. Installed add-on "Raspberry Pi Tools" from LE GUI as the Internet recommends. Still can't import RPi.GPIO. Tried even download the latest tar.gz from RPi.GPIO · PyPI and install it manually => failed on missing compilers and dependencies... I am afraid to ruin the LE... so ir-ctl looks very reasonable way to go.
Now I ran into other trouble:
LibreELEC:~ # mount -o nolock,rw /flash
mount: can't find /flash in /etc/fstab // the trouble
LibreELEC:~ # mount | grep flas
/dev/mmcblk0p1 on /flash type vfat (ro,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
LibreELEC:~ # cat /etc/fstab
LibreELEC:~ # grep flash /etc/mtab
/dev/mmcblk0p1 /flash vfat ro,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro 0 0
LibreELEC:~ #
Just wanted to add another dtoverlay into /flash/config.txt.
The Internet advises to write into /etc/fstab. I understand that /etc/fstab is created dynamically on LE boot. Correct? mtab looks OK... So if I add the line it will be removed on reboot...
Please, help.
Thank you so much, Matthias and Da Flex!
<power>RunScript(/full/path/to/your/python/script)</power>
That was the missing link in my understanding. Now I can invoke a script which can determine the current status and send appropriate command.
better avoid lircd [for transmitting].
You can use ir-ctl instead for sending...
I like the variant of ir-ctl. I am able to record protocol and scancode!
From ir-ctl help:
Quote-d, --device=DEV lirc device to use
It seems i must specify the sending LIRC, while "better avoid lircd" and in my config there still just one overlay. Is adding one more overlay to transmit as explained above will give ir-ctl ability to transmit via /dev/lirc0?
Thank you Hias.
So far:
- There's ready lircd.conf file for the LED controller I have. Is it useful for sending IR commands? Or lircd.conf is just for receiving commands?
- I connected the IR LED with transistor amplifier to GPIO17 on Raspi. I know how to tell to LIRC which pin to listen (dtoverlay=gpio-ir,gpio_pin=18). How to configure other pin to transmit? I found an example for dtoverlay for lirc, I can't find similar example for gpio-ir.
Hi Da Flex, thank you for quick response.
Connect an IR sending LED with the RPi
Seems my 2nd proposal isn't that bad
This sending process will be triggered when the RPi receives the "TV Power" button press over CEC.
You can use LE's key mapping to start your script by "TV Power" button press.
So the question is: What to configure and where in Kodi file system to run my script on receive of "Power" IR signal? I guess it should be a reference in Lircmap.xml... but how? I'm lost at this point.
The RPi "knows" whether "TV Power" on/off means
That's cool! How do I read the status of TV power on/off?
Another update:
Both lircd.conf and Lircmap.xml have definition for 'power' button on the RC.
Not clear how this can be useful: once you shut Raspi down with RC, you can't turn it on.
To workaround this I removel all lined in both files which contain word 'power'.
Now the RC turns the TV on and off, however Raspi is always on.
Hi guys,
How it is possible to run an external command when specific IR command received by LIRC?
Details:
I have surround LED lighting behind the TV. The light is controlled with dedicated IR remote.
Every time I turn the TV on and off, I should remember to turn the LEDs too. Not a big deal, just not comfortable.
Once I managed to control Kodi with TV remote, I thought the same remote can control the LED light as well.
And OpenELEC over Raspberry pi might be the translator.
Possible solutions:
1. When "Power" key received, transmit MQTT command to separate IR transmitter. The transmitter will do the rest. This requires additional MCU and depends on network. Not the best solution.
2. When "Power" key received, bit-bang GPIO with codes of LED light controller. The IR LED need to be connected to the GPIO. This is wired solution, not the best too.
What's optimal way to transmit IR command by receiving other IR command over LIRC?
Hi guys,
Reading this cool document didn't help me to make the RC working. Please, advise.
The IR receiver is connected to GPIO 18 on Raspberry PI 3 model B, running LibreELEC 9.2.0.
The log with configuration is here. Not sure I inserted the dtoverlay line in proper place of /flash/config.txt.
The lirc is up.
# ps -ef | grep lirc
246 root 0:00 /usr/sbin/eventlircd -f --evmap=/etc/eventlircd.d --socket=/run/lirc/lircd
# ir-keytable
Found /sys/class/rc/rc0/ (/dev/input/event2) with:
Name: gpio_ir_recv
Driver: gpio_ir_recv, table: rc-rc6-mce
lirc device: /dev/lirc0
Supported protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon rc-mm
Enabled protocols: lirc nec rc-6
bus: 25, vendor/product: 0001:0001, version: 0x0100
Repeat delay = 500 ms, repeat period = 125 ms
Display More
At this moment Kodi does not react on RC keys.
I found the proper RC configuration file for LIRC for the RC I have (TV LG xx-LW5700-yy), which looks different from all descriptions of the document above. I understand the file describes the protocol of LG TV.
Update: Solved
This awesome page was a good start to connecting things together.
Here's a guide for newbies like me. Maybe this will help someone with info abuse and docs distraction.
Apparently, no need to 'enable LIRC' or install any service/software to have the IR RC working.
1. Get any Arduino-type IR receiver connected to Raspberry PI. Default pins:
IR -- RasPI
Vin -- 3.3V (Raspi GPIO intolerant to 5V, use 3.3V to not burn the CPU).
Out -- GPIO18 (you can choose any IO - just update the config later properly).
Gnd -- Gnd
2. Find and download the closest possible lircd.conf file in the internet. Look on part number or model name on your IR RC, search to your appliance model, be creative. In my case, the IR RC model matched first 5 symbols with what was published in sourceforge, and it works.
3. Configure /flash/config.txt as following:
mount -oremount,rw /flash
nano /flash/config.txt
<add next line above [all] section>
dtoverlay=gpio-ir,gpio_pin=18
Ctrl+X -> Y -> Enter
mount -oremount,ro /flash
4. Put the conf file you've found in step 2 at /storage/.config/lircd.conf. Usually, the files are published with model number before lircd.conf. So keep just lircd.conf as file name. You are going to work with this file a lot in next step. So keep it open in side window.
5. Prepare template for your own RC:
6. Add your RC into Lircmap.xml:
nano /storage/.kodi/userdata/Lircmap.xml
pick/cope any ready configuration in the file. The configuration starts from tag <remote .... and finishes with </remote>
paste it under any remote, but above the </lircmap> tag.
change <remote device="..."> with the name you device conf file you've found in step 2. Look into the lircd.conf, as said in step 4.
change required key functions accordingly to key names in lircd.conf, as said in step 4.
Ctrl+X -> Y -> Enter
7. reboot
That's it. Booted Kodi works with your RC.
Now I can control both TV and Kodi with the same remote