Getting value from separat InfluxDB as sensor

Hi all

Another issue where I don’t know how to solve - and the google solutions didn’t work.

I built a water meter for monitoring the water consumption of my house. In fact its a webcam over the meter and some python code for interpreting the pointer. If there is a change it is writing the difference (>0.25 liter) into an InfluxDB.

Now I want to visualize the consumption in a lovelace statistic card and thought the easiest way would be to create a sensor which is reading the last value from this DB table. Something like this:

SELECT last("Current_Consump") AS "mean_Current_Consump" FROM "water"."autogen"."Consump" 

How can I create this?
And overall, is this a good solution or are there better ways to do so?

Thanks in advance and cheers
Marco

Did you check the docs for the influxdb sensor?

Yes and I was struggling again with the YAML.

But now I checked it again and I think I found my error.

sensor:
  - platform: influxdb
    host: localhost
    username: bla
    password: blabla
    queries:
    - name: last_water_value
      unit_of_measurement: l
      value_template: '{{ value | round(3) }}'
      group_function: last
      measurement: "Consump"
      where: "time > now() - 1d"
      field: Current_Consump
      database: water

I was doing the measurement part wrong and always got errors. Ok, feeling bit stupid now :wink:

But thanks again Burningstone.

1 Like