Hi, all.
I am using an M5stack, and I want to update a HomeAssistant switch inside a GPIO button lambda.
Here is some code I am trying to use:
- platform: gpio
id: M5_BtnB
pin:
number: 38
inverted: true
on_click:
then:
lambda: |-
if(id(screen_type) == 1 or id(screen_type) == 2) {
if(id(screen_show_all) == 1) {
id(screen_show_all) = 0;
} else {
id(screen_show_all) = 1;
}
} else if(id(screen_type) == 3) {
id(mbr_bedside_lamp).toggle();
}
I am using the M5stack Button C to cycle between several screen types (screen types are Weather, Temp/Humidity, and Lights). Basically, the M5stack will show me weather data, or ESPHome sensor temp/humidity data, or light data depending on which screen type is being shown.
M5stack button A cycles through the various pieces of data for each screen type: for weather, button A cycles between the days in the forecast; for temp/humidity data, button A cycles between the different temp/humidity sensors in my house; for lights, button A cycles between the various lights in the house.
Button B toggles between “all” and “one” (i.e., all of the weather data, or just one day’s weather data; or all of the temp/humidity sensor data, or just one sensor’s data). For lights, I want button B to toggle the indicated light on or off.
I tried using this in my ESPHome code, but it fails to compile:
switch:
- platform: homeassistant
id: mbr_bedside_lamp
entity_id: switch.mbr_bedside_lamp
I get an error indicating that there is no HomeAssistant switch in ESPHome.
I have searched the web and the forums, and I have found references to controlling a HomeAssistant switch from ESPHome inside a trigger. But I am not using triggers – I am using lambda here. Is it possible to control a HomeAssistant switch from inside a lambda inside ESPHome, or is it only possible inside a trigger? If this only works in a trigger, is it possible to call a trigger from inside a lambda?
Thanks.