rPi Sniffer - Hass.io

Hello everyone - prior to moving over to Hass.IO, I was using hassbian, which allowed me to sniff RF codes for my outlets. Well, we moved into new house and I’d like to get the RF outlets working gain, but I’ve lost the codes and can’t seem to figure out how it is possible to sniff using Hass.IO.

I have the RF tx/rx receivers in my Pi from before.

1 Like

I would like to know this as well. Afaict there is no way to install the required rpi_rf module needed for the rpi-rf_receive.py script to work but then again shouldn’t it already be somewhere inside of Hass.io?

1 Like

I tried to make an add-on to run that script and it looks like it’s working… at least at the end it says it’s listening on the pin 27.
Make a directory in the add-on share and call it “rpi-rf_receiver” and copy the 3 files:

  • Dockerfile
  • config.json
  • run.sh

You can find here: https://drive.google.com/folderview?id=1XiXGIPcWoF5gRuos1HLoR_1-tQ7hzFOE

  • Dockerfile:
    ARG BUILD_FROM
    FROM $BUILD_FROM

    ENV LANG C.UTF-8
    RUN apk add --no-cache jq
    RUN apk add --no-cache py2-pip
    RUN apk add --no-cache clang
    RUN apk add --no-cache libgcc
    RUN apk add --no-cache gcc-gnat
    RUN apk add --no-cache libgc++
    RUN apk add --no-cache g++
    RUN apk add --no-cache make
    RUN apk add --no-cache libffi-dev
    RUN apk add --no-cache openssl-dev
    RUN apk add --no-cache python2-dev
    RUN apk add --no-cache mosquitto
    RUN apk add --no-cache mosquitto-dev
    RUN apk add --no-cache mosquitto-clients
    RUN apk add --no-cache mosquitto-libs
    RUN pip install pyaes
    RUN pip install pycrypto
    RUN apk add --no-cache \
        	jq \
            py-pip \
    	python \
    	python-dev \
    	python3 \
    	python3-dev\
     && pip install -U pip \
     && pip3 install -U pip \
     && pip install -U virtualenv

    COPY run.sh /
    RUN chmod a+x /run.sh

    CMD [ "/run.sh" ] 
  • config.json
    {
        "name": "RPi RF Receiver",
        "version": "1.0",
        "slug": "rfreceiver",
        "description": "RPi RF Receiver Script",
        "startup": "application",
        "boot": "auto",
        "devices": ["/dev/mem:/dev/mem:rw"],
        "privileged": ["SYS_RAWIO"],
        "gpio": "true",
        "ports": {"5055/tcp": null},
        "options": {
      "code": "/share/rpi-rf_receive.py",
      "requirements": [
        "rpi-rf"
      ],
      "clean": true
    },
        "schema": {"code": "str",
    	       "requirements": ["str"],
    	       "clean": "bool?"},
        "map": ["share"]
    } 
  • run.sh
    #!/bin/bash
    set -e

    requirements=$(cat /data/options.json | jq -r 'if .requirements then .requirements | join(" ") else "" end')
    code=$(cat /data/options.json | jq -r '.code')
    clean=$(cat /data/options.json | jq -r '.clean //empty')
    py2=$(cat /data/options.json | jq -r '.python2 // empty')

    PYTHON=$(which python3)

    if [ "${py2}" == "true" ];
    then
        PYTHON=$(which python2)
    fi

    if [ -n "$requirements" ];
    then
        if [ "$clean" == "true" ];
        then
    	rm -rf /data/venv/
        fi
        if [ ! -f "/data/venv/bin/activate" ];
        then
           mkdir -p /data/venv/
           cd /data/venv
           virtualenv -p ${PYTHON} .
           . bin/activate
        fi
        pip install -U ${requirements}
    fi
    python ${code} 

If I’m not wrong you should make the run.sh executable going inside the directory /addon/rpi-rf_receiver and using the command “chmod +x run.sh”.
Then copy rpi-rf_receive.py in the “share” share of your hassio.
Now, install the add-on going inside the Hass.io add-on section and refreshing the list. After installing it, in the option section you should see this:

    {
      "code": "/share/rpi-rf_receive.py",
      "requirements": [
        "rpi-rf",
      "clean": true
      ]
    }

Now start the add-on and refreshing the logs this is what you should see:

starting version 3.2.2
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /data/venv/bin/python3
Also creating executable in /data/venv/bin/python
Installing setuptools, pip, wheel...done.
Collecting rpi-rf
  Downloading rpi-rf-0.9.6.tar.gz
Collecting RPi.GPIO (from rpi-rf)
  Downloading RPi.GPIO-0.6.3.tar.gz
Building wheels for collected packages: rpi-rf, RPi.GPIO
  Running setup.py bdist_wheel for rpi-rf: started
  Running setup.py bdist_wheel for rpi-rf: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/16/e2/54/205bfe1826862c70b36a59d02c340d06726cdbd82f5b88dfdb
  Running setup.py bdist_wheel for RPi.GPIO: started
  Running setup.py bdist_wheel for RPi.GPIO: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/ae/4d/3b/e924997dbf06810adf3b2e37f1d9627b2327eb9cbb285949c9
Successfully built rpi-rf RPi.GPIO
Installing collected packages: RPi.GPIO, rpi-rf
Successfully installed RPi.GPIO-0.6.3 rpi-rf-0.9.6
2017-11-08 19:43:08 - [INFO] rpi-rf_receive: Listening for codes on GPIO 27

I’m not really a coder, so I made it just copying and pasting other projects, let me know if it works guys

I don’t have the hardware but I wanna buy it, so let me know if it works :+1:

I just received my RF Receiver and it looks like it’s working.

I also modified the rpi-rf_receive.py script so that the addon writes the values it receives into a mqtt variable which is called “sensors/rf/receiver”:

codici2

1 Like

Works great! Thanks for taking the time to do this!!

1 Like

Wonderful - genius! I’ve been away and saw this on my return so super excited to give it a go tonight. Thanks!

Actually I’m not sure it works correctly. I tried to use a rf receiver on a RPi-1 with Hassbian and it works correctly but with this addon on a Rpi-3, it keeps reading ghost signals. @motoolfan, does it work correctly on your Hassio?

I’m trying it now actually. Gotten as far as “Install” but it doesn’t actually install anything. Followed your steps as described.

It takes a few minutes to install.

Have you made the run.sh file executable with the “chmod +x run.sh” command? Eventually try to reboot…

Oh, ok, in my case I found out where the problem was. I had, don’t know why, to use the 3,3 V pin insted of the 5V… and now it works perfectly…

I’ve not noticed any ghost signals

1 Like

When I downloaded the files from google drive, there was an extension .txt added to dockerfile. You need to copy the the contents into a new file and name it Dockerfile. Not sure if removing the extension will work.

1 Like

Ok I’ll give that a try. I did remove the .txt extension. I’m on a Mac so figured it was fairly straightforward.

ok, this is all new to me, so I’m not sure I’m doing it the right way, anyway, I tried to make a repository on GitHub so you can install it directly from there. Try to add this repository to your hassio:

And let me know if it works :wink:

@motoolfan, it’s strange that Drive adds an extension which is not there, good to know.

Ok thanks - Trying your repo now. Although it’s been spinning circle on the Install button for the past 5 minutes :smile:

Quick update - did a restart on HassIO - now won’t launch. Currently doing an update to HassIO over terminal.

Really? I did installed on my RPi and it works correctly. Is it possible that your disk was full?

So this is fun. HassIO won’t start up now :blush:. I think I’ve royally messed things up.

   \h:\w\$ hassio homeassistant check
    Error on homeassistant/check: starting version 3.2.2
    Traceback (most recent call last):
      File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
      File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
      File "/usr/lib/python3.6/site-packages/homeassistant/__main__.py", line 374, in <module>
    sys.exit(main())
      File "/usr/lib/python3.6/site-packages/homeassistant/__main__.py", line 349, in main
    args = get_arguments()
      File "/usr/lib/python3.6/site-packages/homeassistant/__main__.py", line 90, in get_arguments
    import homeassistant.config as config_util
      File "/usr/lib/python3.6/site-packages/homeassistant/config.py", line 23, in <module>
    from homeassistant.core import callback, DOMAIN as CONF_CORE
      File "/usr/lib/python3.6/site-packages/homeassistant/core.py", line 41, in <module>
    import homeassistant.util.location as location
      File "/usr/lib/python3.6/site-packages/homeassistant/util/location.py", line 10, in <module>
    import requests
      File "/usr/lib/python3.6/site-packages/requests/__init__.py", line 76, in <module>
    check_compatibility(urllib3.__version__, chardet.__version__)
    AttributeError: module 'chardet' has no attribute '__version__'

Tried several reboots and no joy.