Template light limit maximum and minimum brightness of light

I had a hard time believing it too. Its the only light switches I have with this issue. I have told them about it, and they said they are looking into it, but I am not too confident they will do much about it.

Seems nuts to me as making light templates is a bit of a pain to get going, and while zwave can take a little more technical knowledge, this seems to be totally unneccessary, as I can’t imagine most folks wouldn’t want the recalculation to be automatic.

I have this issue with all my zooz dimmers, but not my inovelli dimmer. I have only used zwavejs2mqtt and have it on the latest version.

Are you sure there isn’t a parameter in the device to change what 100% and 0% means? Inovelli has this.

Yep, there is. Parameter 10 and parameter 11.

Minimum and Maximum Brightness

Parameter 10: Set the minimum
brightness level (in %) for your
dimmer. You won’t be able to dim the
light below the set value.
Values: 1 – 99 (%). Default set to 1.
Size: 1 byte dec.

Parameter 11: Set the maximum
brightness level (in %) for your
dimmer. You won’t be able to add
brightness to the light beyond the set
value. Note: if Parameter 12 is set to
value 0, Parameter 11 is automatically
disabled.
Values: 1 – 99 (%). Default set to 99.
Size: 1 byte dec.

No that is there. But in Home Assistant, it doesnt remap the range. So if you set those parameters (which I do) to min: 30 and max 70, the range in HA will not change, it just wont go lower than 30 or higher than 70 on the existing range. If you want a traditional 0-100 scale, you need to make a light template.

Well yeah, that mapping should be done on the command class like inovelli does. Those aren’t standard parameters so zwavejs won’t know how to use the to apply to a brightness. You should contact Zooz about this.

1 Like

Good to know. Not sure what command class is, but I will send zooz a note about this. I hope its a relatively easy fix for them to implement. I can’t imagine a reason on why this would be better left to the end user to figure out.

I try this template but not pass…

light:
- platform: template
    lights:
      l_1:
        value_template: >
          {% if is_state('light.0xa4c13830306c281a_l1', 'on') %}
            on
          {% elif is_state('light.0xa4c13830306c281a_l1', 'off') %}
            off
          {% else %}
            unknown
          {% endif %}
        turn_on:
          service: light.turn_on
          data:
            entity_id: light.0xa4c13830306c281a_l1
        turn_off:
          service: light.turn_off
          data:
            entity_id: light.0xa4c13830306c281a_l1
        level_template: >
          {% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %}
          {{ (1.783 * b - 199.7) | int }}
        set_level:
          service: light.turn_on
          data_template:
            entity_id: light.0xa4c13830306c281a_l1
            brightness: "{{ ((brightness + 199.7) / 1.783) | int }}"

                    Error loading /config/configuration.yaml: mapping values are not allowed here
  in "/config/configuration.yaml", line 18, column 11

Where am I wrong?

needs to be

light:
  - platform: template
    lights:

thanks so much for this

I have some errors in log


2022-11-29 18:34:57.812 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1701, in forgiving_float_filter
    return float(value)
TypeError: float() argument must be a string or a real number, not 'NoneType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 420, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1933, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1704, in forgiving_float_filter
    raise_no_default("float", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1402, in raise_no_default
    raise ValueError(
ValueError: Template error: float got invalid input 'None' when rendering template '{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}' but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 536, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 422, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'None' when rendering template '{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}' but no default was specified
2022-11-29 18:34:57.834 ERROR (MainThread) [homeassistant.components.template.light] Received invalid light is_on state: unknown for entity light.faretti_sala_1. Expected: on, off, true, false
2022-11-29 18:34:57.847 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}' but no default was specified') while processing template 'Template("{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}")' for attribute '_brightness' in entity 'light.faretti_sala_1'
2022-11-29 18:35:41.649 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}' but no default was specified') while processing template 'Template("{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}")' for attribute '_brightness' in entity 'light.faretti_sala_1'
2022-11-29 18:36:22.403 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}' but no default was specified') while processing template 'Template("{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}")' for attribute '_brightness' in entity 'light.faretti_sala_1'
2022-11-29 18:36:23.939 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}' but no default was specified') while processing template 'Template("{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}")' for attribute '_brightness' in entity 'light.faretti_sala_1'
2022-11-29 18:37:05.497 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}' but no default was specified') while processing template 'Template("{% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float %} {{ (1.783 * b - 199.7) | int }}")' for attribute '_brightness' in entity 'light.faretti_sala_1'

Those errors are unrelated to what you’re talking about in this thread.

Sorry, wrong post. Thought you were someone else. You’re missing defaults for your float filters.

what are the default parameters for float filter?

there is none, you need to provide it, that’s what your error is saying

ok I have modified to this, no error for float but I have this error.

I calculated the linear regression from 112 to 254, I use this tool linear regression

2022-11-30 16:19:07.851 ERROR (MainThread) [homeassistant.components.template.light] Received invalid light is_on state: unknown for entity light.salon_1. Expected: on, off, true, false

2022-11-30 16:19:07.862 ERROR (MainThread) [homeassistant.components.template.light] Received invalid brightness : -199 for entity light.salon_1. Expected: 0-255
  - platform: template
    lights:
      salon_1:
        value_template: >-
          {% if is_state('light.0xa4c13830306c281a_l1', 'on') %}
            on
          {% elif is_state('light.0xa4c13830306c281a_l1', 'off') %}
            off
          {% else %}
            unknown
          {% endif %}
        turn_on:
          service: light.turn_on
          data:
            entity_id: light.0xa4c13830306c281a_l1
        turn_off:
          service: light.turn_off
          data:
            entity_id: light.0xa4c13830306c281a_l1
        level_template: >
          {% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float(0) %}
          {{ (1.7958 * b - 201.1268) | int }}
        set_level:
          service: light.turn_on
          data_template:
            entity_id: light.0xa4c13830306c281a_l1
            brightness: "{{ ((brightness + 1.7958) / 201.1268) | int }}"

your calc isn’t correct, it’s feeding -199 to brightness

I use your code 1:1 and result same error…

2022-11-30 17:22:31.268 ERROR (MainThread) [homeassistant.components.template.light] Received invalid brightness : -218 for entity light.salon_1. Expected: 0-255

Your code (I have add to float (0)):

        level_template: >
          {% set b = state_attr('light.0xa4c13830306c281a_l1', 'brightness') | float(0) %}
          {{ (2.85714286 * b - 218.57142857) | int }}
        set_level:
          service: light.turn_on
          data_template:
            entity_id: light.0xa4c13830306c281a_l1
            brightness: "{{ ((brightness + 218.57142857) / 2.85714286) | int }}"

it’s not my code, i already explained to the guy above

Is this equation is not yours?

the hardware accept scale to 0-255, what else should I know?

No, it’s not. I just helped the guy generate the equation to use by showing him what he can do. It’s up to you to feed it the correct values and generate the proper equation for your light. If you’re getting a negative number, you got to come up with the correct equation that works with your light.