Hi.
I try to explain how I did it, I’m using HA for about 4 weeks now, currently migrating from Openhab,
But I have more than 25 years experience in Linux, makes it easier for me to tweak files, restart services, read the logs, …
I don’t know the sensors you are using, hope it works with them as it does with mine. What I do have is thermostats for Bosch SmartHomeControl and one Bosch BME680 Sensor directly attached to one of my Raspis, the Bosch SHC has integration in HA, from the BME680 I retrieve data using a python script and mqtt.
Am I right that you are using Home Assistant OS (image from HA flashed to the SD card)? I’m using Home Assistant Core ( manual installation of all HA components on a standard Raspi OS).
In HA OS you might need the File Editor(?) or Samba Plugins to get direct access to the config files
Also please make copies of any files you change, python and yaml is very picky about the formatting and indentation, one little error and it doesn’t like the file anymore. For Editing from a Windows System I strongly recommend tools like notepad++ or Visual Studio Code.
As already explain I’m using template sensors based on a recommendation from other community members. A template sensor is, in simple words, a manually created sensor retrieving its values from another entity. With the template you can how to create the value ( calculation, formatting, …) and you can also add addtional attributes.
I’m not aware that a template sensor can be created with the Web-GUI, thus tweaking the files is required.
Locate the configuration folder in your system, this is the folder containing “configuration.yaml”
Create a new file “template_sensor.yaml”
Define the first template, this is a sample
heizungwz1_temperature_db:
value_template: "{{ states('sensor.heizungwz1_temperature') }}"
friendly_name: "Heizung Wohnzimmer 1 Temperatur"
unique_id: heizungwz1_temperature_db
device_class: temperature
attribute_templates:
update_now: "{{ (now().minute / 5) | round(0) }}"
heizungwz1_temperature_db: this is the name for the new entity. All my entities going to Influx are the original entity_id ( without “sensor.” ) suffixed with “_db”, I’ll get back to that with the influx configuration
value_template: the name in quotes refers to the entity_id of the original sensors, the sensor our new template is based on
unique_id: not sure if I really require this, but it didn’t hurt so far…
device_class: based on list here, tells HA what kind of sensors this is… https://www.home-assistant.io/integrations/sensor/
attribute_templates: the addtional attribute for my sensor, forcing it to update
update_now: name of the attribute, in quotes the calculation to update it every 5 minutes. You can also use “{{ (now()}}” to update every minute. But that’s 1440 rows for each sensor per day, I decided that 5 minutes is good enough for me, and least when storing something related to room temperature
The template language is very powerfull, you can do a lot more than what I’m doing here
Next step is to include to new file in the main configuration file “configuration.yaml”. Open the file and check if you already have a line starting “sensor:”, if not add it at the end of the file. Then include “template_sensor.yaml” for the platform “template” (my file has additional sensors for mqtt and my Fritzbox), the new entry is the last in the list:
sensor:
- platform: mqtt
name: "BME680 Temperature"
state_topic: "sensors/bme680"
unit_of_measurement: '°C'
value_template: "{{ value_json.Temperature }}"
unique_id: bme680_temperature
- platform: fritzbox_netmonitor
host: 192.168.0.1
name: "Fritz DSL"
- platform: template
sensors: !include template_sensor.yaml
if you have no other sensors already defined, it looks like:
sensor:
- platform: template
sensors: !include template_sensor.yaml
After restarting you should see a new entity named “sensor.heizungwz1_temperature_db” ( or any other name you choose above)
My influxdb integration is this:
influxdb:
host: 127.0.0.1
port: 8086
database: homeassistant
username: someuser
password: somepassword
default_measurement: state
include:
entity_globs:
- binary_sensor.*_db
- sensor.*_db
component_config_glob:
sensor.*humidity*:
override_measurement: humidity
sensor.*temperature*:
override_measurement: temperature
sensor.*valve*:
override_measurement: valve
sensor.*battery*:
override_measurement: battery
sensor.*light*:
override_measurement: light
sensor.*synology*:
override_measurement: synology
the entity_globs in “include” defines the entities to store in influx, I choose to store only entities with suffix “*_db”, gives me much finer control on what is going to influx.
In component_config_glob I’m overwriting the names of the measurements used in influx, the influx integration in HA has the odd habit to use the unit of the sensor as name, you then have measurements like “°C” or “%”… I just didn’t like the naming… With the override I for example define that entities matching “sensor.temperature” are going to “temperature” in influx.
sorry, that’s a lot to read, hope it helps.
If somebody from the community knows an easier way, just respond here.
Armin