core
core copied to clipboard
template lights turn_on missing `brightness` parameter
The problem
in documentation: https://www.home-assistant.io/integrations/light.template/#turn_on it is noted May receive variables brightness and/or transition.
with that information i was attempting to implement an integration, but received:
Error rendering data template: UndefinedError: 'brightness' is undefined
I'm expecting it to have the brightness
value as int | None
because turning the light on does restore its brightness
What version of Home Assistant Core has the issue?
core-2023.10.3
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
No response
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
- platform: template
lights:
l_light_1:
unique_id: restll1
friendly_name: "Lounge light 1"
turn_on:
service: rest_command.set_dimmer_level
data:
brightness: "{{ (brightness | int(1)) * 256}}"
id: 17
turn_off:
service: rest_command.set_dimmer_level
data:
brightness: 0
id: 17
set_level:
service: rest_command.set_dimmer_level
data:
brightness: "{{ brightness * 256 }}" # accepts u16 value
id: 17
Anything in the logs that might be useful for us?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 226, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 2012, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2049, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
return await service.entity_service_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
response_data = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 580, in async_handle_light_on_service
await light.async_turn_on(**filter_turn_on_params(light, params))
File "/usr/src/homeassistant/homeassistant/components/template/light.py", line 421, in async_turn_on
await self.async_run_script(
File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 554, in async_run_script
await script.async_run(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 675, in _async_call_service_step
params = service.async_prepare_call_from_config(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 366, in async_prepare_call_from_config
raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'brightness' is undefined
Additional information
No response
Hey there @phracturedblue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template
) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of template
can trigger bot actions by commenting:
-
@home-assistant close
Closes the issue. -
@home-assistant rename Awesome new title
Renames the issue. -
@home-assistant reopen
Reopen the issue. -
@home-assistant unassign template
Removes the current integration label and assignees on the issue, add the integration domain after the command.
(message by CodeOwnersMention)
template documentation template source (message by IssueLinks)
The brightness
is only passed to the turn_on
action of the template if the light.turn_on
service is called with brightness
.
that is correct, but it shouldn't break the template if it doesn't have the brightness value
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
issue persists on Core 2024.1.6
Can confirm. Frustrating to use set_temperature with brightness. Either you ignore the brightness value or break the template if you don't call the service with both values defined. Lights works either way, template should behave equal.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.