Skip to content

Instantly share code, notes, and snippets.

@debsahu

debsahu/HA_RTLAMR.yaml

Last active Oct 13, 2020
Embed
What would you like to do?
RTLAMR: RTL-SDR to read electric/gas/water meters
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"
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()
@gbdavidx

This comment has been minimized.

Copy link

@gbdavidx gbdavidx commented Mar 8, 2019

Traceback (most recent call last):
File "water.py", line 12, in
completed = subprocess.run(['$HOME/projects/bin/rtlamr -server=127.0.0.1','-filterid=1481976504', '-single=true', '-format=json', '-duration=10m'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
AttributeError: 'module' object has no attribute 'run'

@debsahu

This comment has been minimized.

Copy link
Owner Author

@debsahu debsahu commented Mar 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.