Last active
July 8, 2024 17:48
-
-
Save debsahu/ee33914e8dea896ff3956f02970e38b9 to your computer and use it in GitHub Desktop.
RTLAMR: RTL-SDR to read electric/gas/water meters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shell_command: | |
rtlamr_start: 'python3.6 /home/pi/work/rtlamrmqtt.py' | |
kill_rtlamr: 'pkill -f rtlamr' | |
automation: | |
- action: | |
- data: {} | |
service: shell_command.rtlamr_start | |
alias: Start RTLAMR Script | |
condition: [] | |
id: '4367493654362' | |
trigger: | |
- event: start | |
platform: homeassistant | |
- action: | |
- data: | |
payload_template: '{{ states(''sensor.gas_meter'') }}' | |
retain: 'true' | |
topic: home/gas_prior_day | |
service: mqtt.publish | |
alias: Post Day's Gas Reading for cumulative calculation | |
condition: [] | |
id: '54745735557534' | |
trigger: | |
- at: 00:00:01 | |
platform: time | |
- action: | |
- data: | |
payload_template: '{{0}}' | |
retain: 'true' | |
topic: home/gas_month_usage | |
service: mqtt.publish | |
alias: Current Month Gas Reading Zeroing | |
condition: | |
- before: '23:59:55' | |
condition: time | |
id: '25752745752725475' | |
trigger: | |
- platform: template | |
value_template: '{{ now().strftime("%d") == "01" }}' | |
- action: | |
- data: | |
payload_template: '{{ states(''sensor.gas_month_usage'') | float + states(''sensor.gas'') | float }}' | |
retain: 'true' | |
topic: home/gas_month_usage | |
service: mqtt.publish | |
alias: Cumulative Monthly Gas Usage | |
condition: [] | |
id: '546725745752752' | |
trigger: | |
- at: '23:59:59' | |
platform: time | |
sensor: | |
- platform: mqtt | |
state_topic: "home/gasmeter" | |
name: "Gas Meter" | |
qos: 0 | |
unit_of_measurement: "gal" | |
value_template: "{{ value | round(1) }}" | |
- platform: mqtt | |
state_topic: "home/gas_prior_day" | |
name: "Gas Prior Day" | |
qos: 0 | |
unit_of_measurement: "gal" | |
value_template: "{{ value | round(1) }}" | |
- platform: mqtt | |
state_topic: "home/gas_month_usage" | |
name: "Gas Month Usage" | |
qos: 0 | |
unit_of_measurement: "gal" | |
value_template: "{{ value | round(1) }}" | |
- platform: template | |
sensors: | |
gas: | |
value_template: '{%- if not (is_state("sensor.gas_meter","unknown") or is_state("sensor.gas_prior_day","unknown") )-%} {{ ((states.sensor.gas_meter.state | float) - (states.sensor.gas_prior_day.state | float)) | max (0) | round(1) }} {%- endif -%}' ## ensure calc is no lower than zero! | |
friendly_name: "Gas Today" | |
unit_of_measurement: "gal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import paho.mqtt.client as mqtt | |
import time | |
import json | |
client = mqtt.Client() | |
client.connect("localhost", 1883, 60) | |
client.loop_start() | |
try: | |
while True: | |
completed = subprocess.run(['/home/pi/go/bin/rtlamr','-filterid=xxxxxxxxx', '-single=true', '-format=json', '-duration=10m'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) | |
try: | |
data=json.loads(completed.stdout.decode("utf-8")) | |
except ValueError: | |
print("Error") | |
else: | |
reading = data['Message']['Consumption'] | |
client.publish("home/gasmeter",reading,0,True); | |
print("Reading:",reading) | |
except KeyboardInterrupt: | |
print("interrupted!") | |
client.loop_stop() | |
client.disconnect() |
Please tell me the exact steps to do this project. I did everything in your Youtube video. Plus some AI help when I need help. I still can't get it to work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Lenny43 Maybe get in touch with @airspy as that is his/her/their code. I have an add on to make everyone’s life simpler: https://github.com/debsahu/hassio-rtlamr-addon