This is probably so simple, but I spent over an hour last night searching and reading and couldn’t find anything. It’s gotta be really simple but I just can’t figure out how to do it. Basically, I have a Home assistant text_input that can change whenever I want, and when someone enters a code on my garage keypad, ESPHome ensures that it matches my set keypad (these people are a variety of dog sitter/walkers/maid services/etc). But, I have a sensor set up (well, it’s not my code), but it reports the last user. Normally they are manually set: when I enter 6543 it says “Last User was Mark”.
But when I have a varying variable, I can’t get it to go. Here’s my code:
But I don’t want it to just say “Custom Dog Walker”. I want it to say “Custom Dog Walker Code - 4157” (or whatever the code is. It’s the (dogwalkercode1).
Unfortunately it gives me this error. I’m a very novice at this programming, and I’m completely confused by floats vs integers vs strings, and I think that this is the problem. I just don’t know how to fix.
Compiling .pioenvs/garage-keypad/lib64d/WiFi/WiFiAP.cpp.o
/config/esphome/garage-keypad.yaml: In lambda function:
/config/esphome/garage-keypad.yaml:106:42: error: invalid operands of types 'const char [26]' and 'float' to binary 'operator+'
state: !lambda 'return "Custom Dog Walker Code - " + id(dogwalkercode1).state;'
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Compiling .pioenvs/garage-keypad/lib64d/WiFi/WiFiClient.cpp.o
*** [.pioenvs/garage-keypad/src/main.cpp.o] Error 1
Floats are numeric values with a floating point like 123.456 or 789.0
Integers are numeric values without a floating point like 1234 or 5
Strings are any ranges of characters without a numeric value, like abcd or ab23 but also 4321 can be a string.
Looking at your error message the dogwalkercode1 appears not to be a string but a float, so this has to be converted to a string before the two strings can be added together.
Try this:
ok it worked, thank you! Now for a little more formatting! It returns the wiegand input codes like “4157.000” How can I get it to write only the first 4 numbers and skip the decimal and everything after?