Hello,
I would like to request some help of my project. I’ve also tried my GPT friend, but it was not able to solve my problem, I always get into a message loop.
I would like to control my light with PWM on GPIO4 (and parallely on GPIO14 as well). I have monostable switch on GPIO2.
Requirements would be:
-brightening/dimming from webgui manually and from HA manually+script. (as of now, it is working)
-
if Ha started the automatic dimming/brightening it should be overruled manually (it is also working)
-
for a short click it should toggle the light: turn on (100%) and turn off (0%) the light, it is not important what value was there before when it is different then 0%-> turn off. if it was 0% then it should changed to 100%.
-
for a long press it should increase the value (if it was 0%) OR previous action was dimming.
-
for a long press it should decrease the value (if it was different then 0%) AND previous action was brightening.
Unfortunately, I’ve encountered a problem where, after the lights are turned off and I attempt to brighten them, they start blinking or sometimes do not respond to the first few actions for several minutes after flashing and boots up correctly.
(I’ve tried to invert the code, then it never dimmed, and fully shined.)
- I bet the startup unressponsiveness is another issue, so first of all let’s focus to the actions.
Please let me know what I’ve missed!
light:
- platform: monochromatic
name: ${friendly_name} Indoor Lighting
id: ${IdPrefix}_light
output: ${IdPrefix}_light_indoor_out
default_transition_length: 1.0s
icon: "mdi:castle"
on_turn_off:
then:
- lambda: 'id(button_released_after_brightening) = false;'
- lambda: 'id(button_released_after_dimming) = true;'
on_turn_on:
then:
- lambda: 'id(button_released_after_brightening) = true;'
- lambda: 'id(button_released_after_dimming) = false;'
- platform: monochromatic
name: ${friendly_name} Outdoor Lighting
id: ${IdPrefix}_light_outdoor
output: ${IdPrefix}_light_outdoor_out
default_transition_length: 1.0s
icon: "mdi:chess-rook"
on_turn_off:
then:
- lambda: 'id(button_released_after_brightening) = false;'
- lambda: 'id(button_released_after_dimming) = true;'
on_turn_on:
then:
- lambda: 'id(button_released_after_brightening) = true;'
- lambda: 'id(button_released_after_dimming) = false;'
# Example output entry
output:
- platform: esp8266_pwm
id: ${IdPrefix}_light_indoor_out
pin: GPIO4
frequency: 200 Hz
#inverted: false
zero_means_zero: true
min_power: 0.00
max_power: 1.00
- platform: esp8266_pwm
id: ${IdPrefix}_light_outdoor_out
pin: GPIO14
frequency: 200 Hz
#inverted: false
zero_means_zero: true
min_power: 0.00
max_power: 1.00
- platform: gpio
pin: GPIO15
id: voltage_meter_power
binary_sensor:
- platform: template
name: "Dimming in Progress"
id: ${IdPrefix}_dimming_in_progress
lambda: |-
return id(dimming_in_progress);
- platform: template
name: "Manual control mode"
id: ${IdPrefix}_manual_control
lambda: |-
return id(manual_control);
- platform: gpio
pin:
number: GPIO2
mode: INPUT_PULLUP
inverted: true
icon: "mdi:castle"
id: ${IdPrefix}_light_touch
filters:
- delayed_on_off: 50ms
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- if:
condition:
and:
- lambda: 'return id(button_released_after_brightening);'
- or:
- light.is_on: ${IdPrefix}_light
- light.is_on: ${IdPrefix}_light_outdoor
then:
- light.turn_off:
id: ${IdPrefix}_light
transition_length: 2.5s
- light.turn_off:
id: ${IdPrefix}_light_outdoor
transition_length: 2.5s
else:
- light.turn_on:
id: ${IdPrefix}_light
transition_length: 2.5s
brightness: 100%
- light.turn_on:
id: ${IdPrefix}_light_outdoor
transition_length: 2.5s
brightness: 100%
- timing:
- ON for at least 1s
then:
- while:
condition:
binary_sensor.is_on: ${IdPrefix}_light_touch
then:
- if:
condition:
and:
- lambda: 'return id(button_released_after_brightening);'
- or:
- light.is_on: ${IdPrefix}_light
- light.is_on: ${IdPrefix}_light_outdoor
then:
- light.dim_relative:
id: ${IdPrefix}_light
relative_brightness: -4%
transition_length: 0.2s
- light.dim_relative:
id: ${IdPrefix}_light_outdoor
relative_brightness: -4%
transition_length: 0.2s
else:
- light.dim_relative:
id: ${IdPrefix}_light
relative_brightness: 4%
transition_length: 0.2s
- light.dim_relative:
id: ${IdPrefix}_light_outdoor
relative_brightness: 4%
transition_length: 0.2s
- delay: 0.2s
on_release:
then:
- if:
condition:
lambda: 'return id(dimming_in_progress);'
then:
- lambda: 'id(manual_control) = true;'
- lambda: 'id(button_released_after_brightening) = true;'
- lambda: 'id(button_released_after_dimming) = true;'
on_press:
then:
- lambda: 'id(button_released_after_brightening) = false;'
- lambda: 'id(button_released_after_dimming) = false;'
globals:
- id: manual_control
type: bool
restore_value: no
initial_value: 'false'
- id: dimming_in_progress
type: bool
restore_value: no
initial_value: 'false'
- id: button_released_after_brightening
type: bool
restore_value: no
initial_value: 'false'
- id: button_released_after_dimming
type: bool
restore_value: no
initial_value: 'false'
Thank’s in advance!