birdie1 / victron

Victron bluetooth and serial communication at a python script. With MQTT and HomeAssistant support.
GNU General Public License v3.0
125 stars 16 forks source link

JSON output and single query? #12

Open ctschach opened 2 years ago

ctschach commented 2 years ago

Thanks for the brilliant work on this project. Pretty amazing what you have created so far.

I totally understand your approach of getting data in the MQTT. However, I would love to use it for single queries. So instead of running a delay and then query the device again, I would like to just quit the script. In addition I would love you you could do a JSON encoded output to stdout.

I'm not that familiar with Python, so not sure if I would be able to change the code accordingly (and pretty).

But is this anything which we could add to the project? Or would this be against the overall concept?

birdie1 commented 2 years ago

Thanks! I already thought about something like that and started some time ago to introduce the "direct disconnect method". I can improve it to quit after getting the data once. At least for serial and bluetooth-ble connection method. The bluetooth connection method get its data via async functions and not always all data, but I could add an config parameter to define for which data should be waited.

The output via JSON shouldn't be to complicated.

Hopefully I find the time next weekend for some programming...

birdie1 commented 2 years ago

Sorry for the delay. I have added json as output option in configfile. For serial and bluetooth-ble there is a --direct-disconnect option to run only once. I will try to add a similar option for bluetooth connection method soon. You may want to add an collection to your configfile and run the program with -c, otherwise it will print the first single value as a single json output and then exit if you use --direct-disconnect. With a collection you can "merge" it into one output with all values.

If it is not clear from my comments in the configfile, I can provide you with a sample config, if you tell me which device and connection method you are using,

Is the output what you expected?