I recently started learning ESPHome. The problem is the following: I have several light bulbs and I want to control them through mqtt. In the future I want to buy more, if I can with these. But I don’t want to create an almost individual topic for each lamp. Is it possible to automate this? I wanted to use the MAC address, but I can’t figure out how to bind it to the name
Unfortunately, I did not achieve the desired result. The Device name is changed, but when I want to use this name as a topic name in mutt, the name is written without the suffix
i want to get that lamp name with suffix as topic
Something like:
lamp27-(mac_suffix)/status
I suspect I didn’t quite understand how to use this and would appreciate it if you could provide an example.
How many lamp27’s do you have?
Your yaml and log may help.
Now I have 3 of them, but I want to replace all the lamps.
substitutions:
device_name: lamp27
esphome:
name: $device_name
name_add_mac_suffix: True
esp8266:
board: esp01_1m
# WIFI Setting's
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
priority: 5.0
- ssid: Lamp.update
password: IDoNotKnow
priority: 10.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ...
password: ...
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: !secret api_encryption
# Configuration entry
ota:
password: !secret ota_password
captive_portal:
# MQTT Setting's
mqtt:
broker: test.mosquitto.org
username: ...
password: ....
discovery: true
discovery_prefix: Lamp27-150/homeassistant
log_topic: ${device_name}/logs
on_connect:
then:
- switch.toggle: red_light
- delay: 5s
- switch.toggle: red_light
on_disconnect:
then:
- switch.toggle: blue_light
- delay: 25s
- switch.toggle: blue_light
switch:
- platform: gpio
name: "Red_Light"
id: red_light
pin: GPIO4
- platform: gpio
name: "Green_Light"
id: green_light
pin: GPIO12
- platform: gpio
name: "Blue_Light"
id: blue_light
pin: GPIO14
- platform: gpio
name: "White_Light"
id: white_light
pin: GPIO13
# Output's pin on lamp27
output:
- platform: esp8266_pwm
id: output_red
pin: GPIO4
- platform: esp8266_pwm
id: output_green
pin: GPIO12
- platform: esp8266_pwm
id: output_blue
pin: GPIO14
- platform: esp8266_pwm
id: output_white
pin: GPIO13
light:
- platform: rgbw
name: ${device_name}
red: output_red
green: output_green
blue: output_blue
white: output_white
color_interlock: true
default_transition_length: 0.2s
command_topic: esphome/ota_mode/${device_name}
effects:
- pulse:
name: fpulse
transition_length: 0.2s
update_interval: 0.2s
- pulse:
name: spulse
transition_length: 1s
update_interval: 1s
Please forgive me if the code is badly written.
It seems to be formatted, as in the instructions.
no ideas?
variant 1:
substitutions:
name: esp02
topic: esp/esp02
esphome:
name: ${name}
switch:
- platform: gpio
id: Relay1
name: "Relay 1"
pin: GPIO12
state_topic: "${topic}/gpio12"
command_topic: "${topic}/set/gpio12"
variant2:
substitutions:
name: esp02
esphome:
name: ${name}
switch:
- platform: gpio
id: Relay1
name: "Relay 1"
pin: GPIO12
state_topic: "${name}/gpio12"
command_topic: "${name}/set/gpio12"