I’m trying to import the state of a switch from HA and then use it in lambdas to trigger other actions. However, after compiling, uploading and running I’m getting a ‘warning’ error that esphome “Can’t convert ‘off’ to number!”. Can anyone point me in the right direction?
I tried text sensor and am now getting a new error.
error:
src/main.cpp: In lambda function:
src/main.cpp:419:33: error: no match for 'operator==' (operand types are 'std::string {aka std::basic_string<char>}' and 'int')
if ( fan_state_ha->state == 'on' {
^
While I’m not 100% what you want to accomplish, I think what you may want to look at is including the lambda function for triggering another action in the text_sensor itself. I’m going to link to some of my ESPHome YAML on GitHub, maybe it’ll help you get started:
The YAML is for a light switch that has red, blue, and green LED indicator lights on it. Down at the very bottom, I have a couple of homeassistanttext_sensors that look at the state of some smart bulbs in the room (I’ve programmed the smart switch to control my smart bulbs) as well as the state of the garage door. Based on those sensors, the blue LED on the light switch may be solid, off, or blinking, and the action of turning the LED on/off is executed by lambda functions in the text_sensor itself.
Excellent. Thank you! Changed my single quote marks to double and started seeing some success. Using your example I was able to clean things up a bit too and was able to accomplish what I was aiming for without the intermediate sensor or switch. Thanks for the help!