james-fry / hassio-addons

Repository for hass.io add ons
99 stars 96 forks source link

`frequency` , `gain`, `frequency_offset` not detailed in readme - how to calculate? #26

Open charlietomo opened 5 years ago

charlietomo commented 5 years ago

This looks a great add-on and is my first foray into SDR, so I may be missing something basic. I bought an SDR specifically to use with currentcost. When I follow the setup instructions it asks for protocol": 44 - I have set this to 44 as indicated for current cost.

The following are not mentioned in the readme: frequency , gain, frequency_offset and I am not sure what is required here.

I suspect I need to use the SDR device on another computer in order to scan and then find some details? I tried SSH into the docker container running on hassos, and ran rtl_433 -G but it looks like it can't get access to the SDR because it is already in use.

Any instruction appreciated.

james-fry commented 5 years ago

Hi @charlietomo

These additional parameters were added by a contributor, and I confess I didnt get the time to update the readme. These are the settings I am using for current cost:

"protocol": 44, "frequency": 433920000, "gain": 60, "frequency_offset": 0

Also I made a little hard coded addition to the rtl2mqtt script to auto discover the sensor in HA. I added this to the repo. If you want to try it then copy it and rename to rtl2mqtt.sh

charlietomo commented 5 years ago

Thanks @james-fry I have tried using your settings and am still no further. I have attached my log below; does it look correct? Any help appreciated. It seems to detect a USB device and my MQTT server logs a connection from this user - but no data is sent.

Starting RTL_433 with parameters:
MQTT Host = 192.168.1.20
MQTT User = [snip]
MQTT Password = [snip]
MQTT Topic = homeassistant/sensor/currentcost
RTL_433 Protocol = 44
RTL_433 Frequency = 433920000
RTL_433 Gain = 60
RTL_433 Frequency Offset = 0
rtl_433 version 18.12-210-g7ab2894 branch master at 201905261917 inputs file rtl_tcp RTL-SDR
Trying conf file at "rtl_433.conf"...
Trying conf file at "/root/.config/rtl_433/rtl_433.conf"...
Trying conf file at "/usr/local/etc/rtl_433/rtl_433.conf"...
Trying conf file at "/etc/rtl_433/rtl_433.conf"...
    Consider using "-M newmodel" to transition to new model keys. This will become the default someday.
    A table of changes and discussion is at https://github.com/merbanan/rtl_433/pull/986.
Registered 1 out of 126 device decoding protocols [ 44 ]
Detached kernel driver
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
[R82XX] PLL not locked!
Sample rate set to 250000 S/s.
Tuner gain set to 60.000000 dB.
Tuned to 433.920MHz.
Allocating 15 zero-copy buffers
Detected Kernel usbfs mmap() bug, falling back to buffers in userspace

As an aside what kind of aerial are you using in order to receive CurrentCost data?

james-fry commented 5 years ago

@charlietomo this is a full log from my addon:

Starting RTL_433 with parameters:
MQTT Host = hassio.local
MQTT User = xxxx
MQTT Password = yyyy
MQTT Topic = rtl4332mqtt
RTL_433 Protocol = 44
RTL_433 Frequency = 433920000
RTL_433 Gain = 60
RTL_433 Frequency Offset = 0
MQTT Autodiscovery:
{"unit_of_measurement":"W","device_class":"power","icon":"mdi:gauge","value_template":"{{ value_json.power0 }}","state_topic":"rtl4332mqtt/CurrentCost_TX_3575","json_attributes_topic":"tl4332mqtt/CurrentCost_TX_3575","name":"Current Cost Tx","unique_id":"3575_CurrentCost TX_rtl4332mqtt","device":{"identifiers":"Current Cost Tx_3575","name":"Current Cost Tx","sw_version":"N/A","model":"Current Cost EnviR Tx","manufacturer":"Current Cost"}}
rtl_433 version 18.12-208-g17b8e86 branch master at 201905170853 inputs file rtl_tcp RTL-SDR
Trying conf file at "rtl_433.conf"...
Trying conf file at "/root/.config/rtl_433/rtl_433.conf"...
Trying conf file at "/usr/local/etc/rtl_433/rtl_433.conf"...
Trying conf file at "/etc/rtl_433/rtl_433.conf"...

    Consider using "-M newmodel" to transition to new model keys. This will become the default someday.
    A table of changes and discussion is at https://github.com/merbanan/rtl_433/pull/986.

Registered 1 out of 125 device decoding protocols [ 44 ]
Detached kernel driver
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
[R82XX] PLL not locked!
Sample rate set to 250000 S/s.
Tuner gain set to 60.000000 dB.
Tuned to 433.920MHz.
Allocating 15 zero-copy buffers

Seems that something is causing that error/warning on the final line in your log:

Detected Kernel usbfs mmap() bug, falling back to buffers in userspace

Try un-commenting the line in the script:

set -x ## uncomment for MQTT logging...

for more logging...

When I googled the error it seems its coming from the RTL SDR code rather than rtl_433: https://github.com/osmocom/rtl-sdr/blob/master/src/librtlsdr.c (row 1758) I have no idea what this is though, and IIRC I didnt see it before.

Regarding aerial, I use the crappy magnetic one that came with my DVB dongle. Looks like this: image

charlietomo commented 5 years ago

@james-fry thanks for the tip re uncommenting

set -x ## uncomment for MQTT logging...

I did that and saw that actually the MQTT topic it was posting to was homeassistant/sensor/currentcost/CurrentCost_TX/null despite the config setting being homeassistant/sensor/currentcost.

When I subscribe to homeassistant/sensor/currentcost/CurrentCost_TX/null I see it has found my Currentcost and is getting some data! So that is progress. This is a snippet of the log.

+ DEVICE=CurrentCost_TX
+ jq --raw-output .id
+ tr -s ' ' _
+ echo '{"time"' : '"2019-06-10' '19:16:07",' '"model"' : '"CurrentCost' 'TX",' '"dev_id"' : 1560, '"power0"' : 5642, '"power1"' : 0, '"power2"' : '0}'
+ DEVICEID=null
+ MQTT_PATH=homeassistant/sensor/currentcost
+ '[' 14 ]
+ MQTT_PATH=homeassistant/sensor/currentcost/CurrentCost_TX
+ '[' 4 ]
+ MQTT_PATH=homeassistant/sensor/currentcost/CurrentCost_TX/null
+ '[' -w /tmp/rtl_433.log ]
+ echo '{"time"' : '"2019-06-10' '19:16:07",' '"model"' : '"CurrentCost' 'TX",' '"dev_id"' : 1560, '"power0"' : 5642, '"power1"' : 0, '"power2"' : '0}'
+ /usr/bin/mosquitto_pub -h 192.168.1.20 -u [user] -P [pass] -i RTL_433 -r -l -t homeassistant/sensor/currentcost/CurrentCost_TX/null
+ read line
+ echo '{"time"' : '"2019-06-10' '19:16:10",' '"model"' : '"CurrentCost' 'TX",' '"dev_id"' : 1723, '"power0"' : 0, '"power1"' : 0, '"power2"' : '0}'
+ jq --raw-output .model+ 
tr -s ' ' _

I have one house meter (the clamp connected to the main box) and three IAM plug sockets that give me individual power readings of the relevant socket. The only power reading I am getting is from power0 and it seems to jump between each of my 4 readings (and sometimes zero) - with the dev_id unique for each device.

Thanks again for the help it has got me significant progress.

Edit: tweaked in related to understanding dev_id

james-fry commented 5 years ago

There is another issue thread regarding supporting multiple devices: https://github.com/james-fry/hassio-addons/issues/9

I only have the one currentcost device (clamp). IIRC that transmitter has three inputs, so I assume I would also see power1 and power2 if I was using three clamps (for three phase supply?)

Regarding debugging, one way is to create a script that does nothing (e.g. sleep loop) and then connect to the container (e.g. via command line, or via portainer addon). you can then launch rtl_433 manually

charlietomo commented 5 years ago

Thanks - I will investigate that other thread in more detail. I'm no programmer so that sleep loop is beyond me! Do you know why the MQTT path is different to the specified one - is this intended behaviour?

+ DEVICEID=null
+ MQTT_PATH=homeassistant/sensor/currentcost
+ '[' 14 ]
+ MQTT_PATH=homeassistant/sensor/currentcost/CurrentCost_TX
+ '[' 4 ]
+ MQTT_PATH=homeassistant/sensor/currentcost/CurrentCost_TX/null
james-fry commented 5 years ago

homeassistant/# topics are used for MQTT discovery in ARM The autodiscovery payload JSON gives the state topic for sensor readings:

{  
   "unit_of_measurement":"W",
   "device_class":"power",
   "icon":"mdi:gauge",
   "value_template":"{{ value_json.power0 }}",
   "state_topic":"rtl4332mqtt/CurrentCost_TX_3575",                   <================
   "json_attributes_topic":"tl4332mqtt/CurrentCost_TX_3575",
   "name":"Current Cost Tx",
   "unique_id":"3575_CurrentCost TX_rtl4332mqtt",
   "device":{  
      "identifiers":"Current Cost Tx_3575",
      "name":"Current Cost Tx",
      "sw_version":"N/A",
      "model":"Current Cost EnviR Tx",
      "manufacturer":"Current Cost"
   }
}
clsferguson commented 4 years ago

to find out frequency offset google kalibrate rtl-sdr

MomosX commented 4 years ago

Hi, someone please help me to get this sorted out. Clearly i am doing something wrong.... I am trying to get some data out of a WH1080 weather station 868 MHz.

I start the addon and the full log is

` [s6-init] making user provided files available at /var/run/s6/etc...exited 0. [s6-init] ensuring user provided files have correct perms...exited 0. [fix-attrs.d] applying ownership & permissions fixes... [fix-attrs.d] done. [cont-init.d] executing container initialization scripts... [cont-init.d] done. [services.d] starting services [services.d] done. Starting RTL_433 with parameters: MQTT Host = 192.168.1.225 MQTT User = weatherstation MQTT Password = weatherstation MQTT Topic = homeassistant/sensor/currentcost RTL_433 Protocol = 32 RTL_433 Frequency = 868000000 RTL_433 Gain = 0

The Mosquitto broker addon config is" ` logins:

And in config.yaml i added: mqtt: broker: 192.168.1.225 username: weatherstation password: weatherstation discovery: true

I then go to integrations, set the MQTT integration and wait... and wait... but it does not get populated with anything :(

Please tell me what am i doing wrong. thank you !

PS: i can not seem to get the formatting right also :(