Numer.set_value in automation

Hi All,

I used always the installed integration for FKB. Now using the internal one of HA itself.
Before I was able to control brightness to set the light entity of FKB. Now it’s a number entity.

I tried to change the automation as follow but get a error:

2023-04-14 20:42:06.211 ERROR (MainThread) [homeassistant.components.automation.control_fkb_with_scenes] Control - FKB with scenes: Error executing script. Invalid data for call_service at pos 2: expected float for dictionary value @ data['value']
2023-04-14 20:42:06.223 ERROR (MainThread) [homeassistant.components.automation.control_fkb_with_scenes] Error while executing automation automation.control_fkb_with_scenes: expected float for dictionary value @ data['value']

there must be somewhere a float() added. But don’t know how to solve this.

    - service: number.set_value
      target:
        entity_id: number.galaxy_tab_a_screen_brightness
      data:
        value: >-
          {% if is_state('input_select.helpers_scenes', 'scene evening') %} 
            {{ 28 if is_state('group.family', 'off') else 205 }}
          {% elif is_state('input_select.helpers_scenes', 'scene daytime') %} 
            {{ 28 if is_state('group.family', 'off') else 205 }}
              {% if is_state('input_select.helpers_scenes', 'scene appletv') %} 
                28
              {% elif is_state('input_select.helpers_scenes', 'scene dinner') %} 
                205
              {% elif is_state('input_select.helpers_scenes', 'scene tv') %} 
                205
              {% elif is_state('input_select.helpers_scenes', 'scene nintendo') %} 
                28
              {% elif is_state('input_select.helpers_scenes', 'scene kodi') %} 
                28
              {% elif is_state('input_select.helpers_scenes', 'scene goodnight') %} 
                13
              {% else %} 
                205
              {% endif %} | float(0)
          {% endif %}

converted the percentage to the 1-255 values already as you see in automation.

You are quoti g the numbers so they are actually strings not numbers. Remove your quotes

First tried them without quotes didn’t work. Same error. So I tried with quotes.
Updated the script in first post. So this issue is gone. But had same errors.

That isn’t doing what you think it is. It is instead turning the value into the string:

205 | float(0)

So I have to remove that part? Because I also tried it without already.

Created a momentary switch. So was able to test with on and of state. Below is working. Now will check the automation itself. The way itself is ok to change brightness.

    - service: number.set_value
      target:
        entity_id: number.galaxy_tab_a_screen_brightness
      data:
        value: >-
          {% if is_state('switch.momentary_for_testing', 'on') %} 
            255
          {% elif is_state('switch.momentary_for_testing', 'off') %} 
            28
          {% endif %}

I get 2 values in dev tool. That gives the error I guess. So remove the last {% else %} then it must be ok

Your nested if block from appletv onwards is the problem. You need to continue with top-level elif blocks (and lose the float).

If you’re on the daytime scene, you get 28 or 205 from the fourth line of the template as well as the default 205 from the else of the nested block.

1 Like

First part make sense… Now is see it also… stupid why I did this nested if…
But then I can shorten the whole part:

          {% if is_state('group.family', 'off') %} 
            28
          {% elif states('input_select.helpers_scenes') in ['scene appletv', 'scene nintendo', 'scene kodi'] %}
            28
          {% elif is_state('input_select.helpers_scenes', 'scene goodnight') %} 
            13
          {% else %} 
            205
          {% endif %}
1 Like

now scripts follow the right path for exceptions first, otherwise always 205.