ok, I hear you - thanks for this - at least I’m not going nuts. I get it - It’s doing what it should, just not what I need.
Yes, i played with the output options of rtl_433 to try and find a way but no luck. Just specifying a filename actually seems to decode the radio singals on the fly - recording if you like - you end up with megabytes of undecoded radio signal data in a few seconds!
pi@custard-pi:~ $ sudo rtl_433 -q -R 43
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-10-31 16:13:31 : CurrentCost TX
Device Id: 3709
Power 0: 0 W
Power 1: 444 W
Power 2: 0 W
2016-10-31 16:13:37 : CurrentCost TX
Device Id: 3709
Power 0: 0 W
Power 1: 446 W
Power 2: 0 W
in the file I redirect to I just get…
2016-10-31 16:13:31 : CurrentCost TX
Device Id: 3709
Power 0: 0 W
Power 1: 444 W
Power 2: 0 W
2016-10-31 16:13:37 : CurrentCost TX
Device Id: 3709
Power 0: 0 W
Power 1: 446 W
Power 2: 0 W
....... and on and on....
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).
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?
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)
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?