cpyarger / Home-Assistant-Addons

A hass.io addon for a software defined radio tuned to listen for Utility Meter RF transmissions and republish the data via Home Assistant's API
MIT License
9 stars 4 forks source link

Unable to start SDRMR addon successfully #20

Open N3rdP1um23 opened 1 year ago

N3rdP1um23 commented 1 year ago

Describe the bug Have tried to follow the instructions as best as possible and have attempted to use different ID's for the water/gas/electric components, though I'm unable to get it working. It also seems that it starts, doesn't find any devices, then crashes as it's unable to connect to the spectrum server.

To Reproduce Steps to reproduce the behavior:

  1. Install the addon following the steps in the readme
  2. Configure the addon
  3. Start the addon
  4. View addon logs

Expected behavior Start the addon, find the sensors, log the data in Home Assistant.

Screenshots N/A

Desktop

Additional context

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Starting RTLAMR with parameters:
AMR Message Type = all
AMR Device IDs =
Time Between Readings = 30
Duration =  15
Electric Unit of measurement =  kWh
Gas Unit of measurement =  m³
Water Unit of measurement =  l
Water measurements provided in tenths =  true
SCM PLUS GAS DIVISOR =  1
Debug is  true
No supported devices found.
13:52:54.704732 main.go:90: Error connecting to spectrum server: dial tcp 127.0.0.1:1234: connect: connection refused
rcvr.Connect
main.(*Receiver).NewReceiver
    /go/pkg/mod/github.com/bemasher/rtlamr@v0.9.3/main.go:90
main.main
    /go/pkg/mod/github.com/bemasher/rtlamr@v0.9.3/main.go:313
runtime.main
    /usr/lib/go/src/runtime/proc.go:250
runtime.goexit
    /usr/lib/go/src/runtime/asm_amd64.s:1571
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Is there possibly a way to continually listen to scans and view the data to determine which ids are the correct ones? Or even if it's setup/working to pickup data?

N3rdP1um23 commented 1 year ago

Okay, I was able to setup the package individually (outside of Home Assistant) and it seems I'm now able to grab both water and gas usage 🎊

Now that I've done it this way, it seems that the docker container is missing the rtl_tcp "spectrum" server running?

pasyn commented 1 year ago

The addon is not able to find the USB device. Assuming you are running HA on a RPI, try performing a power cycle and then check if the RTL-SDR dongle is detected.

N3rdP1um23 commented 1 year ago

I've set it back up on the HA server (was using my laptop to test rtlamr which worked) and it's detecting the USB properly, though I'm currently running into this timeout issue. I've also power cycled just to be sure as well as per your comment.

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Starting RTLAMR with parameters:
AMR Message Type = all
AMR Device IDs = ...........................
Time Between Readings = 30
Duration =  15
Electric Unit of measurement =  kWh
Gas Unit of measurement =  ft³
Water Unit of measurement =  l
Water measurements provided in tenths =  false
SCM PLUS GAS DIVISOR =  1
Debug is  false
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001
Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!
Tuned to 100000000 Hz.
Allocating 15 zero-copy buffers
10:58:45.369561 decode.go:45: CenterFreq: 912380000
10:58:45.370110 decode.go:46: SampleRate: 2359296
10:58:45.370128 decode.go:47: DataRate: 32768
10:58:45.370142 decode.go:48: ChipLength: 72
10:58:45.370156 decode.go:49: PreambleSymbols: 32
10:58:45.370168 decode.go:50: PreambleLength: 4608
10:58:45.370181 decode.go:51: PacketSymbols: 736
10:58:45.370193 decode.go:52: PacketLength: 105984
10:58:45.370215 decode.go:59: Protocols: scm,scm+,idm,r900
10:58:45.370232 decode.go:60: Preambles: 01010101010101010001011010100011,00000000000000001110010101100100,111110010101001100000,0001011010100011
10:58:45.370256 main.go:124: GainCount: 29
10:58:50.373988 main.go:343: Receiver context cancelled.
10:58:50.374516 main.go:320: read tcp 127.0.0.1:54122->127.0.0.1:1234: i/o timeout
io.ReadFull
main.(*Receiver).Run.func2
    /go/pkg/mod/github.com/bemasher/rtlamr@v0.9.3/main.go:181
runtime.goexit
    /usr/lib/go/src/runtime/asm_amd64.s:1571
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped
Signal caught, exiting!
Signal caught, exiting!
pasyn commented 1 year ago

Turn on both of the debug switches. Post the new logs and your raw yaml for the addon configuration.

N3rdP1um23 commented 1 year ago

Debug

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Starting RTLAMR with parameters:
AMR Message Type = all
AMR Device IDs =
Time Between Readings = 30
Duration =  15
Electric Unit of measurement =  kWh
Gas Unit of measurement =  ft³
Water Unit of measurement =  l
Water measurements provided in tenths =  false
SCM PLUS GAS DIVISOR =  1
Debug is  true
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001
Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!
Tuned to 100000000 Hz.
listening...
Allocating 15 zero-copy buffers
11:29:21.288749 decode.go:45: CenterFreq: 912380000
11:29:21.289216 decode.go:46: SampleRate: 2359296
11:29:21.289236 decode.go:47: DataRate: 32768
11:29:21.289249 decode.go:48: ChipLength: 72
11:29:21.289261 decode.go:49: PreambleSymbols: 32
11:29:21.289274 decode.go:50: PreambleLength: 4608
11:29:21.289286 decode.go:51: PacketSymbols: 736
11:29:21.289298 decode.go:52: PacketLength: 105984
11:29:21.289317 decode.go:59: Protocols: scm,scm+,idm,r900
11:29:21.289341 decode.go:60: Preambles: 111110010101001100000,0001011010100011,01010101010101010001011010100011,00000000000000001110010101100100
11:29:21.289363 main.go:124: GainCount: 29
11:29:26.294546 main.go:343: Receiver context cancelled.
11:29:26.295210 main.go:320: read tcp 127.0.0.1:50540->127.0.0.1:1234: i/o timeout
io.ReadFull
main.(*Receiver).Run.func2
    /go/pkg/mod/github.com/bemasher/rtlamr@v0.9.3/main.go:181
runtime.goexit
    /usr/lib/go/src/runtime/asm_amd64.s:1571
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped
Signal caught, exiting!
Signal caught, exiting!

YAML

debug: true
rtltcpdebug: true
msgType: all
ids: 
duration: 15
pause_time: 30
gas_unit_of_measurement: ft³
electric_unit_of_measurement: kWh
water_unit_of_measurement: l
water_use_tenths: false
scm_plus_gas_divisor: 1

Side note

I'm not sure if it makes a difference, though I'm using a NooElec NESDR Nano 2+. I was reading this https://github.com/jdeath/RTLAMR2MQQT/issues/10#issuecomment-964277534 saying that it's probably better to use another dongle? If so, I could switch it out to something better. Though when I tested it on my laptop, it worked without issue so it may be some config issue I have or something.

pasyn commented 1 year ago

I don't think it is a hardware issue since it worked on your laptop. I'm trying to reproduce the issue on my HA server.

N3rdP1um23 commented 1 year ago

Oh awesome, thanks! Let me know if I can help in anyway 🙂

pasyn commented 1 year ago

No luck on my end with reproducing the issue. Can you attempt to run RTLAMR in the terminal addon in the same way you got it working on your laptop? Also, check the output of dmesg | grep usb for any related errors on the kernel level.

pasyn commented 1 year ago

Just managed to reproduce the issue after a full reboot

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Starting RTLAMR with parameters:
AMR Message Type = all
AMR Device IDs = 23876447,1540559732
Time Between Readings = 30
Duration =  120
Electric Unit of measurement =  kWh
Gas Unit of measurement =  ft³
Water Unit of measurement =  gal
Gas Multiplier =  1
Electric Multiplier =  1
Water Multiplier =  0.1
Debug is  true
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001
Using device 0: Generic RTL2832U OEM
Detached kernel driver
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!
Tuned to 100000000 Hz.
rtlsdr_read_reg failed with -1
rtlsdr_write_reg failed with -1
rtlsdr_read_reg failed with -1
rtlsdr_write_reg failed with -1
rtlsdr_write_reg failed with -1
rtlsdr_write_reg failed with -1
Allocating 15 zero-copy buffers
Failed to allocate zero-copy buffer for transfer 0
Falling back to buffers in userspace
Failed to submit transfer 0
Please increase your allowed usbfs buffer size with the following command:
echo 0 > /sys/module/usbcore/parameters/usbfs_memory_mb
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
r82xx_write: i2c wr failed=-4 reg=17 len=1
r82xx_set_freq: failed=-4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
r82xx_write: i2c wr failed=-4 reg=0a len=1
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
r82xx_write: i2c wr failed=-4 reg=05 len=1
rtlsdr_demod_write_reg failed with -4
rtlsdr_demod_read_reg failed with -4
01:00:24.648013 decode.go:45: CenterFreq: 912380000
01:00:24.652145 decode.go:46: SampleRate: 2359296
01:00:24.652657 decode.go:47: DataRate: 32768
01:00:24.652837 decode.go:48: ChipLength: 72
01:00:24.653341 decode.go:49: PreambleSymbols: 32
01:00:24.653531 decode.go:50: PreambleLength: 4608
01:00:24.653854 decode.go:51: PacketSymbols: 736
01:00:24.654058 decode.go:52: PacketLength: 105984
01:00:24.654378 decode.go:59: Protocols: scm,scm+,idm,r900
01:00:24.654875 decode.go:60: Preambles: 111110010101001100000,0001011010100011,01010101010101010001011010100011,00000000000000001110010101100100
01:00:24.655340 main.go:124: GainCount: 29
01:00:29.659323 main.go:343: Receiver context cancelled.
01:00:29.659902 main.go:320: read tcp 127.0.0.1:53216->127.0.0.1:1234: i/o timeout
io.ReadFull
main.(*Receiver).Run.func2
    /go/pkg/mod/github.com/bemasher/rtlamr@v0.9.3/main.go:181
runtime.goexit
    /usr/lib/go/src/runtime/asm_arm64.s:1270
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped
Signal caught, exiting!
Signal caught, exiting!
pasyn commented 1 year ago

There seems to not be enough space in the USBFS buffer. The default buffer size is only 16mb. Try adding usbcore.usbfs_memory_mb=1000 to your cmdline options in /boot/cmdline.txt.

pasyn commented 1 year ago

@N3rdP1um23, were you able to resolve this issue?

N3rdP1um23 commented 1 year ago

@pasyn My apologies for the delay. I've just updated the plugin and it didn't initially work out of the gate. The /boot/cmdline.txt you mentioned, would I have to add this in Home Assistant OS? It doesn't currently exist. Just wanted to make sure before messing something else up haha.

I was able to play around with it a little more, and found that the following plugin works without issue https://github.com/allangood/rtlamr2mqtt

N3rdP1um23 commented 1 year ago

Actually, stopping the rtlamr2mqtt addon and restarting the this one seems to have done the trick! I am able to see an individual sensor now which is awesome!

I do have a few questions however

pasyn commented 1 year ago

The /boot/cmdline.txt you mentioned, would I have to add this in Home Assistant OS?

cmdline.txt is found in the boot partition if you are running HA on a raspberry pi. To access this file, you will have to chuck the sdcard into a computer.

I wasn't able to set a non-whole number for the multiplier as the input only steps by "1", uncommenting that in the field and then saving it worked. (not 100% sure if that's something that you have control over)

I'm looking into a fix for this one. As far as I know, it is only an issue on the first run/install. You can override the value to a decimal by editing the YAML.

The entities that it exposes don't have a unique ID so I'm unable to modify the name, icon, etc.. from the GUI. Is this something that's by design or could be added? Would be a little nicer as compared to sensor.ID

I agree but this is a limitation of Addons in homeassistant and the HA core dev team has made it clear that this will not change. See: https://github.com/cpyarger/Home-Assistant-Addons/issues/10#issuecomment-1139100629 A semi-fix is to add a sensor template to your config.yaml in HA.

I have the duration and pause set to the defaults (15 and 30 respectfully), though it doesn't seem to be updating the values of the sensor. Even after a restart and full stop/start of the addon. Any idea if I might have messed up the configuration or something like that?

Personally, I have the duration set to 120 and the pause left at the default value. Check the logs with the debug switch on. You should see something similar to the following when your meter signal is picked up.

RTLAMR JSON Output
{"Time":"2023-02-05T22:18:11.769490954-05:00","Offset":0,"Length":0,"Type":"SCM","Message":{"ID":23876447,"Type":4,"TamperPhy":0,"TamperEnc":2,"Consumption":45624,"ChecksumVal":21337}}
JSON Output to HA REST API
{"state":"45624","attributes":{"unique_id":"23876447-sdrmr","device_class":"energy","unit_of_measurement":"kWh","state_class":"total_increasing"}}
200