Skip to content

Instantly share code, notes, and snippets.

@itayavra
Last active June 7, 2025 22:40
Show Gist options
  • Select an option

  • Save itayavra/e14677bd2e8d1f45bf05c575c183be80 to your computer and use it in GitHub Desktop.

Select an option

Save itayavra/e14677bd2e8d1f45bf05c575c183be80 to your computer and use it in GitHub Desktop.
A callable automation blueprint that cycles a light through configurable brightness levels. If brightness is at or above the highest level, it wraps to the lowest.
blueprint:
name: Cycle Tuya light brightness
description: >
A callable automation blueprint that cycles a light through configurable brightness levels.
If brightness is at or above the highest level, it wraps to the lowest.
domain: automation
input:
target_light:
name: Light to control
description: Select the light entity whose brightness will be cycled.
selector:
entity:
domain: light
brightness_levels:
name: Brightness Levels
description: >
List of brightness levels (percent) to cycle through. Example: [1, 33, 66, 100]
default: [1, 33, 66, 100]
selector:
object:
trigger: []
mode: restart
variables:
processed_brightness_levels: !input brightness_levels
action:
- service: system_log.write
data:
message: "Light Cycle Debug: Processed Levels: {{ processed_brightness_levels }}"
level: info
- variables:
light_entity_id: !input target_light
current_brightness_pct_ha_attr: >
{% set current_pct = state_attr(light_entity_id, 'brightness_pct') %}
{% if current_pct is not none %}
{{ current_pct | float(0.0) }}
{% else %}
{% set current_255 = state_attr(light_entity_id, 'brightness') | float(0.0) %}
{{ (current_255 / 255.0 * 100.0) | round(0) | float }}
{% endif %}
- service: system_log.write
data:
message: "Light Cycle Debug: Current Brightness PCT: {{ current_brightness_pct_ha_attr }}"
level: info
- variables:
next_brightness: >
{% set levels = processed_brightness_levels %}
{% set current_val = current_brightness_pct_ha_attr %}
{% set sorted = levels | sort %}
{% set next_list = sorted | select('gt', current_val) | list %}
{{ (next_list[0] if next_list | length > 0 else sorted[0]) }}
- service: system_log.write
data:
message: "Light Cycle Debug: Setting brightness to: {{ next_brightness }}"
level: info
- service: light.turn_on
target:
entity_id: "{{ light_entity_id }}"
data:
brightness_pct: "{{ next_brightness }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment