Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: mi_desk_lamp_1s
- platform: ESP32
- board: esp32doit-devkit-v1
- platformio_options:
- platform: espressif32@1.11.0
- platform_packages: |-4
- framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.4
- wifi:
- ssid: !secret ssid
- password: !secret wpa2
- captive_portal:
- logger:
- api:
- ota:
- sensor:
- - platform: rotary_encoder
- id: rotation
- pin_a: GPIO27
- pin_b: GPIO26
- resolution: 2
- on_value:
- then:
- - if:
- condition:
- # Check if Button is pressed while rotating
- lambda: 'return id(button).state;'
- then:
- # If Button is pressed, change CW/WW
- - lambda: |-
- auto min_temp = id(light1).get_traits().get_min_mireds();
- auto max_temp = id(light1).get_traits().get_max_mireds();
- auto cur_temp = id(light1).current_values.get_color_temperature();
- auto new_temp = max(min_temp, min(max_temp, cur_temp + (x*20)));
- auto call = id(light1).turn_on();
- call.set_color_temperature(new_temp);
- call.perform();
- else:
- # If Button is not pressed, change brightness
- - light.dim_relative:
- id: light1
- relative_brightness: !lambda |-
- return x / 10.0;
- # Reset Rotation to 0
- - sensor.rotary_encoder.set_value:
- id: rotation
- value: 0
- binary_sensor:
- - platform: gpio
- id: button
- pin:
- number: GPIO33
- inverted: True
- mode: INPUT_PULLDOWN
- on_click:
- then:
- # use if-condition instead of toggle to set full brightness on turn_on
- - if:
- condition:
- light.is_on: light1
- then:
- - light.turn_off:
- id: light1
- else:
- - light.turn_on:
- id: light1
- brightness: 100%
- color_temperature: 2700 K
- output:
- - platform: ledc
- pin: GPIO2
- id: output_cw
- min_power: 0.03
- power_supply: power
- - platform: ledc
- pin: GPIO4
- id: output_ww
- min_power: 0.03
- power_supply: power
- power_supply:
- - id: power
- pin: GPIO12
- enable_time: 0s
- keep_on_time: 0s
- light:
- - platform: cwww
- id: light1
- default_transition_length: 0s
- constant_brightness: true
- name: "Lights"
- cold_white: output_cw
- warm_white: output_ww
- cold_white_color_temperature: 5000 K
- warm_white_color_temperature: 2600 K
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement