InfluxDB Grafana and tags_attributes

Hello all,

I have been redoing my installation moving all my sensors to Zigbee2MQTT to avoid my reliance on third party hubs. Everything has gone nicely, but my integration with InfluxDB is not quite working as I would like.

I am trying to bring in additional tags, AREA would be nice and getting friendly_name_str to work. I think it is probably tags_attributes: that I need modify in my InfluxDB section of configuration.yaml, but can’t find where this is documented and which attributes you can add.

Has anyone already wrestled with this? Or am i going to have to create a continuous query in Influx to create room specific graphs in Grafana?

1 Like

It’ll help if you post your influxdb: config from Home Assistant.

Snipped version below

influxdb:
  host: 192.168.212.4
  port: 8086
  database: HASS
  default_measurement: state
  include:
    entities:
       - binary_sensor.bridge_router
       - binary_sensor.cc2531_router_router
       - binary_sensor.ring_front_door_ding
       - binary_sensor.ring_front_door_motion 
       - Lots more sensors....
  component_config_glob:
    sensor.*humidity:
      override_measurement: humidity
    sensor.*battery:
      override_measurement: battery
    More Sensor Overrides - but you get this picture
  tags:
    instance: HA_ZM
    source: HA
  tags_attributes:
    - area

It is the tag_attributes that I am trying to find out about

1 Like

So, without tag_attributes, “friendly_name”, for instance, is available as a “field”. By adding it to tag_attributes, it will no longer be a field, but, instead, a tag.

So, by making area a tag, for instance, you would be able to gather all temperature data in a specific area and graph an average of them.

If you just want to know the temperature of a specific sensor, this is possible regardless of which things are fields and which things are tags.

As far as which attributes you can add, to my knowledge, you can add ANY attribute to then become a tag. However, adding, for instance, a battery_level attribute as a tag wouldn’t make a lot of sense because you wouldn’t want to group based on that level because there are so many possible values for that level. “area” is a good choice of things to add as a “tag” because you might want to group by it.

There’s no right or wrong answer here. It’s all dependent on which type of queries you’re going to run.

I would leave it at the defaults, then start building useful queries. When you find a query that would benefit from having that attribute as a tag, add it to tag_attributes.

I don’t use “area” in Home Assistant. I also don’t have anything in tag_attributes and I’ve yet to find a query that needs something there.

Cheers,

That makes a lot more sense now. The only issue I have though is that Influx doesn’t seem to be pulling the AREA tag through:

select * from light group BY area  ORDER BY DESC lIMIT 10
name: light
tags: area=
time                brightness color_temp domain effect_list_str         effect_str entity_id       friendly_name friendly_name_1 friendly_name_str hs_color_str instance    max_mireds min_mireds rgb_color rgb_color_str   source state supported_features value xy_color_str
----                ---------- ---------- ------ ---------------         ---------- ---------       ------------- --------------- ----------------- ------------ --------    ---------- ---------- --------- -------------   ------ ----- ------------------ ----- ------------
1573311302481704960 254                   light                                     cloakroom_main                                Cloakroom Main                 ZMHA                                                 HA     on    41                 1     
1573311212164598016                       light  ['colorloop', 'random']            hall_front_door                               Hall Front Door                ZMHA 500        153                                  HA     off   63                 0     
1573311212162651136                       light                                     cloakroom_main                                Cloakroom Main                 ZMHA                                                 HA     off   41                 0     
1573311181567795968 254                   light  ['colorloop', 'random'] none       hall_front_door                               Hall Front Door   (0.0, 0.784) ZMHA  500        153        255253253 (255, 253, 253) HA     on    63                 1     (0.325, 0.329)```

Any idea?

My tags show up… like this:

> SELECT * FROM "binary_sensor.art_door_wyze" LIMIT 10
name: binary_sensor.art_door_wyze
time                battery device_class_str domain        entity_id     friendly_name_str signal source state state_ timeLastAlarm  timeLastAlarm_str    value
----                ------- ---------------- ------        ---------     ----------------- ------ ------ ----- ------ -------------  -----------------    -----
1571145334068516864         door             binary_sensor art_door_wyze Art Door                 hass   off                                              0
1571145334250636032 96      door             binary_sensor art_door_wyze Art Door          65     hass   off   0      20191015123842 2019-10-15T12:38:42Z 0
1571146534744116992 96      door             binary_sensor art_door_wyze Art Door          65     hass   off   0      20191015123842 2019-10-15T12:38:42Z 0
1571157537860728064 96      door             binary_sensor art_door_wyze Art Door          71     hass   off   0      20191015163850 2019-10-15T16:38:50Z 0
1571171936751727104 96      door             binary_sensor art_door_wyze Art Door          67     hass   off   0      20191015203823 2019-10-15T20:38:23Z 0
1571186335666328064 96      door             binary_sensor art_door_wyze Art Door          68     hass   off   0      20191016003830 2019-10-16T00:38:30Z 0
1571200734697787904 96      door             binary_sensor art_door_wyze Art Door          69     hass   off   0      20191016043837 2019-10-16T04:38:37Z 0
1571215133882700032 96      door             binary_sensor art_door_wyze Art Door          68     hass   off   0      20191016083845 2019-10-16T08:38:45Z 0
1571229532845391104 96      door             binary_sensor art_door_wyze Art Door          67     hass   off   0      20191016123819 2019-10-16T12:38:19Z 0
1571243931750947072 96      door             binary_sensor art_door_wyze Art Door          67     hass   off   0      20191016163826 2019-10-16T16:38:26Z 0

“source” is a tag for me. When I “group by” a tag, the tag no longer shows in the output. I.E.

> SELECT * FROM "binary_sensor.art_door_wyze" GROUP BY entity_id LIMIT 10
name: binary_sensor.art_door_wyze
tags: entity_id=art_door_wyze
time                battery device_class_str domain        friendly_name_str signal source state state_ timeLastAlarm  timeLastAlarm_str    value
----                ------- ---------------- ------        ----------------- ------ ------ ----- ------ -------------  -----------------    -----
1571145334068516864         door             binary_sensor Art Door                 hass   off                                              0
1571145334250636032 96      door             binary_sensor Art Door          65     hass   off   0      20191015123842 2019-10-15T12:38:42Z 0
1571146534744116992 96      door             binary_sensor Art Door          65     hass   off   0      20191015123842 2019-10-15T12:38:42Z 0
1571157537860728064 96      door             binary_sensor Art Door          71     hass   off   0      20191015163850 2019-10-15T16:38:50Z 0
1571171936751727104 96      door             binary_sensor Art Door          67     hass   off   0      20191015203823 2019-10-15T20:38:23Z 0
1571186335666328064 96      door             binary_sensor Art Door          68     hass   off   0      20191016003830 2019-10-16T00:38:30Z 0
1571200734697787904 96      door             binary_sensor Art Door          69     hass   off   0      20191016043837 2019-10-16T04:38:37Z 0
1571215133882700032 96      door             binary_sensor Art Door          68     hass   off   0      20191016083845 2019-10-16T08:38:45Z 0
1571229532845391104 96      door             binary_sensor Art Door          67     hass   off   0      20191016123819 2019-10-16T12:38:19Z 0
1571243931750947072 96      door             binary_sensor Art Door          67     hass   off   0      20191016163826 2019-10-16T16:38:26Z 0

I think your GROUP BY needs an aggregator, and you need a less inclusive select in order to get any useful results. On top of that, you are likely doing a measurement override for light.*

In which case, while this doesn’t work for me, it probably works for you

SELECT MEAN(brightness) FROM light GROUP BY entity_id

I can’t see the area tag either, even though I’ve listed it in tags_attributes. Actually, I can’t even see it in the MariaDB database. Does this actually work for someone?

@swiftlyfalling, what you’re doing is different, you’re creating a new tag with a static value for all events.

I’m unable to access Friendly Name as a field. What would be causing that?