Get your smart electric, water and gas meter scm readings into home assistant with a RTL-SDR

it looks like AMR data is coming over 900mhz range while my weather stuff is 433mhz, only solution I can think of is another SDR . My weather stuff is running in docker and i notice when I run rtl_tcp and rtlamr in two different terminals I get out put that look like this

{Time:2019-01-24T09:27:27.759 SCM:{ID:34528191 Type:12 Tamper:{Phy:00 Enc:00} Consumption: 417372 CRC:0x34C0}}
{Time:2019-01-24T09:27:30.535 SCM:{ID:38392240 Type:12 Tamper:{Phy:02 Enc:00} Consumption: 406242 CRC:0x576E}}

with a lot more ID , so I am guessing I am picking up the neighbors as well and have to figure out my id. From the type it looks to be gas, but I have not looked at the meters to figure it out.

I think the best solution for both 433mh weather and 900mhz amr is two SDR antena , if I can dockerize this it will work great. I hope to find time to play with it over the weekend.

BTW this is great find, new ideas to tinker with.

1 Like

I was not sure if two programs could control the SDR at the same time for different frequencies. I did not try it, but I was debating getting a weather station if it can read both frequencies at once. Logically, doesn’t the SDR receive a big range of frequency and the software decides what to do with it? If the dongle can communicate to both programs at the same time, it could work.

You did find gas meter data (Type:12). Your meter ID should be written on your meter or maybe on your bill (Account number?).

I have not been out to look at the meter. I actually tried the arm software from remotely and it works but I had to shut down the rtl 433 docker container that I built first,

I can look at the amr 2 mqtt software ymaybe incorporate it with my rtl433 to mqtt code that is in python and see if I can make them alternate polling.

It might be easier just to get another sdr

I tried this awhile ago and at least in my area (California), the meters are encrypted so the data can’t be read. Be sure to check the rtlamr site to see if the meter is supported before you buy a radio.

That’s too bad that you could not read it…

I placed a link to show the supported meters in the start of the instructions. I now updated it so that it’s in bold.

Great tutorial. I am working though it. I am able to read my water and gas meter wby using rtlamr, but the problem I am having is registering the service on my raspberry pi. Every time I try to start the service, I get the error:

amridm2mqtt.service: Failed at step EXEC spawning /opt/amridm2mqtt/amrscm2mqtt: Permission denied

Any idea what this would be caused by?

Thanks

I am guessing that the readings you are getting are from rtlamr and not amrscm2mqtt script. You can make sure that the amrscm2mqtt script is running fine by running it in one terminal with the rtl-tcp running in another terminal (started first) and a third terminal with mosquitto (or other broker) where you would receive the mqtt data.

When you modified the service file,it should not be blank. I just noticed that in my tutorial, I had not put the correct link there (I will fix it). It should be:

sudo nano /opt/amridm2mqtt/amridm2mqtt.systemd.service instead of sudo nano systemd.service

There you should see the line ExecStart=/opt/amridm2mqtt/amridm2mqtt and modify it to :

ExecStart=/opt/amridm2mqtt/amrscm2mqtt

If it still doesn’t work and the original service file works (the one that points to the amridm2mqtt), you could always replace the contents of this file. with the contents of the amrscm2mqtt file

Finally, after doing a quick search for Failed at step EXEC spawning - Permission denied, I am not sure if this could help, but you might simply need to change the permissions of the file by doing sudo chmod +x /opt/amridm2mqtt/amrscm2mqtt

Hope this helps!

1 Like

just curious are you in the states? I am very interested in doing this with my home-assistant, are the readings identical? does this work with therms?

damn, this sucks so I assume you weren’t able to get it to work, do you have pge?

I am using lovelace UI. The readings are good and match my utilities. I can see in my power readings when the dryer is on or when a baseboard heater has turned on with a graph that shows a few days using the current average power. With a recent update of Home Assistant, they created a new utility meter component that might help someone with calculating daily power, monthly power and costs instead of using my configurations.

If you are interested in doing this project, just make sure that your meters are compatible…

I had SCE and then Glendale W&P- both were encrypted. Take a pic of your meter and compare it withe the rtamr repo page - there is a list of supported meters there.

Can confirm here in SoCal for electrical I’m also on SCE with a Zigbee-based smart meter.

Thanks @biochemguy, I will try this out in the next day when I have some time. I did some more research tonight as well and I think I might have the solution.

My water and gas meter is compatible with the rtlamr library, its amazing how many neighbours I pick up doing a 10 minute monitor. Unfortunately my power meter is also zigbee encrypted, however there is a device made by Rainforest automation that is compatible with my meter. There are some other posts about integrating it.

1 Like

if someone is interested, here is my dashboard using those components. I also added calculations that use the cost for the last 30 days of utility use. This uses the scrape sensor from home assistant to get the current rates for my utilities, as the gas will fluctuate. It’s not perfect, but it’s good enough for me…

Oh and yes, it was a cold month, lol!

3 Likes

can you measure in therms?

according to PGE’s website, the data isn’t encrypted until it his the network nodes (their wireless access points), going to try it out anyways, it’ll only be a loss of $35 if I can’t get it to work

Does it measure gas or just electric?

so I got it working. I had to change a few things:

The code for “amrscm2mqtt” had a few syntax errors, please see below the corrected code. I also renamed it to “amrscm2mqtt.py”

#!/usr/bin/env python3
'''
Runs rtlamr to watch for IDM broadcasts from power meter. If meter id
is in the list, usage is sent to 'readings/{meter id}/meter_reading'
topic on the MQTT broker specified in settings.

WATCHED_METERS = A Python list indicating those meter IDs to record and post.
MQTT_HOST = String containing the MQTT server address.
MQTT_PORT = An int containing the port the MQTT server is active on.

'''
import subprocess
import signal
import sys
import time
import paho.mqtt.publish as publish
import settings

# uses signal to shutdown and hard kill opened processes and self
def shutdown(signum, frame):
    subprocess.call('/usr/bin/pkill -9 rtlamr', shell=True)
    subprocess.call('/usr/bin/pkill -9 rtl_tcp', shell=True)
    subprocess.call('/usr/bin/pkill -9 amridm2mqtt', shell=True)
    sys.exit(0)

signal.signal(signal.SIGTERM, shutdown)
signal.signal(signal.SIGINT, shutdown)

auth = None

if len(settings.MQTT_USER) and len(settings.MQTT_PASSWORD):
        auth = {'username':settings.MQTT_USER, 'password':settings.MQTT_PASSWORD}

def send_mqtt(topic, payload,):
    try:
        publish.single(topic, payload=payload, qos=1, hostname=settings.MQTT_HOST, port=settings.MQTT_PORT, auth=auth)
    except Exception as ex:
        print("MQTT Publish Failed: " + str(ex))

time.sleep(30)

# start the rtl_tcp program
rtltcp = subprocess.Popen([settings.RTL_TCP + " > /dev/null 2>&1 &"], shell=True,
    stdin=None, stdout=None, stderr=None, close_fds=True)

time.sleep(5)

# start the rtlamr program.
rtlamr = subprocess.Popen([settings.RTLAMR,
    '-msgtype=scm',
    '-format=csv'], stdout=subprocess.PIPE)

while True:

    try:
        # rtlamr's readline returns byte list, remove whitespace and convert to string
        amrline = rtlamr.stdout.readline().strip().decode()
        # split string on commas
        flds = amrline.split(',')

        if len(flds) != 9:

            # proper SCM results have 9 fields
            continue

        # make sure the meter id is one we want
        meter_id = int(flds[3])
        if len(settings.WATCHED_METERS) and meter_id not in settings.WATCHED_METERS:
            continue

        # get some required info: current meter reading, current interval id, most recent interval $
        read_cur = int(flds[7])

        current_reading_in_kwh = (read_cur * settings.WH_MULTIPLIER) / 1000

        send_mqtt(
            'readings/' + str(meter_id) + '/meter_reading',
            '%s' % (current_reading_in_kwh)
        )

    except:
        time.sleep(2)

Next, I made some changes to the “amridm2mqtt.service” file. For some reason, my system did not like the “User=root” designation, so I deleted it. Also, I needed to explicitly call python3.

[Unit]
Description=AMR IDM to MQTT
After=network.target

[Service]
ExecStart=/usr/bin/python3 /opt/amridm2mqtt/amrscm2mqtt.py
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=amridm2mqtt

[Install]
WantedBy=multi-user.target

The service now auto starts and pushes MQTT messages to my broker.

I am by no means a python programmer; my strengths are in industrial automation. Therefore I have no idea if what I did was good or not… but it seems to work, so I will let it run for the next few days and see how it goes.

Thanks @biochemguy for the help

2 Likes

The data sent by the meter will be in it’s specific format. If your meter reads in therms, then it should theoretically send therms data to mqtt. You can always convert it in home assistant afterwards. As for gas / electric / water, it depends on your meter. You can see if your meter is supported in this list

Hi @david1, The Rainforest automation bridge is only for the power meters. My utility provider (EPCOR) will apparently pair the device to my power meter. I read someplace that PG&E can also use the Rainforest Automation device as well, but I cant remember for sure. I have not pulled the trigger yet because the bridge was reviewed quite poorly by a number of people; they cited security issues and constant rebooting. I am waiting until some better firmware is released