Page 1 of 3

IR Sensor on Raspberry Pi 3

Posted: Sunday 12 March 2017 1:23
by Harlov
Hey all

I have a Raspberry Pi 3 and razberry2 and Domoticz installed and so I would like to install an IR receiver to Domoticz, How to add USB IR receiver in Raspberry to make it work with domoticz. Or there are other solutions for this

someone who can help me with this

/Peter

Re: IR Sensor on Raspberry Pi 3

Posted: Sunday 12 March 2017 10:25
by Harlov
No one who can help me

Re: IR Sensor on Raspberry Pi 3

Posted: Sunday 12 March 2017 12:13
by Nautilus
Have you checked out Flirc if it would suit your needs?
https://www.domoticz.com/forum/viewtopi ... 33#p123013
https://flirc.tv/

Re: IR Sensor on Raspberry Pi 3

Posted: Sunday 12 March 2017 14:00
by supermat
Hello i make a tutorial (in french) for a receiver directly connected to the GPIO.
https://matdomotique.wordpress.com/2016 ... arouge-ir/


Envoyé de mon iPhone en utilisant Tapatalk

Re: IR Sensor on Raspberry Pi 3

Posted: Sunday 12 March 2017 14:52
by Harlov
thanks for the information

But how do I do an installation with FLIRC USB to Raspberry Pi

Re: IR Sensor on Raspberry Pi 3

Posted: Sunday 12 March 2017 14:55
by Harlov
supermat wrote:Hello i make a tutorial (in french) for a receiver directly connected to the GPIO.
https://matdomotique.wordpress.com/2016 ... arouge-ir/


Envoyé de mon iPhone en utilisant Tapatalk
thanks for the information
Gets a little difficult when I have RazPberry Z-Wave module installed

Re: IR Sensor on Raspberry Pi 3

Posted: Sunday 12 March 2017 22:49
by Nautilus
Harlov wrote:thanks for the information

But how do I do an installation with FLIRC USB to Raspberry Pi
It goes something like this:

1. Install the Flirc configuration software (to pc/mac) and plug in the Flirc to this computer
2. Using the configurator, link IR commands of your choice to key combinations (whatever key combinations you prefer)
3. Plug Flic to your RPi in such way it can receive IR commands (I used a 2m USB extension chord as my RPi is in a cabinet), Flirc is automatically recognised as a keyboard so nothing needs to be installed
4. Raspbian comes pre-installed with a program called Triggerhappy (thd), use this program to link the key combinations to Domoticz json calls
5. Now you can use any IR command to trigger any Domoticz action! :D

To configure the triggerhappy program, go to "/etc/triggerhappy/triggers.d" and create a new text file (I use domoticz.conf) with lines like (in this example the IR command is tied to SHIFT+CTRL+1):

Code: Select all

KEY_1+KEY_LEFTSHIFT+KEY_LEFTCTRL 1 curl -s "http://url:port/json.htm?type=command&param=switchlight&idx=IDXofNEOplug&switchcmd=On"
Works well for my purposes.

Re: IR Sensor on Raspberry Pi 3

Posted: Monday 13 March 2017 20:13
by Harlov
I thank you very much for this :D

What I do not understand is how to start Trigger Happy (thd) .. I start it with
Example PUTTY?

Thanks again for your help

Re: IR Sensor on Raspberry Pi 3

Posted: Monday 13 March 2017 20:33
by Harlov
I think it worked now

Is this right?

Play Button
EV_KEY KEY_PLAYPAUSE 1 /dev/input/event0
# KEY_PLAYPAUSE 1 command
EV_KEY KEY_PLAYPAUSE 0 /dev/input/event0
# KEY_PLAYPAUSE 0 command

Pause Button
EV_KEY KEY_PLAYPAUSE 1 /dev/input/event0
# KEY_PLAYPAUSE 1 command
EV_KEY KEY_PLAYPAUSE 0 /dev/input/event0
# KEY_PLAYPAUSE 0 command

Stop Button
EV_KEY KEY_X 1 /dev/input/event0
# KEY_X 1 command
EV_KEY KEY_X 0 /dev/input/event0
# KEY_X 0 command

Re: IR Sensor on Raspberry Pi 3

Posted: Monday 13 March 2017 22:32
by Nautilus
Harlov wrote:I thank you very much for this :D

What I do not understand is how to start Trigger Happy (thd) .. I start it with
Example PUTTY?

Thanks again for your help
Well, in my Raspbian Wheezy it was running automatically by default, no need to install or do anything. Just check that you have a file called "triggerhappy" in /etc/init.d/ (check it e.g. by running cat /etc/init.d/triggerhappy - if you are running Jessie it might be something else). For testing purposes I used (http://manpages.ubuntu.com/manpages/tru ... thd.1.html) thd --dump /dev/input/event* which dumps all events processable by thd to the console (useful to find out the correct event name for a specific key). Some info also here: https://github.com/wertarbyte/triggerhappy. Both links contain examples of the .conf file as well.

edit. just in case you don't have it, the content of the triggerhappy file in /etc/init.d/ is:
Spoiler: show
#!/bin/sh
### BEGIN INIT INFO
# Provides: triggerhappy
# Required-Start: $local_fs $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: triggerhappy hotkey daemon
### END INIT INFO

# Author: Stefan Tomanek <[email protected]>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="input event daemon"
NAME=thd
PNAME=triggerhappy
DAEMON=/usr/sbin/thd
PIDFILE=/var/run/$NAME.pid
DAEMON_ARGS="--daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfile $PIDFILE --user nobody /dev/input/event*"
DAEMON_OPTS=""
SCRIPTNAME=/etc/init.d/$PNAME

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$PNAME ] && . /etc/default/$PNAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS $DAEMON_OPTS \
|| return 2
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
exit 3
;;
esac

:

Re: IR Sensor on Raspberry Pi 3

Posted: Monday 13 March 2017 22:47
by Nautilus
Harlov wrote:I think it worked now

Is this right?
....
Depends entirely on what you want to achieve and this I do not know...:) But at least you are not calling any Domoticz json url so does not look like anything that would integrate with Domoticz. Or was that just based on some event dump? You pressed "play/pause" key on an input device associated with /dev/input/event0? To associate this button press with something in Domoticz, the conf file would need to be something like:

Code: Select all

EV_KEY KEY_PLAYPAUSE 1 curl -s "http://url:port/json.htm?type=command&param=switchlight&idx=IDXofNEOplug&switchcmd=On"
Then the pressing of "play/pause" would switch the device with the specified idx "On"....

Re: IR Sensor on Raspberry Pi 3

Posted: Monday 13 March 2017 23:15
by Harlov
Thanks again for your help, I appreciate it

it looks like I've gotten it to work

then I have to create a new conf file for each button?

Have tried to think of where to save (play.conf) file somewhere
in which folder, I do not know where to place the conf file so domoticz can find it

Re: IR Sensor on Raspberry Pi 3

Posted: Monday 13 March 2017 23:35
by Nautilus
Harlov wrote:Thanks again for your help, I appreciate it

it looks like I've gotten it to work

then I have to create a new conf file for each button?

Have tried to think of where to save (play.conf) file somewhere
in which folder, I do not know where to place the conf file so domoticz can find it
First of all, the .conf file is for triggerhappy, not Domoticz. It tells triggerhappy to listen for certain key (combination) and then perform an action if it catches one of them. You save them in /etc/triggerhappy/triggers.d/

And what comes to number of .conf files one is enough, you can list everything you need there. But if you want to categorise them somehow then maybe more than one file is in order. I put all my commands going towards Domoticz to one file (domoticz.conf) and then other commands for controlling my squeezebox players to another file (squeezebox.conf). But as mentioned, no matter if you use one file, two or 100 :)

Re: IR Sensor on Raspberry Pi 3

Posted: Tuesday 14 March 2017 4:49
by asjmcguire
Probably the important point here that OP might not realise - is that when you change a conf file - in order to test it works with trigger happy - you will need to restart trigger happy.

probably - "sudo /etc/init.d/triggerhappy restart"

Re: IR Sensor on Raspberry Pi 3

Posted: Tuesday 14 March 2017 8:07
by Nautilus
asjmcguire wrote:Probably the important point here that OP might not realise - is that when you change a conf file - in order to test it works with trigger happy - you will need to restart trigger happy.

probably - "sudo /etc/init.d/triggerhappy restart"
Excellent point which is often overlooked when testing new .conf setup! :)

Re: IR Sensor on Raspberry Pi 3

Posted: Tuesday 14 March 2017 18:38
by Harlov
I can't seem to save config files in the root system (eg: /etc/triggerhappy/triggers.d/); it just says "permission denied" or the save option is blocked in the text editor.

Re: IR Sensor on Raspberry Pi 3

Posted: Tuesday 14 March 2017 23:11
by Nautilus
Harlov wrote:I can't seem to save config files in the root system (eg: /etc/triggerhappy/triggers.d/); it just says "permission denied" or the save option is blocked in the text editor.
Open some command line tool (e.g. telnet or something from the Raspbian desktop) and then "sudo nano /etc/triggerhappy/triggers.d/play.conf". Write or copy/paste the planned content and then close the nano editor by pressing CTRL+x (and press Y to save the file). Then reload Triggerhappy.

By the way, I though you were planning to buy some IR receiver, but I guess you already had one? Which type is it, some sort of media controls remote? That should work in similar way as I described my setup wit Flirc as long as the commands are recognized by Triggerhappy and based on the earlier posts (like "EV_KEY KEY_PLAYPAUSE") it seems they are...:)

Re: IR Sensor on Raspberry Pi 3

Posted: Tuesday 14 March 2017 23:21
by Harlov
I think I have got it working with savings in /etc/triggerhappy/triggers.d/ but when I need to type in Domoticz

EV_KEY KEY_PLAYPAUSE 1 curl -s "http://192.168.0.???:8080/json.htm?type ... t&idx=1=On"
EV_KEY KEY_PLAYPAUSE 1 curl -s "http://192.168.0.???:8080/json.htm?type ... &idx=1=Off"

I get the error message in Domoticz saying Invalid ON Action!

Of course I have changed the IP ich idx

Yes i have Flirc Ir

Re: IR Sensor on Raspberry Pi 3

Posted: Tuesday 14 March 2017 23:34
by Nautilus
Harlov wrote:I think I have got it working with savings in /etc/triggerhappy/triggers.d/ but when I need to type in Domoticz

EV_KEY KEY_PLAYPAUSE 1 curl -s "http: // url: port / json.htm? Type = Command & param = Switch light & idx = IDXofNEOplug & switchcmd = On"

I get the error message in Domoticz saying Invalid ON Action!

Of course I have changed the IP ich idx
I would first verify it ( = http: // url: port / json.htm? Type = Command & param = Switch light & idx = IDXofNEOplug & switchcmd = On) works in the browser. I think it's case sensitive so the string you have there will not work like that but I'm not sure if you just wrote something there and have the correct format in the .conf file (there are also some extra spaces on your example but perhaps those are because of some copy/paste issue? :))

It could also be security (disable authentication on local network), protected switch or something like that. Check the correct json syntax here: https://www.domoticz.com/wiki/Domoticz_ ... Fswitch_on

edit: I see you edited the post but the syntax is still wrong. Should be something like:

Code: Select all

http://192.168.0.???:8080/json.htm?type=command&param=switchlight&idx=1&switchcmd=On
note the added "&switchcmd

Re: IR Sensor on Raspberry Pi 3

Posted: Tuesday 14 March 2017 23:39
by Nautilus
Harlov wrote:...but when I need to type in Domoticz...
This I don't quite get. You should not be typing anything in Domoticz (not sure though if I understand the sentence correctly :))...
Harlov wrote: EV_KEY KEY_PLAYPAUSE 1 curl -s "http://192.168.0.???:8080/json.htm?type ... t&idx=1=On"
EV_KEY KEY_PLAYPAUSE 1 curl -s "http://192.168.0.???:8080/json.htm?type ... &idx=1=Off"
Also, why are you trying to link both On and Off to same ir command? :)