Hi All,
Did the hard bit - now can’t do the easy bit !
I got a energy monior (current cost) and I got a cheap SDR stick for my pi. Installed a load of stuff and after some pain installing the libraries and usb hub for power I can do this…
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
So I thought - happy days - all i need to do now is redirect output to a file and have HA read it.
I ca’t do that bit !
I was planning to grep / awk the output down to the wattage number (most recent) so in this case 446. and then overwrite a file continually with that number.
I thought just…
sudo rtl_433 -q -R 43 > /path/to/datafile
but that appends I thought > should overwrite. “>>” is append. Anyone help me with the secret sauce?
anyone able to help, probably more of a linux / bash question but if I get this working I can then get it hooked up to HA via a command line sensor I guess.
I have appdeamon installed and with that it would be simple to split out the file to anything you like and then use it in HA.
without that i have to little knowledge from Linux to be able to do such a thing.
yes - thanks - that was my first instinct. It works but unfortunately the file keeps growing, the latest reading is appended to the bottom of the file.
that’s right - I get “two”, just did it. No strange aliases AFAIK…
I guess the problem is that the application rtl_433 is continually churning out this log of values and the whole thing is getting added to my file rather than just the latest… bit frustrating
ahhh, no - I’m at the first stage, getting the data onto the pi in a sensible form.
Here’s the app…
basically it reads a USB SDR stick and which is monitoring an electricity reader (current cost). I thought I’d done the tricky bit when I got the readings on my screen…
yes tried that - got the same result - appended data to the file ( new reading every six seconds or so.
need sudo to run the command I think the privilege is required to get the readings, I don’t think that’s the problem though - maybe just the way the app writes out the data in a rolling fashion?
oh – so the program continues running. Well, this is the expected behavior then – it keeps stdout open, and you are redirecting it to a file, which is being appended to because the stream is still open.
You could:
do what you’re doing now, writing to file A (or as @ReneTode just mentioned, instead of redirecting using >, look at the usage for rtl_433 which says you can just specify a filename, either way, same result)
write another script which will loop forever, open file A, look for the last occurrence of your search string, append THAT to another file, file B, (which will be overwritten each time), delay, recur the loop
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....