Need help scripting light dimmer w/ flash when hit limits

Hey everyone,

I’m still very new to home assistant having come over from openhab. Here’s what I’m trying to do.

I have a script that when it is triggered will either dim or brighten the referenced bulb. The script checks if the referenced bulb has hit it’s limits either can’t go any brigher brightness=255 or can’t go any dimmer in this case I selected brightness=25 basically 10% of the bulb’s ability. When someone attempts to dim or brighten pass these marks I want the bulb to flash. I tried writing the flash part into the original script but hours later and it still wasn’t flashing. the brightness or dimness of the bulbs are working. I then decided to split the flash part out into it’s own script. now if I call the dimmer script the bulb works fine with the information passed to it with a minor caveat that I get a warning template rendered an invalid service. If I call the flash script it works beautifully so I’m guessing my screw up is in my dimmer script code calling the flash script. I’ve beaten my head against the desk for hours on this so far so I’m really hoping someone can offer me some assistance here.

dimmer:                                                                                
  alias: Dimmer                                                                        
  description: Ramp light brightness up or down                                        
  fields:                                                                              
    light_entity:                                                                      
      description: The light you want to affect                                              
    direction:                                                                               
      description: 'Directon to change brightness: up or down'                                 
      example: up                                                                              
  sequence:                                                                                     
  - service: light.turn_on                                                             
    data_template:                                                                             
     entity_id: >-                                                                          
       {{ light_entity }}                                                              
     brightness_step: >-                                                                       
       {% if direction == 'up' and state_attr(light_entity , 'brightness') < 255 %}         
          +25                             
       {% elif direction == 'down' and state_attr(light_entity , 'brightness')  > 25 %}        
          -25                                                                               
       {% else %}                                             
          0                                                                                    
       {% set flash = 'on' %}                                                               
       {% endif %}                                            
  - service_template: >-                                                                       
     {% if (state_attr(light_entity , 'brightness') | float) <= 255 and direction == 'up' %}
       script.flash                                                                         
     {% elif (state_attr(light_entity , 'brightness') | float) >= 25 and direction == 'down' %}
       script.flash                                                                            
     {% else %}                                                                                
       homeassistant.update.entity                                                             
     {% endif %}                                                                                
       data_template:                                                                          
        entity_id: >-                                                                          
         {{ light_entity }}                                                                    
                                                                                            
flash:                                                                                         
  alias: Flash                                                                                 
  fields:                                                                                   
    light_flash:                                                                               
      description: The light you want to flash                                                 
  sequence:                                                                                 
    service: light.turn_on                                                                     
    data_template:                                                                             
      entity_id: >-                                                                         
       {{ entity_id }}                                                                         
      flash: short                   

that is my code I’m hoping someone can shed some light on my screwup.

thanks,

Chris

1 Like

Anyone?? Please could definitely use the help on this…

1 Like