You absolute star!
Thankyou everybody!
You absolute star!
Thankyou everybody!
did something change with this im getting an error.
17-03-01 15:13:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=139996349380648-5>
17-03-01 15:13:20 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=139996349380648-6, domain=automation, service_data=entity_id=automation.increase_living_room_lights, service=trigger>
17-03-01 15:13:20 INFO (MainThread) [homeassistant.components.automation] Executing increase living room lights
17-03-01 15:13:20 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: domain=automation, name=increase living room lights, message=has been triggered, entity_id=automation.increase_living_room_lights>
17-03-01 15:13:20 INFO (MainThread) [homeassistant.helpers.script] Script increase living room lights: Executing step call service
17-03-01 15:13:20 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/template.py”, line 99, in async_render
return self._compiled.render(kwargs).strip()
File “/usr/local/lib/python3.5/dist-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/usr/local/lib/python3.5/dist-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/usr/local/lib/python3.5/dist-packages/jinja2/_compat.py”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
jinja2.exceptions.UndefinedError: ‘mappingproxy object’ has no attribute ‘brightness’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/components/automation/init.py”, line 294, in async_trigger
yield from self._async_action(self.entity_id, variables)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/components/automation/init.py”, line 376, in action
yield from script_obj.async_run(variables)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/script.py”, line 151, in async_run
yield from self._async_call_service(action, variables)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/script.py”, line 181, in _async_call_service
self.hass, action, True, variables, validate_config=False)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/service.py”, line 88, in async_call_from_config
config[CONF_SERVICE_DATA_TEMPLATE]))
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/service.py”, line 84, in _data_template_creator
for key, item in value.items()}
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/service.py”, line 84, in
for key, item in value.items()}
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/service.py”, line 86, in _data_template_creator
return value.async_render(variables)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/template.py”, line 101, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: ‘mappingproxy object’ has no attribute ‘brightness’
- alias: 'increase living room lights'
trigger:
platform: zone
entity_id: device_tracker.benjimatt_benjimatt
zone: zone.work
event: leave
action:
- service: light.turn_on
entity_id: light.living_room
data_template:
brightness: '{{ states.light.living_room.attributes.brightness + 10 }}'
It seems right but I am still getting an error. I really dont care about the event because im going to change that. I really just need the script.
I had a similar problem that gave the same error and it turned out that the light had to be switch on first. I imagine that this is so that the state can be received. I ended up having another service that turns it on first.
Can someone help me implement this into a variable? I received the following error when I tried:
homeassistant found character ‘%’ that cannot start any token
I think it’s something to do with the line below line as it works if I simply put in a number. Just can’t figure what the solution is.
{%- set state = states.light.bedroom.attributes.brightness + 10 -%}
Config code:
- alias: "Bedroom Brightness"
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_xxxxxxxxxxxxxx
action_type: rotate
action:
- service: light.turn_on
entity_id: light.bedroom
data_template:
transition: 1
brightness: >
{% set state = (trigger.event.data.action_value|float) -%}
{%- if state > 0 -%}
{%- set state = states.light.bedroom.attributes.brightness + 10 -%}
{%- elif state < 0 -%}
{%- set state = states.light.bedroom.attributes.brightness - 10 -%}
{%- endif %}
{{ state }}
that was it. I need to read a little closer next time lol
Hi there, can some one help me with this automation? I can’t really figure out
- alias: Comodino Andrea Dim+
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00012641b4
click_type: hold
action:
service: light.turn_on
entity_id: light.comodino_andrea
data_template:
brightness: '{{states.light.comodino_andrea.attributes.brightness + 10}}'
Try to change this line to:
brightness: ‘{{states.light.comodino_andrea.attributes.brightness|int + 10}}’
Thanks mate this solved my issue
Do you know if there is a way for dim -
I’m trying this way but it doesn’t work… maybe is the service? light.turn_on?
action:
data_template:
brightness: '{{states.light.comodino_andrea.attributes.brightness|int - 25}}'
entity_id: light.comodino_andrea
service: light.turn_on
Hello @MastroPino, I would try something like this:
action:
- service: light.turn_on
entity_id: light.comodino_andrea
data_template:
brightness: '{{states.light.comodino_andrea.attributes.brightness|int - 25}}'
Make sure the indentation is correct. It looks wrong the way you set it up. Check also the logs for error when you reload. The way I have set up + and - dim looks like this:
- alias: Lysere på Toalettet +10%
trigger:
- platform: event
event_type: zwave.scene_activated
event_data:
entity_id: zwave.bryter_toalett_overetasje
scene_id: 23
action:
- service: light.turn_on
entity_id: light.dimmer_toalett_overetasje_level
data_template:
brightness: >
{% set suggested = states.light.dimmer_toalett_overetasje_level.attributes.brightness|int + 31 %}
{% if suggested < 200 %}
{{ suggested }}
{% else %}
200
{% endif %}
- alias: Mørkere på Toalettet -10%
trigger:
- platform: event
event_type: zwave.scene_activated
event_data:
entity_id: zwave.bryter_toalett_overetasje
scene_id: 40
action:
- service: light.turn_on
entity_id: light.dimmer_toalett_overetasje_level
data_template:
brightness: >
{% set suggested = states.light.dimmer_toalett_overetasje_level.attributes.brightness|int - 31 %}
{% if suggested > 25 %}
{{ suggested }}
{% else %}
25
{% endif %}
The if settings are just to define a minimum and maximum dim. This way it never gets pitch black. The last steps on the dimmer above 200 makes no difference at my house so I define 200 as max.
Good luck
do you guys have an easy, nice, clean way of increase/decrease stepping without going above 100% or 255 and below 0?
brightness: ‘{{states.light.comodino_andrea.attributes.brightness|int + 10}}’
brightness: >
{% set suggested = states.light.dimmer_toalett_overetasje_level.attributes.brightness|int - 31 %}
{% if suggested > 25 %}
{{ suggested }}
{% else %}
25
{% endif %}
This is doing exactly that. This example is decrease. It first takes the current value from the attribute, detracts 31, checks if the proposed value is above 25, if yes, use the proposed. If no then use 25. The same logic for increase is used in in the example from my previous post. You can change the 25s to 0s for your example. Or 255 for increase (remember to change - to + and > to <
that is true… overlooked this one
Thanks
Thanks mate, you save me
So i have been struggling with this case my self from 2 days now.
I have read and tested deferent things around the forum and reddit and did not find working solution. Obviously I am missing something somewhere.
I am trying to do a simple automation.
If i press a button (Ikea E1524 remote connected via Zigbee2MQTT) i want to increase or decrease the brightness of a light. Ether by percent or value. The simple on/off automation works with no problems.
I have no Idea where to put the pointed solution
data_template:
brightness: '{{states.light.light_name.attributes.brightness + 10}}'
CAN somebody paste/publish a complete working code from automation.yaml for reference.
Thank you.
@TGR I got one just build it today with the same config as you have.
Zigbee2MQTT configuration (with latest release 1.21 and firmware, you must upgrade for use with the E1524 button).
Ikea TRADFRI E1524 button
Ikea TRADFRI LED bulb E27 LED1623G12 (light)
My dimmer E1524 button is showing as 0xd0cf5efffe276402_action
and the bulb has multiple entities 2 of them has a attribute with brightness in it. I renamed the entity within zigbee2mqtt but that’s somehow not done for al the HASS entries The bulb has this address x000b57fffe307869
and in HASS this entities:
So first I tried to use states.sensor.light.0x000b57fffe307869_light .attributes.brightness
but that failed with the validation. But it works with states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness
So this is the complete example script:
- alias: ZB badroom ON/OFF
trigger:
platform: state
entity_id: sensor.0xd0cf5efffe276402_action
to: 'toggle'
action:
entity_id: light.0x000b57fffe307869_light
service: light.toggle
- alias: ZB badroom - dimmer UP
trigger:
platform: state
entity_id: sensor.0xd0cf5efffe276402_action
to: 'brightness_up_click'
action:
- service: light.turn_on
entity_id: light.0x000b57fffe307869_light
data_template:
brightness: >
{% set suggested = states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness|int + 31 %}
{% if suggested < 200 %}
{{ suggested }}
{% else %}
200
{% endif %}
- alias: ZB badroom - dimmer DOWN
trigger:
platform: state
entity_id: sensor.0xd0cf5efffe276402_action
to: 'brightness_down_click'
action:
- service: light.turn_on
entity_id: light.0x000b57fffe307869_light
data_template:
brightness: >
{% set suggested = states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness|int - 31 %}
{% if suggested > 25 %}
{{ suggested }}
{% else %}
25
{% endif %}
So you can use this for reference, just put your own entity ID’s in it.
And the Ikea E1524 dimmer is quite fancy, it has multiple states when you press a button. short and long presses gives different states:
“toggle”
“brightness_up_hold”
“brightness_up_release”
“brightness_up_click”
“brightness_down_click”
“brightness_down_release”
“brightness_down_click”
“arrow_right_click”
“arrow_left_click”
Next step is to get this states working in a script so that way when I long press the brightness button the bulb will continue to in/decrease the levels.
I do no get only this:
states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness
My light does not support such state.sensor
My light is Philips Xiaomi wifi
my brightness is set in an other sensor than the switch for the light ON/OFF.
on/off is in light.0x000b57fffe307869_light
and brightness is in sensor.zb_ikea_lamp_badkamer_linkquality
so according to https://www.home-assistant.io/components/light.xiaomi_miio/ you can set brightness. so look for it in your entity list.
OK, I need help then in other direction then.
How can I read/use the current brightness of switched on light as condition?
What condition TYPE should I use: numeric state, state, or template?
I did try state, but all I tried to put in numeric state does not work.
Examples or suggestions anyone?
I have somewhat the same configuration as @alco has above, but I don’t use the discovery mode from zigbee2mqtt. I define all of my devices (sensors) manually in yaml.
An example with the IKEA Tradfri LED bulb E27 600 lumen dimmable, color, opal white light (LED1624G9):
light:
- platform: mqtt
name: living_room
state_topic: 'zigbee2mqtt/light_living_room'
command_topic: 'zigbee2mqtt/light_living_room/set'
availability_topic: 'zigbee2mqtt/bridge/state'
json_attributes_topic: 'zigbee2mqtt/light_living_room'
brightness: true
xy: true
schema: json
Notice the fact that I’m using json_attributes_topic
in there, which adds all of the attributes (which are available in the zigbee2mqtt JSON) to the light sensor in Home Assistant.
So, by adding that I can simply call states.light.living_room.attributes.brightness
or state_attr('light.living_room', 'brightness')
to retrieve its brightness, whichever you prefer.
And this is my automation which is based on percentages:
automation:
- alias: remote_brightness_up
initial_state: true
trigger:
platform: mqtt
topic: 'zigbee2mqtt/remote_living_room'
condition:
condition: template
value_template: "{{ trigger.payload_json.action == 'brightness_up_click' }}"
action:
service: light.turn_on
data_template:
entity_id: light.living_room
brightness_pct: >
{% set brightness_pct = (state_attr('light.living_room', 'brightness') / 2.55) | int | round(0) %}
{% set new_brightness = brightness_pct + 10 %}
{% if new_brightness < 100 %}
{{ new_brightness }}
{% else %}
100
{% endif %}
In this automation you see zigbee2mqtt/remote_living_room
as the topic
. remote_living_room
is the friendly_name
of my IKEA Tradfri remote control in the zigbee2mqtt configuration itself.
@alco, did you ever figure out how to use the long press to continuously brighten/dim? If so, I’d be very grateful to see the solution!