Looking for an optimized was to pulsate some lights, without overloading their Hub (Tradfri in this case), ive set up this script now , which I could repeat/while:
script:
pulsate_sterren:
alias: Pulsate sterren
mode: restart
sequence:
- service: light.turn_on
data:
entity_id: light.kerststerren
transition: >
{{states('input_number.transition_time')}}
brightness: 50
- delay: >
{{states('input_number.transition_time')}}
- service: light.turn_on
data:
entity_id: light.kerststerren
transition: >
{{states('input_number.transition_time')}}
brightness: 250
- delay: >
{{states('input_number.transition_time')}}
please see if I am being silly here, and add improvement where possible?
thanks!
ha, this works:
automation:
- alias: Pulsate lights
id: Pulsate lights
trigger:
platform: state
entity_id: input_boolean.pulsate_light
to: 'on'
action:
- repeat:
sequence:
- service: script.pulsate_sterren
until:
condition: state
entity_id: input_boolean.pulsate_light
state: 'off'
- service: light.turn_on
data:
entity_id: light.kerststerren
transition: >
{{states('input_number.transition_time')}}
brightness: 150
and Tradfri gateway isnt complaining just yet #fingferscrossed for that
and button-card to turn on/off:
but id like the animation to reflect the automation/script, so have a pulsating glow around the card. Could anyone help me out please?
type: custom:button-card
entity: input_boolean.pulsate_light
tooltip: >
[[[ return entity.state == 'on'? 'Fixed lights' :'Breathing lights'; ]]]
show_name: false
size: 90%
aspect_ratio: 1/1
state:
- value: 'on'
icon: mdi:hexagram
styles:
card:
- background-color: ivory
icon:
- color: '#B71515'
- value: 'off'
styles:
card:
- background-color: saddlebrown
icon:
- color: green
icon: mdi:hexagram
custom_fields:
circle: |
[[[
return `
<div class="shadow_circle">
<div class="shadow shadow_green"></div>
<div class="shadow shadow_red"></div>
</div>
`
]]]
styles:
custom_fields:
circle:
- position: absolute
- z-index: 1
- height: inherit
- width: inherit
- top: 0
card:
- border: |
[[[ if (entity.state == 'on') return '2px solid red'; return 'none']]]
icon:
- z-index: 2
- top: 2%
# - color: '#fa3241'
name:
- z-index: 3
card_mod:
style: |
.shadow_circle {
height: 500px;width: 500px;
}
#card {
{% if states(config.entity) == 'on' %}
animation: alert_border 2s infinite !important;
-webkit-animation: alert_border 2s infinite !important;
{% endif %}
;
}
#name {
{% if states(config.entity) == 'on' %}
animation: alert_name 2s infinite !important;
-webkit-animation: alert_name 2s infinite !important;
{% endif %}
;
} #img-cell {
{% if states(config.entity) == 'on' %}
animation: rotate_icon 1s !important;
-webkit-animation: rotate_icon 1s !important;
animation-delay: 1s;
{% endif %}
;
} #img-cell > #icon {
{% if states(config.entity) == 'on' %}
animation: alert_icon 2s infinite ease !important;
-webkit-animation: alert_icon 2s infinite ease !important;
animation-delay: 1s !important;
{% endif %}
;
} .shadow {
background-position: center center;
background-size: 100% 100%;
border-radius: 50%;
bottom: 0px;
left: 0px;
margin: auto;
right: 0px;
top: 0px;
position: absolute;
} .shadow_green {
{% if states(config.entity) == 'on' %}
animation:alert_ani 2s infinite;
-webkit-animation:alert 2s infinite;
animation-delay: -1s;
{% else %}
display: none;
{% endif %}
} .shadow_red {
{% if states(config.entity) == 'on' %}
animation:alert_ani 2s infinite ease-in;
-webkit-animation:alert 2s infinite;
{% else %}
display: none;
{% endif %}
} .shadow_green {
box-shadow: rgb(0, 128, 0 / 20%) 0px 0px 0px 0px, rgb(0, 128, 0 / 20%) 0px 0px 0px 800px inset;
} .shadow_red {
box-shadow: rgb(183, 21, 21 / 20%) 0px 0px 0px 0px, rgb(183, 21, 21 / 20%) 0px 0px 0px 800px inset;
} @keyframes alert {
0% {
width: 0px;
height: 0px
}
50% {
width: inherit;
height: inherit;
box-shadow: 0 0 0 1px rgba(183, 21, 21, 0), 0 0 0 4px rgba(183, 21, 21, 0) inset;
}
51% {
width: 0px;
height: 0px;
}
100% {
width: 0px;
height: 0px;
}
} @keyframes rotate_icon {
0% {
transform: rotate(0);
}
100% {
transform: rotate(3.142rad);
}
}
@keyframes alert_icon {
0% {
top: -2%;
transform: rotate(3.142rad);
color: green;
}
24% {
color: green;
}
40% {
color: green;
}
75% {
color: #B71515;
}
100% {
top: -2%;
transform: rotate(3.142rad);
color: #B71515;
}
} @keyframes alert_name {
0% {
color: #B71515;
}
24% {
color: #B71515;
transform: scale(1.5);
}
55% {
color: #B71515;
transform: scale(1);
}
60% {
color: green;
}
75% {
color: green;
transform: scale(1.5);
}
100% {
color: green;
}
}
@keyframes alert_border {
0% {
border: 2px solid #B71515;
}
55% {
border: 2px solid #B71515;
}
60% {
border: 2px solid green;
}
100% {
border: 2px solid green;
}
}
cleaned that up a bit…:
type: custom:button-card
entity: input_boolean.pulsate_light
variables:
duration: >
[[[ return states['input_number.transition_time'].state; ]]]
tooltip: >
[[[ return entity.state == 'on'? 'Fixed lights' :'Breathing lights'; ]]]
show_name: false
size: 95%
aspect_ratio: 1/1
state:
- value: 'on'
icon: mdi:hexagram
styles:
card:
- background-color: ivory
- animation: >
[[[ return 'glow ' + variables.duration + 's ease ' +
variables.duration + 's infinite normal forwards'; ]]]
- border: '2px dashed #B71515'
icon:
- color: '#B71515'
- animation: rotate_icon 2s, flash_icon 2s 1s infinite ease
- value: 'off'
styles:
card:
- background-color: saddlebrown
- border: 2px solid green
icon:
- color: ivory
icon: mdi:hexagram
extra_styles: |
@keyframes glow {
0% {
box-shadow: 0px 0px 0px 0px #B71515;
}
20% {
box-shadow: 0px 0px 2px 2px green;
}
40% {
box-shadow: 0px 0px 4px 4px green;
}
50% {
box-shadow: 0px 0px 6px 6px green;
}
60% {
box-shadow: 0px 0px 8px 8px #B71515;
}
70% {
box-shadow: 0px 0px 6px 6px green;
}
80% {
box-shadow: 0px 0px 4px 4px green;
}
90% {
box-shadow: 0px 0px 2px 2px #B71515;
}
100% {
box-shadow: 0px 0px 0px 0px #B71515;
}
}
@keyframes flash_icon {
0% {
color: green;
}
24% {
color: green;
}
40% {
color: green;
}
75% {
color: #B71515;
}
100% {
color: #B71515;
}
}
@keyframes rotate_icon {
0% {
transform: rotate(0);
}
100% {
transform: rotate(3.142rad);
}
}
and made the automation a bit more robust:
automation:
- alias: Pulsate lights
id: Pulsate lights
trigger:
platform: state
entity_id: input_boolean.pulsate_light
to: 'on'
action:
- repeat:
sequence:
- service: light.turn_on
data:
entity_id: light.kerststerren
transition: >
{{states('input_number.transition_time')}}
brightness: 50
- delay: >
{{states('input_number.transition_time')}}
- service: light.turn_on
data:
entity_id: light.kerststerren
transition: >
{{states('input_number.transition_time')}}
brightness: 250
- delay: >
{{states('input_number.transition_time')}}
until: >
{{is_state('input_boolean.pulsate_light','off') or
is_state('light.kerststerren','off')}}
- choose:
- conditions:
- condition: state
entity_id: light.kerststerren
state: 'on'
sequence:
service: light.turn_on
data:
entity_id: light.kerststerren
transition: >
{{states('input_number.transition_time')}}
brightness: 150
- alias: Pulsating lights trigger boolean
id: Pulsating lights trigger boolean
trigger:
platform: state
entity_id: light.kerststerren
to: 'off'
condition:
condition: state
entity_id: input_boolean.pulsate_light
state: 'on'
action:
service: input_boolean.turn_off
entity_id: input_boolean.pulsate_light