I have a small ESP-01 dimmer with a touch sensor. It works well but I now want to set the minimum brightness when on and I’m stumped. Can anyone help, please?
The full code is below - I have added comments and one option I tried where I thought this could be done but if there is a better way to do this please advise.
Thanks.
esphome:
name: test_dimmer
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_name
password: !secret wifi_password
domain: !secret wifi_domain
reboot_timeout: 5min
manual_ip:
static_ip: x.x.x.x
gateway: y.y.y.y
subnet: 255.255.255.0
logger:
api:
ota:
globals:
- id: my_global
type: bool
restore_value: no
initial_value: 'false'
switch:
# This is to restart the ESPHome device remotely
- platform: restart
name: "Restart ESPHome - Test_Dimmer"
sensor:
- platform: wifi_signal
name: "WiFi - Test_Dimmer"
update_interval: 60s
output:
- platform: esp8266_pwm
pin: 2
frequency: 1000 Hz
id: pwm_a
inverted: TRUE
light:
- platform: monochromatic
name: "Test_Dimmer"
id: led
output: pwm_a
gamma_correct: 0
binary_sensor:
- platform: gpio
pin:
number: 0
inverted: TRUE
id: led_touch
filters:
- delayed_on: 50ms
- delayed_off: 50ms
on_click:
then:
- if:
condition:
light.is_off: led
then:
- light.turn_on:
id: led
brightness: 0.1
- lambda: |-
id(my_global) = (true);
else:
light.turn_off: led
on_press:
then:
- if:
condition:
lambda: |-
return id(my_global);
# When above condition evaluates to true - Fade_up function else Fade_down
then:
- delay: 0.5s
- while:
condition:
binary_sensor.is_on: led_touch
then:
- light.dim_relative:
id: led
relative_brightness: 2%
transition_length: 0.1s
- delay: 0.1s
- lambda: |-
id(my_global) = (false);
else:
- delay: 0.5s
- while:
condition:
and:
- binary_sensor.is_on: led_touch
# This is where I want to set minimum value so that touch sensor only allows 30% minimum
# - lambda: |-
# return {id(led).get_current_values().get_brightness() > 30};
then:
- light.dim_relative:
id: led
relative_brightness: -2%
transition_length: 0.1s
- delay: 0.1s
- lambda: |-
id(my_global) = (true);