using HASS .116.0 (updated yesterday) and Supervisor 247
Yesterday, I started to push data from Home Assistant into InfluxDB.
host: 192.168.1.42
port: 8086
username: !secret influxdb_username
password: !secret influxdb_password
database: homeassistant
include:
entities:
- sensor.weatherstation_outside_temperature
- sensor.weatherstation_outside_pressure
- sensor.weatherstation_outside_humidity
- sensor.greenhouse_temp_soil
- sensor.greenhouse_temp_outside
- sensor.greenhouse_temp_inside
Senosr data is coming from MQTT platform and initially the data was send with the unit of measurement included in the MQTT payload. Eg: 15掳C, 80%, 1014hPa. The unit_of_measurement was mentioned in the sensor but set to "". The transfer to InfluxDB went OK, into measurements having the name of the entity mentioned above. But data was stored as a string/state and hence not useful to Grafana. I grasped and understand this. So far so good.
So I changed the MQTT transfer to be without the unit of measurement, only numeric data. changed the sensor so unit_of_measurement would be "掳C" or "%" or "hPa". On the HA side all OK. However on the InfluxDB side, now measurements with the name 掳C, % and hPa are created and data is pushed in there but this time with field value and numeric data (so that is OK)
show measurements
name: measurements
name
%
hPa
sensor.greenhouse_temp_inside
sensor.greenhouse_temp_outside
sensor.weatherstation_outside_humidity
sensor.weatherstation_outside_pressure
sensor.weatherstation_outside_temperature
掳C
To double-check behaviour, I commented out unit_of_measurement in the sensor and got then the data in the entity measurement with the value filed but then of course in HA you do not see the 掳C or % or hPa as unit appended to the value which is also not desirable.
platform: mqtt
unique_id: greenhouse_tempoutside
name: "Greenhouse Temp Outside"
state_topic: "greenhouses/greenhouse-DCA6323B6CF8/temp/outside"
device_class: temperature
platform: mqtt
unique_id: greenhouse_tempinside
name: "Greenhouse Temp Inside"
state_topic: "greenhouses/greenhouse-DCA6323B6CF8/temp/inside"
device_class: temperature
Is this normal behavior or a issue/bug?
Note: you should indicate in the documentation that when a database eg: homeassistant, is created, one should also create a retention policy for it as the preceding of the entity (in my case 'sensor') is taken as a retention policy in InfluxDB (1.8.2)
eg:
create database homeassistant
use homeassistant
create retention policy "sensor" on homeassistant duration 0s replication 1 default
show retention policies
name duration shardGroupDuration replicaN default
autogen 0s 168h0m0s 1 false
sensor 0s 168h0m0s 1 true
Running HA on Raspberry PI 4B 4 GB version 0.116.0 with supervisor 247.
InfluxDB : 1.8.2 on Windows 10 Update 2004
arch | armv7l
-- | --
chassis | embedded
dev | false
docker | true
docker_version | 19.03.11
hassio | true
host_os | HassOS 4.13
installation_type | Home Assistant OS
os_name | Linux
os_version | 4.19.127-v7l
python_version | 3.8.5
supervisor | 247
timezone | Europe/Brussels
version | 0.116.0
virtualenv | false
configuration.yaml
influxdb documentation
influxdb source
(message by IssueLinks)
Hey there @fabaff, @mdegat01, mind taking a look at this issue as its been labeled with an integration (influxdb) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)
Hi, tested above with HassOS 4.16, HA 0.117.6 and Supervisor 2020.11.0 but issue remains.
Any idea when this will be looked at?
Thx
Marc
@MarcEngrie when adding data points to influxdb running v1.x.x the API requires that a measurement be provided with each data point. By default, the InfluxDB integration in HA uses the value in unit_of_measurement if it is present when recording a state change for an entity. If there is no unit_of_measurement for a given entity then it uses the ID of the entity instead. So what you are describing sounds like everything is working as expected using the default configuration for measurement.
Note that if you don't like this behavior you do have a number options available to you for changing it. measurement_attr can be set which changes the default behavior here so you can use entity ID instead of unit_of_measurement as the measurement field. You can also specify an override_measurement if you would prefer to store all data points in a single measurement.
Additionally you can also take more fine-grained control over this by using component_config, component_config_domain and component_config_glob to override the measurement used for specific entities or groups of entities. This is good if you generally like the default behavior but want to tweak it for some specific entities.
@mdegat01 Thx for this feedback. Somehow I did not grasp this default behavior. Now I understand it.
I implemented the suggested measurement_attr and this, indeed, solves my problem.
Thx a lot
Marc
Most helpful comment
@MarcEngrie when adding data points to influxdb running v1.x.x the API requires that a measurement be provided with each data point. By default, the InfluxDB integration in HA uses the value in
unit_of_measurementif it is present when recording a state change for an entity. If there is nounit_of_measurementfor a given entity then it uses the ID of the entity instead. So what you are describing sounds like everything is working as expected using the default configuration for measurement.Note that if you don't like this behavior you do have a number options available to you for changing it. measurement_attr can be set which changes the default behavior here so you can use entity ID instead of
unit_of_measurementas the measurement field. You can also specify an override_measurement if you would prefer to store all data points in a single measurement.Additionally you can also take more fine-grained control over this by using
component_config,component_config_domainandcomponent_config_globto override the measurement used for specific entities or groups of entities. This is good if you generally like the default behavior but want to tweak it for some specific entities.