I’m using the InfluxDB sensor with the following query:
SELECT entity_id,max(last) as value FROM
(SELECT last("value") FROM "Watts" WHERE ("entity_id" != 'Total') GROUP BY "entity_id");
With this result:
name: Watts
time entity_id value
---- --------- -----
1548096215000000000 Bedroom_2&3 333.12
The following works ok in homeassistant:
sensor:
- platform: influxdb
queries:
- name: Iotawatt Max
measurement: (SELECT entity_id, last("value") FROM "Watts" WHERE ("entity_id" != 'Total') GROUP BY "entity_id")
where: '1 = 1'
field: last
group_function: max
value_template: '{{ value | round(1) }}'
database: iotawatt
The thing is that I need the entity_id
too (which can be extracted with this query: SELECT distinct(entity_id) as value from (SELECT entity_id,max(last) as value from (SELECT last("value") FROM "Watts" WHERE ("entity_id" != 'Total') GROUP BY "entity_id"));
)
The best would however be if the InfluxDB had the tags as attributes (or even the whole result) so one can build a template out of the values.