I’m working on a project that will add some Home Assistant smarts to my adjustable bed. I am using an ESP32 to control a set of relays to bypass the normal operating remote for a bed to raise and lower the head and the feet. I added two MPU-6050 Acceleration Sensors to the frame of the bed to monitor the tilt positions. What I am struggling with is having the ability to adjust the bed to predetermined tilt positions. My plan is to use a global variable in the ESPHome configuration to set the desired tilt positions and activate the motors to either lift or lower the bed and stop when it reaches that position. Here is what I’m trying that is not working for a button configuration. Any help or ideas would be appreciated.
button:
- platform: template
name: Craftmatic Zero G
icon: "mdi:bed"
on_press:
then:
- lambda: |-
id(head_target) = 11;
id(feet_target) = 44;
ESP_LOGI("main", "head_target: %d. feet_target: %d", id(head_target), id(feet_target));
# on_value_range: head_pitch
# - above: 11
# then:
# - switch.turn_on: head_down
# - below: 11
# then:
# - switch.turn_on: head_up