I am new to ESPHome and am trying to migrate form using C++ (or Python!).
I want to make sure that an RGB LED is off when I boot.
This code doesn’t work as it confuses the switches. How do I identify each LED
colour independently?
Here is what I tried …
- platform: gpio
pin: GPIO32
name: "LED red"
switch:
- platform: gpio
pin: GPIO33
name: "LED green"
switch:
- platform: gpio
pin: GPIO14
name: "LED blue"
on_boot:
then:
- switch.turn_off: LED red
- switch.turn_off: LED green
- switch.turn_off: LED blue```
By the way I tried your quote marks - without success!!
Thanks
Bruce
I’ve never set up switches myself and I’m not sure what you mean by “it confuses the switches”, but I don’t know if I’ve ever seen a config that allows multiple of the same key like that. Could you confirm that you have the correct structure for multiple switches?
A quick search of “esphome switch configuration” here in the forums shows that people generally use something more like this:
OK Thanks for your reply, but the documentation still leaves me confused!
In my code I tried to use the “name”.
So what is the difference between a “name” and an “id”?
The documentation on ids is clear - the id becomes a variable name in C++ (so that is clear).
But what is a name then?
When should I use either name or id? Or are there other “types” lurking somewhere?
As always the documentation seems to give “boilerplate” sketches which are probably great once you understand the ESPHome concepts, but leave beginners in the dark!!!
To steal a phrase “A snippet of working code is worth a thousand words” …
Thanks Jorg, yes I tried all of the usual Googling, and found a few hints - but mostly on esphome.io…
Thanks for the hint on “name” - since I am not using HA, then I can drop that and just keep the “id” - I read that the name is used as a C++ variable, so the usual rules apply (eg no spaces).
The code is similar to your suggestion, but this is it …
Thanks orange-assistant, so I have done quite a bit of reading over the last week or so!
The automations part was where I found “on_boot”.
The issue I am having is at COMPILE time! I don’t get as far as rebooting the machine!
Still not convinced “the website does really has lot’s of useful stuff to offer” , I agree lot’s of stuff, just not convinced that it is “useful” in getting code running!
The error at the compile time is a result of your wrong yaml. @cyn actually was so nice to correct the code for you. The only transfer you actually need to do now is a copy and paste.
The error you got:
You might want to use a editor with syntax highlighting so you can correct your errors before even try compiling
Can you suggest an editor with syntax highlighting that I could use?
Currently I am using the ESPHome web page and the edit function from there.
Thanks