Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blink lights: return lights to initial state when blink finished? #12

Open
bob454522 opened this issue Jul 9, 2024 · 1 comment
Open

Comments

@bob454522
Copy link

first of all- Thank you very much for making this public, and taking the time to create it. It's very nice of you to do this, and has helped me learn quite a bit (more) about HA.

It would be great (and useful for many i think), if your Blink Lights automation could return the lights to their initial state. (for example if a light is ON and brightness = 50%, when the blink is completed, the light is still on but at 100% brightness).

I'm going to figure out how to accomplish this myself and will update this (here) with my solution, although it may not be pretty.

thanks

@bob454522
Copy link
Author

with The help of chatGPT and your code / blueprint I was able to get what I want working (but as predicted it's sloppy and not portable). I was trying to use chatGPT to help me create a new blueprint just like yours, but that also integrated this option (return brightness to initial level) , but it wasn't happening.

so if others are interested here is the automation im using (I first created the automation using Edwards blueprint, and then "took ownership" of the automation in HA so that I could then directly edit the .yaml of the automation. (This "taking ownership" of an automation generated by a blueprint seems to be a new feature of the July 2024 HA update )

mode: single
trigger_variables:
  input_pause_entities:
    - input_boolean.disableall_light_automations
  input_pause_entities_selected: |-
    {% if input_pause_entities %}
      true
    {% else %}
      false
    {% endif %}
trigger:
  - platform: state
    entity_id:
      - input_boolean.blink_lights_manual
    to: "off"
    from: "on"
  - platform: state
    entity_id:
      - input_boolean.blink_lights_manual
    to: "on"
    from: "off"
condition:
  - condition: or
    conditions:
      - condition: template
        value_template: "{{ ( input_pause_entities_selected == false ) }}"
      - condition: state
        entity_id:
          - input_boolean.disableall_light_automations
        state: "off"
variables:
  repeat_count: 4
  original_states: >-
    {% set ns = namespace(states=[]) %}
    {% for entity in ['light.office_right_lights_3x', 'light.family_room_den_side', 'light.xbox_room_main_lights'] %}
      {% set ns.states = ns.states + [ { 'entity_id': entity, 'state': states(entity), 'brightness': state_attr(entity, 'brightness') | int if state_attr(entity, 'brightness') else None } ] %}
    {% endfor %}
    {{ ns.states }}
action:
  - repeat:
      count: "{{ repeat_count * 2 }}"
      sequence:
        - service: homeassistant.toggle
          data: {}
          target:
            entity_id:
              - light.office_right_lights_3x
              - light.family_room_den_side
              - light.xbox_room_main_lights
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 393
  - service: homeassistant.turn_on
    data_template:
      entity_id: >
        {{ original_states | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | join(', ') }}
  - service: homeassistant.turn_off
    data_template:
      entity_id: >
        {{ original_states | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | join(', ') }}
  - service: light.turn_on
    data_template:
      entity_id: >
        {{ original_states | selectattr('brightness', 'ne', None) | map(attribute='entity_id') | join(', ') }}
      brightness: >
        {{ original_states | selectattr('brightness', 'ne', None) | map(attribute='brightness') | first }}
alias: Blink lights Test
description: Jul 8 2024- testing light blinking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant