Hi,
Looking for a script/automation that will help me with this. maybe I need to look at templates? anyone done anything similar?
When I button is pressed i would like my hue light to increase the brightness by 10% and the reverse if Another button is pressed?
So Always append 10% to previous value or remove 10% depending on with button is pressed.
keithh666
(Keith Hull)
January 28, 2018, 5:38pm
2
The action would be something like this,
action:
- service: light.turn_on
data_template:
entity_id: light.zw_uplight_dimmer_level
brightness: >-
{%if trigger.event.data.action_value | float > 0 %}
{{ states.light.zw_uplight_dimmer_level.attributes.brightness | int + 50 }}
{% else %}
{{ states.light.zw_uplight_dimmer_level.attributes.brightness | int - 50 }}
{% endif %}
Iāve done exactly this with my Lifx lights and a script.
Increase brightness:
livinglightup:
alias: Living Light Up
sequence:
service: light.turn_on
data_template:
entity_id: light.living
transition: '1'
brightness: >
{%- if states.light.living.attributes.brightness <= 25 %}
51
{% elif states.light.living.attributes.brightness <= 51 %}
77
{% elif states.light.living.attributes.brightness <= 77 %}
102
{% elif states.light.living.attributes.brightness <= 102 %}
128
{% elif states.light.living.attributes.brightness <= 128 %}
153
{% elif states.light.living.attributes.brightness <= 153 %}
179
{% elif states.light.living.attributes.brightness <= 179 %}
205
{% elif states.light.living.attributes.brightness <= 205 %}
230
{% elif states.light.living.attributes.brightness <= 230 %}
255
{% endif %}
Decrease brightness:
livinglightdown:
alias: Living Light Down
sequence:
service: light.turn_on
data_template:
entity_id: light.living
transition: '1'
brightness: >
{%- if states.light.living.attributes.brightness <= 51 %}
25
{% elif states.light.living.attributes.brightness <= 77 %}
51
{% elif states.light.living.attributes.brightness <= 102 %}
77
{% elif states.light.living.attributes.brightness <= 128 %}
102
{% elif states.light.living.attributes.brightness <= 153 %}
128
{% elif states.light.living.attributes.brightness <= 179 %}
153
{% elif states.light.living.attributes.brightness <= 205 %}
179
{% elif states.light.living.attributes.brightness <= 230 %}
205
{% elif states.light.living.attributes.brightness <= 255 %}
230
{% endif %}
The only thing I havenāt incorporated is to go from 0% (off) to 10% and vice versa.
Hope this helps
2 Likes
Thanks Keithh666 and Icaman004,
I question Icamann004, canāt you just use on line for this like keithh666 example or Iām missing something here?
I havenāt tried that method so canāt say unfortunately. I created this script to use as a brightness button in HADashboard.
petro
(Petro)
January 30, 2018, 3:39pm
6
For 10% using icaman004ās automation. Works at any brightness. Same principle as Keithh666ās but used in a script without requiring a trigger value.
livinglightdown:
alias: Living Light Down
sequence:
service: light.turn_on
data_template:
entity_id: light.living
transition: '1'
brightness: >
{% set n = states.light.living.attributes.brightness + 25 %}
{% if n > 255 %}
255
{% else %}
{{ n }}
{% endif %}
2 Likes
wdh
December 8, 2018, 4:11pm
7
Iāve been trying to use this one and it is working at any brightness, but not when the light is completely switched off. I tried to add an additional if-statement to first check for the state of the light, but cannot get it done. Anyone that can add that to the script?
Thanks for posting this! Just used it to write a script for my Ikea Tradfri remote and a group of lights.
Hereās what it ended up looking like for Decreasing brightness
Edit: I kept reading and testing and this looks better.
'1234567890':
alias: Kitchen Brightness Increase Button
sequence:
service: light.turn_on
data_template:
entity_id: light.kitchen_lights
transition: '1'
brightness: >
{% if not state_attr('light.kitchen_lights', 'brightness') == None %}
{% set n = state_attr('light.kitchen_lights', 'brightness') + 25 %}
{% if n > 255 %}
255
{% else %}
{{ n }}
{% endif %}
{% else %}
25
{% endif %}
'1234567891':
alias: Kitchen Brightness Decrease Button
sequence:
service: light.turn_on
data_template:
entity_id: light.kitchen_lights
transition: '1'
brightness: >
{% if not state_attr('light.kitchen_lights', 'brightness') == None %}
{% set n = state_attr('light.kitchen_lights', 'brightness') - 25 %}
{% if n > 255 %}
255
{% else %}
{{ n }}
{% endif %}
{% else %}
0
{% endif %}
1 Like
steeveno
(Stefan)
September 19, 2020, 9:36pm
9
Hi, I am trying to achieve this as well with my yeelight, but it just wonāt work.
This is my yaml code at the āactionā part:
data_template:
brightness: >
{% set n = states.light.living_room.attributes.brightness + 25 %}
{% if n > 255 %}
255
{% else %}
{{ n }}
{% endif %}
entity_id: light.living_room
transition: '1'
service: yeelight.set_color_temp_scene
Can you tell me what I am doing wrong?
Thanks,
Steeveno
1 Like
Mutt
(Muttley)
September 19, 2020, 9:45pm
10
You are adding 25 to a string.
Try : -
{% set n = state_attr('light.living_room', 'brightness') | int + 25 %}
petro
(Petro)
September 22, 2020, 12:57pm
11
brightness isnāt a string, itās an int. attributes can be any type and the |int
is not needed.
@steeveno service: yeelight.set_color_temp_scene
is not the same as light.turn_on.
Your issue is that transition is not supported by yeelight.set_color_temp_scene
. The docs say that only entity_id, kelvin, and brightness are allowed.
1 Like
Mutt
(Muttley)
September 22, 2020, 1:06pm
12
Thanks for the correction but as there should be no problem with casting an int to an int and I couldnāt test (I was on my phone) I thought it a fair bet.
Always willing to be corrected
Dolores
September 22, 2020, 1:13pm
13
I would just use light.turn_on
with the newish brightness_step_pct:
used for brightness.
@petro I assume that this can still be used, because presumably home assistant is actually converting this to a brightness instead of brightness step before passing it to the component?
petro
(Petro)
September 22, 2020, 1:17pm
14
The brightness template can still be used anywhere that accepts brightness but Iām assuming his issues are from the āextra key: transitionā.
Dolores
September 22, 2020, 4:21pm
15
I donāt mean the brightness template, I mean the brightness_pct
option.
petro
(Petro)
September 22, 2020, 4:22pm
16
Yeah that should work for brightness_pct but the math will be different:
brightness_pct: >
{% set n = states.light.living_room.attributes.brightness + 10 %}
{% if n > 100 %}
100
{% else %}
{{ n }}
{% endif %}
danstreeter
(Dan Streeter)
October 12, 2021, 10:00am
17
I know this post is quite old, but I wanted to do the same thing here and found that my UI in the services developer tool offered brigness_step
which takes a -/+ integer of the amount to change by.
(Running Home Assistant Container 2021.8.7)
I now have an automation that when I turn a Aqara cube right, it increases my light by 50 (~1/5th of 255) and whe turned left, decreases by 50.
Acts like a dimmer but without being fixed to a wall or anything - currently being used on the bedside table for the bedside lights which are both zibgee bulbs using Zigbee2MQTT.
The service code which is eventually used by the automation GUI is as follows:
- service: light.turn_on
target:
entity_id: light.bedside_lamp
data:
brightness_step: +50
and obviously a -50 step for decrease
3 Likes