Skip to content

Instantly share code, notes, and snippets.

@wildekek
Last active December 31, 2025 23:48
Show Gist options
  • Select an option

  • Save wildekek/d6014f57f9af3f8984da062ef1bed664 to your computer and use it in GitHub Desktop.

Select an option

Save wildekek/d6014f57f9af3f8984da062ef1bed664 to your computer and use it in GitHub Desktop.
globals:
- id: candles_current_brightness_level
type: int
restore_value: yes
initial_value: '7'
script:
- id: set_candle_brightness
parameters:
target_brightness: float
then:
- lambda: |-
int target_level = (int)ceil(target_brightness * 7);
if (target_level < 1) target_level = 1;
int current = id(candles_current_brightness_level);
int delta = target_level - current;
if (delta == 0) return;
uint16_t command = (delta > 0) ? 0xED12 : 0xEF10;
auto call = id(default_ir_transmitter).transmit();
esphome::remote_base::NECData data = {0xFF00, command, 1};
esphome::remote_base::NECProtocol().encode(call.get_data(), data);
call.set_send_times(abs(delta));
call.set_send_wait(100);
call.perform();
id(candles_current_brightness_level) = target_level;
ESP_LOGD("candles", "Brightness: %d -> %d (delta: %d)", current, target_level, delta);
output:
- platform: template
id: output_candles
type: float
write_action:
- script.execute:
id: set_candle_brightness
target_brightness: !lambda 'return state;'
light:
- platform: monochromatic
name: "Candles"
id: light_candles
default_transition_length: 0s
device_id: candles
output: output_candles
restore_mode: RESTORE_DEFAULT_OFF
effects:
- automation:
name: "Candle"
sequence:
- remote_transmitter.transmit_nec:
address: 0xFF00
command: 0xF30C
repeat:
times: 3
wait_time: 100ms
- delay: 1s
- light.control:
id: light_candles
effect: none
- automation:
name: "Static"
sequence:
- remote_transmitter.transmit_nec:
address: 0xFF00
command: 0xF10E
repeat:
times: 3
wait_time: 100ms
- delay: 1s
- light.control:
id: light_candles
effect: none
on_turn_on:
then:
- remote_transmitter.transmit_nec:
address: 0xFF00
command: 0xFF00
repeat:
times: 3
wait_time: 100ms
- lambda: 'id(candles_current_brightness_level) = 7;' # Candles reset to 100%
- delay: 100ms
- script.execute:
id: set_candle_brightness
target_brightness: !lambda 'return id(light_candles).current_values.get_brightness();'
on_turn_off:
then:
- remote_transmitter.transmit_nec:
address: 0xFF00
command: 0xFD02
repeat:
times: 3
wait_time: 100ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment