Increasing the brightness / reducing the brightness of the lamp illuminating the aquarium - please help

Hello!

I search our community for a solution to brightening and dimming the lamp that illuminates the aquarium. Unfortunately, I do not know much about programming - I guess you have to do it with a script, because automation alone will probably not be enough?

I found a lot of information on this subject, but I cannot integrate the knowledge into one whole.

I have a TY-021CH dimmer working as Local Tuya

My device and entities are:

DEVICE:

device_id: 821e8d3d5aeea786256ac4b3ec67c3bf

ENTITIES:

entity_id: switch.lighting_controller_1_tuya_switch

entity_id: number.lighting_controller_1_tuya_brightness

Switching on is simple:

alias: Big aquarium lights on
description: ""
trigger:
  - platform: time
    at: "10:30:00"
condition: []
action:
  - device_id: 821e8d3d5aeea786256ac4b3ec67c3bf
    domain: number
    entity_id: number.lighting_controller_1_tuya_brightness
    type: set_value
    value: 10
  - type: turn_on
    device_id: 821e8d3d5aeea786256ac4b3ec67c3bf
    entity_id: switch.lighting_controller_1_tuya_switch
    domain: switch
mode: single

Unfortunately, I have no idea how to brighten an already turned on lamp.
I think it should probably be a loop where:
The values will go from 10 to 1000, I want the step to be 1 and the waiting time is 4 seconds:
(Tuya dimmer - takes numerical values from 10 to 1000)

That is:

- Set the brightness to: 11 
- Wait 4 seconds 
- Set the brightness to: 12 
- Wait 4 seconds 
- Set the brightness to 13 
...
and so on until the brightness is 1000

Can I ask you for help in this matter?
Thanks in advance for all the information.

Kind regards.
Robert

Use call services not device actions. Combine it with a repeat until.

This automation does it all. You can play around with step, start, and end. Just make sure to keep start lower than end, and make the step size smaller than start minus end.

alias: Big aquarium lights on
trigger:
  - platform: time
    at: "10:30:00"
variables:
  step: 1
  start: 10
  end: 1000
  stops: "{{ range(start, end + 1, step) | list }}"
action:
- service: switch.turn_on
  target:
    entity_id: switch.lighting_controller_1_tuya_switch
- repeat:
    for_each: "{{ stops }}"
    sequence:
    - service: number.set_value
      target:
        entity_id: number.lighting_controller_1_tuya_brightness
      data:
        value: "{{ repeat.item }}"
    - delay:
        seconds: 4

and because you’ll probably want a turn off…

alias: Big aquarium lights off
trigger:
  - platform: time
    at: "22:30:00"
variables:
  step: 1
  start: 1000
  end: 10
  stops: "{{ range(start, end - 1, -step) | list }}"
condition:
- condition: state
  entity_id: switch.lighting_controller_1_tuya_switch
  state: 'on'
action:
- repeat:
    for_each: "{{ stops }}"
    sequence:
    - service: number.set_value
      target:
        entity_id: number.lighting_controller_1_tuya_brightness
      data:
        value: "{{ repeat.item }}"
    - delay:
        seconds: 4
- service: switch.turn_off
  target:
    entity_id: switch.lighting_controller_1_tuya_switch
1 Like

and here is another take on it which I use for fading on my deck light:

automation:
  - alias: LC Deck Light Fade On at Dusk
    initial_state: 'on'
    mode: restart
    trigger:
      - platform: state
        entity_id: sensor.dark_outside
        to: 'true'
      - platform: sun
        event: sunset
        offset: "+00:07:00"
    condition:
      - condition: state
        entity_id: light.deck_light_0a4c
        state: 'off'
    action:
      - service: light.turn_on
        data:
          entity_id: light.deck_light_0a4c
          brightness: 5
      - repeat:
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.deck_light_0a4c
                brightness: "{{ state_attr('light.deck_light_0a4c', 'brightness') | int + 1 }}"
            - delay: 2
          until:
            condition: or
            conditions:
              - condition: template
                value_template: "{{ state_attr('light.deck_light_0a4c', 'brightness') | int >= 254 }}"
              - condition: state
                entity_id: light.deck_light_0a4c
                state: 'off'

you just need to substitute your entities & desired values for mine.

That relies on the hardware status. Tuya devices are known to be… sub-par. In his case, he would need to have 100% uptime over 66 minutes for an until repeat version to work. Personally, I wouldn’t trust any Tuya device to maintain that uptime based on all the issues we see on the forums.

EDIT: Marius just had a until loop that caused a memory leak because it fired infinitely when the first action failed to occur which skipped the delay (causing the until to never be reached).

1 Like

I didn’t realize they were that unreliable.

I guess I’m glad I don’t have any of those. :slightly_smiling_face:

I use a zigbee bulb and haven’t ever run into that situation.

Yeah, I’d trust zwave or zigbee. Tuya not so much

@petro - thank you everything works great!

I have an additional question for you, can you recommend any materials on the Internet that will allow me to understand the syntax and use the knowledge in the future, e.g. in other automation?

I analyzed the code you wrote, it is understandable to me except for one line:

stops: "{{ range(start, end - 1, -step) | list }}"

I don’t understand the entry on this line:

| list

I don’t understand what it means - list

Can I ask you to explain this line of code?

that turns the range into a list. | is an operation that means “apply filter”, and list is the filter. So you’re turning range(…) into a list.

Oh - I understand.

Thanks again for your help in solving my problem and explaining the action.

Kind regards.