HBDK / ElOverBlik-helper

Home assistant addon
MIT License
3 stars 1 forks source link

Multiple metering points #11

Closed gllmlbrt closed 3 years ago

gllmlbrt commented 3 years ago

Hi, nice little helper. I runs fine for one of the two metering points I have. How would I handle the two meters I have ? So I have integrated in Eloverblik on home assistant two metering points, how in the configuration page do I set this up so it'd import in the db both metering points ?

gllmlbrt commented 3 years ago

I managed of course to included in the db both metering points by runing the helper twice, and by changing the "measurement" to the name of the metering point, and changing the "prefix" of the relevant sensor. Now obviously this is all manual and defeats the purpose if one needs to runt this manually twice a day. It was simply to let you know that it works and all there is to do is to loop the helper for multiple sensor prefixes and measurement name variables... :-)

HBDK commented 3 years ago

Well it sounds like that will be a easy fix, I'll see if I can find time to get it done during this week.

HBDK commented 3 years ago

may i ask what you changed from the first run to the next? i would like to make sure i test a relevant scenario.

gllmlbrt commented 3 years ago

may i ask what you changed from the first run to the next? i would like to make sure i test a relevant scenario.

Sure, so I run first: db_measurement_name: Energy MeterID1 sensorPrefix: sensor.eloverblik_meterid1_energy_ That creates the measurement for the MeterID1 in influx/grafana

Then I rerun the helper with changing to: db_measurement_name: Energy MeterID2 sensorPrefix: sensor.eloverblik_meterid2_energy_ That creates the measurement for the MeterID2 in influx/grafana

meterID1 or meterID2 stand for whatever I want it to be called in influx db and it needs to match in this case the custom entity name i gave it for the sensors.

Then I can plot both measurements in grafana. image

Although I have not figured out how to plot both bars next to each other, rather than one behind the other... But that's a grafana thing...

Hope this helps. Let me know.

gllmlbrt commented 3 years ago

So ideally, it should be something like below as input in the config which allows: db_measurement_name: {Energy MeterID1, Energy MeterID2} sensorPrefix: {sensor.eloverblik_meterid1_energy_,sensor.eloverblik_meterid2_energy_}

And then it runs for both variable pairs.

Optional feature :Would also be nice to have a built in routine, running the helper say every x hours, where the X is a parameter in the config. I know one can make an automation, but I feel it is more elegant to avoid the need for an automation.

HBDK commented 3 years ago

so i made it so you can specify sets like so:

sets:
  - sensorPrefix: sensor.eloverblik_meterid1_energy_
    db_measurement_name: "Energy MeterID1"
  - sensorPrefix: sensor.eloverblik_meterid2_energy_
    db_measurement_name: "Energy MeterID1"

i have updated the check for existing values to look a specific friendly name so you should be able to add multiple meters to the same measurement if that for some reason makes graphing easier (it might still need a prefix tag to make it useful).

On the question of adding a timer, short answer: no

longer answer: i would have add stuff that home assistant already does very well to do this and turn a simple script into a full blown service, i think that is a bit silly considering how easy it is to get home assistant to start this addon up everytime there is a new value. (plus i think it's rather inelegant to poll when we can react)

gllmlbrt commented 3 years ago

i have updated the check for existing values to look a specific friendly name so you should be able to add multiple meters to the same measurement if that for some reason makes graphing easier (it might still need a prefix tag to make it useful).

Thanks I am eager to test. Sorry if it is a silly question but how to I update and run a branch of the add-on ?

On the question of adding a timer, short answer: no

longer answer: i would have add stuff that home assistant already does very well to do this and turn a simple script into a full blown service, i think that is a bit silly considering how easy it is to get home assistant to start this addon up everytime there is a new value. (plus i think it's rather inelegant to poll when we can react)

Point taken, I see it now. It was just that I have a bunch of automatons like most people, I try to limit the number.

HBDK commented 3 years ago

Thanks I am eager to test. Sorry if it is a silly question but how to I update and run a branch of the add-on ?

No idea... I don't think you can do that and it's a real pain for us that want to test stuff.. I just place the files in the add on folder and install it as a local for now. (Keep in mind the slug is different for a locally installed version so you have to update the automations when you switch back to the "real" one).

I try to limit the number

I don't... :) It's imo pointless to try and limit them it's better to create a more structured config that is easy to maintain even if you end up with ridiculous amounts of automations...

gllmlbrt commented 3 years ago

Worked like a charm:

2020-10-19 22:47:17,529 - INFO: Starting El overblik helper
2020-10-19 22:47:17,530 - INFO: Got Eloverblik for database
2020-10-19 22:47:18,455 - INFO: Inserted data for: 2020-10-18
2020-10-19 22:47:19,090 - INFO: Inserted data for: 2020-10-18

I had to leave blank the original parameters to define the sets which will have to be made clear in the readme:

db_measurement_name: ''
sensorPrefix: ''
sets:
  - sensorPrefix: sensor.eloverblik_meterid2_energy_
    db_measurement_name: Energy ID1
  - sensorPrefix: sensor.eloverblik_meterid2_energy_
    db_measurement_name: Energy ID2

I'd say it does the job well ! thanks !!

HBDK commented 3 years ago

It should just ignore the "original parameters" I was thinking to release this as is for now ( probably add a name to each so they can be in the same series but grouped by the name ) and then give it all a follow up in a week or two where I update the documentation and make some minor improvements that is more nice to have than need.

HBDK commented 3 years ago

i have made my changes and i think the current approach is the right one. it forces all points into the same measurement but you have a name that you can group them by.

the config becomes:

sets:
  - sensorPrefix: sensor.eloverblik_meterid2_energy_
    name: Energy ID1
  - sensorPrefix: sensor.eloverblik_meterid2_energy_
    name: Energy ID

would you mind testing the new version out?

gllmlbrt commented 3 years ago

Will do tomorrow and revert. Thanks !

gllmlbrt commented 3 years ago

Tested. Get the following error:

2020-10-20 23:02:00,501 - INFO: Starting El overblik helper
2020-10-20 23:02:00,502 - INFO: Got Eloverblik for database
Traceback (most recent call last):
  File "/app/main.py", line 35, in <module>
    extractors = ExtractorBuilder(options).build()
  File "/app/Extractor.py", line 72, in build
    Extractors.append(Extractor(self.options['baseUrl'],options['sensorPrefix'],self.token, self.options['Timezone'],self.options['db_measurement_name'], options["name"]))
KeyError: 'name'

I tried with arguments under Sets with "name", "db_measurement_name" and both at the same time Here is the full config I used:

db_ip: 192.168.0.100
db_name: Eloverblik
db_measurement_name: ''
db_port: 8086
db_user: <user>
db_pass: <pass>
sensorPrefix: ''
sets:
  - sensorPrefix: sensor.eloverblik_meterid1_energy_
    db_measurement_name: Energy MeterID1
  - sensorPrefix: sensor.eloverblik_meterid2_energy_
    db_measurement_name: Energy MeterID2 #tried adding "name" as well
webhookUrl: ''
Timezone: Europe/Copenhagen
HBDK commented 3 years ago

Change the db_measurement_name keys to just name

gllmlbrt commented 3 years ago

Change the db_measurement_name keys to just name I had tried that as mentioned, but received the same error. But I realised now that I had not updated properly the local add-on. I have updated now, but I get the following error:

2020-10-21 07:28:14,305 - INFO: Starting El overblik helper
2020-10-21 07:28:14,305 - INFO: Got Eloverblik for database
Traceback (most recent call last):
File "/app/main.py", line 50, in <module>
if not data[0]['tags']['Metering date'] == Einf.GetLatestMeterDate(extractor.measurementName,data[0]['tags']['friendly_name']):
File "/app/Einfluxer.py", line 25, in GetLatestMeterDate
result = self.Client.query('SELECT last("value"),"Metering date" FROM "' + self.Database + '"."autogen"."'+ measurementName +'" WHERE ("friendly_name" = \'' + friendlyName + '\')')
File "/usr/local/lib/python3.9/site-packages/influxdb/client.py", line 527, in query
results = [
File "/usr/local/lib/python3.9/site-packages/influxdb/client.py", line 528, in <listcomp>
ResultSet(result, raise_errors=raise_errors)
File "/usr/local/lib/python3.9/site-packages/influxdb/resultset.py", line 25, in __init__
raise InfluxDBClientError(self.error)
influxdb.exceptions.InfluxDBClientError: invalid measurement

My config input is this:

db_ip: 192.168.0.100
db_name: Eloverblik
db_measurement_name: ""
db_port: 8086
db_user: <user>
db_pass: <pass>
sets:
- sensorPrefix: sensor.eloverblik_meterid1_energy_
name: Energy MeterID1
- sensorPrefix: sensor.eloverblik_meterid2_energy_
name: Energy MeterID2
webhookUrl: ""
Timezone: Europe/Copenhagen
sensorPrefix: ""
HBDK commented 3 years ago

Sorry you have to add a name in the empty measurement name you got in the root. I'll make it a bit more clear before I merge.

gllmlbrt commented 3 years ago

Ok so I did that:

db_ip: 192.168.0.100
db_name: Eloverblik
db_measurement_name: Energy
db_port: 8086
db_user: <user>
db_pass: <pass>
sets:
  - sensorPrefix: sensor.eloverblik_meterid1_energy_
    name: MeterID1
  - sensorPrefix: sensor.eloverblik_meterid2_energy_
    name: MeterID2
webhookUrl: ""
Timezone: Europe/Copenhagen
sensorPrefix: ""

And ran it on a completly new db with no data in it. As it turns out it insert only the first name data. There is onlyMeterID1 availble as name in grafana/influxDB. It apparently stops with the first nameset, and thinks there is already data, and does not proceed with the second name:

2020-10-21 07:55:31,943 - INFO: Starting El overblik helper
2020-10-21 07:55:31,944 - INFO: Got Eloverblik for database
2020-10-21 07:55:32,631 - WARNING: no values! is this first time you run this?
2020-10-21 07:55:34,717 - INFO: Inserted data for: 2020-10-19
2020-10-21 07:55:35,238 - INFO: Ran but already had data for: 2020-10-19
HBDK commented 3 years ago

Hmm, I'll look at it tonight.

HBDK commented 3 years ago

Btw can you find the friendly name of one sensor from each set and post?

gllmlbrt commented 3 years ago

I do not understand. Basically in Influx/grafana there is only 1 db name (Energy: normal). But it transfers only one "name" so as a tag I can only see 1 of the two. But it work well in the previous version. So I do not understand

HBDK commented 3 years ago

the thing with the first solution was that it puts the two sets of values into separate measurements, but as far as i can tell the right way to do this is to put both sets of values into the same measurement and instead use a tag to filter or group the values depending on what you want.

HBDK commented 3 years ago

so i think it's solved now.

the check for existing values was a bit strange but i think it's a little more reasonable now.

gllmlbrt commented 3 years ago

Yes, tested, and it works all fine now. Thanks a lot !

2020-10-22 07:08:37,221 - INFO: Starting El overblik helper
2020-10-22 07:08:37,221 - INFO: Got Eloverblik for database
2020-10-22 07:08:40,503 - INFO: Inserted data for: 2020-10-20
2020-10-22 07:08:41,291 - INFO: Inserted data for: 2020-10-20

And both tag names show for each metering point and I will set up my automations. Needs to be triggered with two "metering date" sensors, because pour metering points are not updated at the same time.

Now I had to delete and loose all previous data on my database to test all this from scratch. SO I am eager to get the bulkLoader.py updated as well to I can rebuild the data and have it all back in Grafana :-) Let me know when ready so I can also test it with two metering points.

HBDK commented 3 years ago

Glad to hear it works