I looked over the API page on the Binary Sensor that you linked to. There’s a link to the class, to this page:
https://esphome.io/api/classesphome_1_1gpio_1_1_g_p_i_o_binary_sensor
On that page, checking in inherited functions, I find this:
I think this is contrary to what I read on the other thread I linked to, since it shows there is a way to get or set the name of an EntityBase class, which would also let me get or set the name of a Binary Sensor. However, when I did that, with the text from a Text Template, I get gibberish as a result:
text:
- platform: template
id: MasterSwitchName
name: "Master Switch Name"
optimistic: true
min_length: 0
max_length: 64
initial_value: "Master Switch"
restore_value: true
mode: text
web_server:
sorting_group_id: sorting_group_values
sorting_weight: 2
on_value:
then:
- logger.log:
format: "DEBUG: Name changed to: %s"
args: ["x.c_str()"]
# args: ['id(MasterSwitchName).state']
- lambda: |-
if (!x.empty()) {
id(PrimarySwitch).set_name(x.c_str());
}
I used the log function to verify that I was actually changing the value of the text, then used the lambda (given to me by someone else) to set the name of the Binary Sensor. Once I did that, I reloaded the webpage and the name of the sensor had changed, but was gibberish - not the text from the Text Template.
But I also notice the argument for set_name() is const char *name
. Again, haven’t used C++ in a LONG time, but doesn’t the asterisk indicate something about a pointer? Not at all sure, but I’d basically like to set that name of the Binary Sensor.
(And if I can’t do that, I’d like some way to display the state of that sensor on the web page with a “Friendly Name” that can be changed, so if I have to create some other kind of component that can be renamed, that would report the state of the Binary Sensor, that would would be more complicated, but it would work.)
Also, along that line, if I have an ID and a Name for a Binary Sensor, and I add the device to Home Assistant, will Home Assistant identify the component by the name or ID? I realize if it identifies it by the name, that changing the name would make a mess on the Home Assistant configuration.