I plan to use several proximity sensors. Obviously they will need unique names, but otherwise they are all the same type of device. Do I need to have a separate ESPHome .yaml for each one, even though the bulk of the config data is the same? I want to use “Ultrasonic Sensor 1”, “Ultrasonic Sensor 2”, etc. and that is the only config data that will change.
Yes, you should have separate yaml files with different name, as Esphome will assign these sensors hostnames in local network, based on that (proximity_sensor.local) and use that for (e.g.) OTA updates.
You might also want to move to MQTT in the future which means every sensor will need its own client_id and topic_prefix in mqtt section of the yaml.
Thanks! I’m still trying to grok the MQTT labeling. The dox say the topic prefix defaults to my node name plus the MAC address of my device. I left those blank but the mqtt messages don’t seem to follow that pattern. Here’s my ESPHome yaml for the device and the resulting messages; maybe you could help me understand what I’m seeing.
proximity_sensor.yaml
esphome:
name: proximity_sensor
platform: ESP8266
board: d1_mini
wifi:
ssid: "my_ssid"
password: "my_pwd"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Proximity Sensor"
password: "a_bunch_of_giberish"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
#api: disable to native api and use mqtt
mqtt:
broker: [broker ip]
username: [broker username]
password: [broker_pwd]
ota:
# Example configuration entry
sensor:
- platform: ultrasonic
trigger_pin: D1
echo_pin: D2
name: "Ultrasonic Sensor"
update_interval: 2s
mqtt messages:
▼proximity_sensor
debug = e[0;36m[D][sensor:092]: 'Ultrasonic Sensor': Sending state 1.34730 m with 2 decimals of accuracye[0m
▼sensor
▼ultrasonic_sensor
state = 1.35
status = online
▼homeassistant
▼sensor
▼proximity_sensor
▼ultrasonic_sensor
config = {"unit_of_measurement":"m","icon":"mdi:arrow-expand-vertical","name":"Ultrasonic Sensor","state_topic":"proximity_sensor/sensor/ultrasonic_sensor/state","availability_topic":"proximity_sensor/status","unique_id":"ESPsensorultrasonic_sensor","device":{"identifiers":"84cca8b16622","name":"proximity_sensor","sw_version":"esphome v1.15.3 Jan 20 2021, 10:12:52","model":"PLATFORMIO_D1_MINI","manufacture…
I’m using MQTT because it allows me to view the comm traffic independent of HA. That way I can use an MQTT sniffer to see if the device is working properly without relying on HA integration.