Rtl_433 - how to get output to HA

i looked at the code and the options a bit and i am sure that it should be possible to get the decoded output to a file with the options somehow.

but i have no possibility to check it out.
probably you better take it up with the person who created the app.

Why are you trying to get output other than what you’re currently getting? Redirecting to a file is giving you what you want, all you need is to do the above suggestion and then you’re an awk, tail, and grep away from getting the actual number.

i think that writing another py which transports the values to a second file is an option. but i myselve would only use that option if i couldnt get it to work without that.

continously running a second py code to extract the values would use more resources then needed and would give a bigger failurerisk then needed, if it is possible without it.

Josh - You’ve hit the nail on the head. I’ve been over thinking it. Thanks.

I came up with this and it’s working a treat… (I suppose I ought to clear down the log file though somehow at some point in time - it writes every six seconds).


@reboot sleep 30 && sudo rtl_433 -q -R 43 > /home/pi/emon/elec 2>&1

*/1 * * * * mosquitto_pub -h custard-pi -d -t "elec" -m `tail -n 2 /home/pi/emon/elec | head -n 1 | cut -c9- |  grep -o -E '[0-9]+'`

It’s working great - is this a valid solution, guess so. :slight_smile:

It is using a fair amount of pi cpu though…

731 root       20   0 37304 26608  1736 S 18.8  2.8  1h27:03 rtl_433 -q -R 43
16:31:15 up  8:32,  2 users,  load average: 0.67, 0.38, 0.29

thanks all.

now clearing the log file down every minute also …

*/1 * * * * mosquitto_pub -h custard-pi -d -t "elec" -m `tail -n 2 /home/pi/emon/elec | head -n 1 | cut -c9- |  grep -o -E '[0-9]+'` && > /home/pi/emon/elec

enhancement might be to filter out the “kettle spikes” so as to get a nice baseline elec usage.

Well kind of happy with my solution but rtl_433 is using up a heck of a lot of CPU on my Pi, not so happy about that.

Hi bingobo,

I am having the same issues that you have. Via command line I can get Acurite info, however, how do I link that to HA? Can you kindly elaborate?

Thanks,
Guy

Hi All,

I am in the same situation, but didn’t really got how to solve it-

Here is the shell, how do I make HA get this info so I can create scenarios?

pi@raspberrypi:~ $ rtl_433 -q -R 39
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
Sample rate set to 250000.
Bit detection level set to 0 (Auto).
Tuner gain set to Auto.
Tuned to 433920000 Hz.
2016-12-04 18:51:51 : Acurite tower sensor : 13851 : A
Temperature: 0.6 C
Humidity: 73
Battery: 0
: 68
2016-12-04 18:51:51 : Acurite tower sensor : 13851 : A
Temperature: 0.6 C
Humidity: 73
Battery: 0
: 68
2016-12-04 18:51:51 : Acurite tower sensor : 13851 : A
Temperature: 0.6 C
Humidity: 73
Battery: 0
: 68
2016-12-04 18:51:52 : Acurite tower sensor : 5486 : C
Temperature: 0.9 C
Humidity: 73
Battery: 0
: 68
2016-12-04 18:51:52 : Acurite tower sensor : 5486 : C
Temperature: 0.9 C
Humidity: 73
Battery: 0
: 68

Thanks for the support :slight_smile:
Guy

if you can convert/parse the output from the rtl_433 script to json, you can use the HTTP API to post it directly to HA (without saving to a file).

Some code I used to post data from energy meters using the ec3k module: https://github.com/molobrakos/ec3kscan

# run the radio scanner, feed data into home assistant, and keep a gzipped log
rtl_433 | tee >(./ha-feeder) | gzip > rtl_433.log.gz

ha-feeder:

#!/usr/bin/python
import requests
import json
API_URL="http://localhost:8123/api/"
if __name__ == '__main__':
    session = requests.Session()
    while True:
        line = stdin.readline()
        if not line:
            break  # end of stream
        try:
            data = json.loads(...)
        except ValueError:
            continue

        data["unit_of_measurement"] = "W"
        data["icon"] = "mdi:speedometer"

        data = json.dumps(dict(state=data["power"],
                               attributes=data))

        sensor_id = data["sensor_id"]
        entity = "sensor.rtl433_%s" % sensor_id

        url = "%s%s/%s" % (API_URL, "states", entity)
        print("Posting to url %s" % url)
        headers = {"Content-Type": "application/json"}
        try:
            response = session.post(url, headers=headers, data=data)
            response.raise_for_status()
        except:
            print("Failed to post to url %s" % url)
1 Like

Hi Falks,

Well, I am still a bit lost and need some assistance.

I’ve created the following script (based on molobrakos tips):
433.py:

#!/usr/bin/env python3
import homeassistant.remote as remote
from subprocess import Popen, PIPE
import json

api = remote.API('127.0.0.1', 'PASSWORD')

with Popen(['rtl_433', '-F', 'json', '-C', 'customary', '-R', '39'], stdout=PIPE, bufsize=1, universal_newlines=True) as p:
    for line in p.stdout:
        tjson = json.loads(line)
        #print(tjson)
        temp = "%.1f" % tjson['temperature_F']
        humidity = tjson['humidity']
        print('temp %s' % temp)
        print('humidity %s' % humidity)
        # Getting the ID from tjson and matching it up with
        # the string name of the sensor in HomeAssistant is
        # left as an exercise to the reader
        remote.set_state(api, ????? , new_state=temp)

So… now what? How to configure the HA to get the temp and the humidity?

Thanks,
Guy

I think HA with create the device in HA automatically if you just feed it data through the API. Then you can customize name, icons etc via the customize-section in your configuration. Alternatively, you can set it to hidden and create a template-sensor in HA that consumes data from it.

(you don’t need the Popen-things, if you instead just start the script with
rtl_433 -F json -C customary -R 39 | ./my_script)

You could send all events to MQTT with this script or dockerimage: https://github.com/roflmao/rtl2mqtt

I am doing what is suggested at this blog: https://esp8266hints.wordpress.com/2017/03/21/cat-successfully-skinned/

Basically pipe the rtl_433 output directly to mqtt like this:

rtl_433 -F json | mosquitto_pub -l -t sensors/rtl_433

1 Like

thanks guys. just received my rtl device from aliexpress. checked out the script here https://esp8266hints.wordpress.com/2017/03/21/cat-successfully-skinned/ and mosquitto receveives the data, added the sensor and BINGO!!

Hi guys - just new to HA & I’ve got currentcost. Any pointers re where best to start re trying to get currentcost connected up/working with HA? Existing component? or anyone have Python code I could use?

( did post a question here earlier - CurrentCost data into Home Assistant? )