seanauff / metermon

Dockerized rtlamr wrapper that outputs formatted JSON messages over mqtt
MIT License
66 stars 12 forks source link

MQTT - Syntax error #1

Closed seaverd closed 5 years ago

seaverd commented 5 years ago

I just tried installing your docker for metermon and I get the following error in the logs:

File "./metermon.py", line 24
print(f"Connected to broker at {MQTT_BROKER_HOST}:{MQTT_BROKER_PORT} with result code {rc}: "+mqtt.connack_string(rc))
^
SyntaxError: invalid syntax

I get this result when using the default settings as well as when I try and run the docker with the extra parameters specified for my own system as I do not use the default values on my server. Any suggestions?

seanauff commented 5 years ago

I think this is due to the golang base image I am using has python 2.7 which does not support "f-strings". I'll update it to use python 3.

seanauff commented 5 years ago

The image now uses python3 and I confirmed it is working on my system. Thanks for helping out and please open another issue if you find something else!

seaverd commented 5 years ago

Perfect. Looks like metermon is working as log says it has connected to MQTT. I get a quick MQTT online message and then it goes to offline as I am having issues with the rtl_tcp docker you recommended. Any suggestions? Log for the rtl_tcp docker is empty.

Dan

On Mon, Aug 26, 2019, 9:39 PM seanauff notifications@github.com wrote:

The image now uses python3 and I confirmed it is working on my system. Thanks for helping out and please open another issue if you find something else!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/seanauff/metermon/issues/1?email_source=notifications&email_token=AAU53BPO23YUWQXC22E5HMDQGSAUJA5CNFSM4IOXX4VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5GF7AY#issuecomment-525098883, or mute the thread https://github.com/notifications/unsubscribe-auth/AAU53BNFYNDBTQWNNBAAMSTQGSAUJANCNFSM4IOXX4VA .

seanauff commented 5 years ago

What does your docker run command for rtl_tcp look like? Mine looks something like this: docker run -d --name=rtl_tcp --device /dev/bus/usb/:/dev/bus/usb rtl_tcp -a 0.0.0.0

Also, I've experienced the MQTT connect and immediate disconnect issue when using a duplicate client ID.

seaverd commented 5 years ago

Sorry to take so long to reply. I walked away from this for awhile and came back to it last night.

I have everything working and can see Mqtt messages for my electric and water meters. My gas meter is the style that only reports when woken up by the meter reader....so I'll have to wait and see what happens with that.

Based on the data I got overnight...is it safe to assume you have rtlamr set to only send an mqtt message when the consumption is different.

I am going to process and bring the readings into home assistant.... probably via nodered as I have to process the json to separate electric and gas readings. Have you ever considered having the mqtt ouput topic include the unique ID of the meter. For example: metermon/UNIQUE_METER_ID

Seems like this would make it easier to process.

Thanks!

Dan

On Wed, Aug 28, 2019, 11:47 AM seanauff notifications@github.com wrote:

What does your docker run command for rtl_tcp look like? Mine looks something like this: docker run -d --name=rtl_tcp --device /dev/bus/usb/:/dev/bus/usb rtl_tcp -a 0.0.0.0

Also, I've experienced the MQTT connect and immediate disconnect issue when using a duplicate client ID.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/seanauff/metermon/issues/1?email_source=notifications&email_token=AAU53BPNT6UYJJK4QRKNEYDQG2MZXA5CNFSM4IOXX4VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5LSNSY#issuecomment-525805259, or mute the thread https://github.com/notifications/unsubscribe-auth/AAU53BKAZPJ35B7DZIRKYXLQG2MZXANCNFSM4IOXX4VA .

seanauff commented 5 years ago

Great! And yes, the rtlamr option -unique=true is set.

I can also see how having the unique ID in the MQTT topic would make it easier to pull into home assistant. When I was still using this with home assistant, I had some code in the script to pick out my meter IDs and send them on their own unique topic; now I just pipe everything directly to my influx database via telegraf and bypass home assistant.

I can work on adding that as an option though.

seanauff commented 5 years ago

I added that ability, but have not tested it. Can you see if it works for you?

seaverd commented 5 years ago

Thank you for adding that feature! Did a quick update and got a new mqtt topic with the ID for my water meter. My electric readings come in sporadically...due to antenna location. I ordered a USB extension cable and plan on relocating my antenna when this arrives tomorrow.

So I now have a senor in home assistant and I can get the consumption. However, if I restart home assistant I get unknown for the consumption readings until a new one is transmitted via mqtt. I am assuming this is because it is not being published with the retain set to true???? In looking at metermon.py file I see that the status is being published with retain set to true....but not of the rtlamr mqtt outputs have qos or retain set. Would adding this impact your use case? I have not used telegraf yet...will need to read up on it.

Thanks again! Dan

On Thu, Oct 10, 2019, 11:50 AM seanauff notifications@github.com wrote:

I added that ability, but have not tested it. Can you see if it works for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/seanauff/metermon/issues/1?email_source=notifications&email_token=AAU53BNARMNZTMTZSHSMDWLQN5FOBA5CNFSM4IOXX4VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA425YA#issuecomment-540651232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU53BI2FDKTI63FHIU6DSDQN5FOBANCNFSM4IOXX4VA .

seanauff commented 5 years ago

Somehow I missed the notification for you latest message so I apologize for taking so long! Glad to hear that the ID topic feature is working well for you.

I added another environment variable to set the rtlamr unique flag. Before it was always true, now it can be set to false if you want so that a fresh message will come in and update the homeassistant value after a restart, although it could still take a few minutes depending on the reporting frequency of your meter and the sensitivity of your receiver. Let me know how it works for you!