I have 10 identical BLE temp/RH sensors for which I need to add code to sensors.yaml and configuration.yaml
Is there a way to make one generic sensor definition for all 10 sensors? I’d like to avoid copy/pasting this 10 times.
What I have now is:
sensors.yaml
- platform: template
sensors:
in100_batt:
friendly_name: "IN100 Battery"
device_class: battery
unit_of_measurement: "v"
value_template: >-
{{states('sensor.bthome_sensor_0001_count') | float / 32}}
configuration.yaml
template:
- sensor:
- name: "Battery"
unit_of_measurement: "%"
device_class: battery
availability: "{{ states('sensor.in100_batt')|is_number }}"
state: >
{% set batt_volts = states('sensor.in100_batt')|float(0) %}
{% set batt_pct = 55.55 * batt_volts - 83.31 %} {# calculate percent from the voltage #}
{% set batt_pct_clamped = ([0, batt_pct, 100]|sort)[1]|int %} {# clamp the output to a 0-100% range #}
The sensor name sensor.bthome_sensor_0001_count is created by BTHome . The second is, ovbiously, named sensor.bthome_sensor_0002_count.
Is there a way to use the 000? numbering as a variable for the sensor definition in the yamls? I guess there is some scripting involved, but since I have zero scripting skills help from the community is highly appreciated
Or is it just copy/paste this 10 times and edit them accordingly.