Rest command setting Hue sensitivity stopped working

have been using these rest_commands for a long time, and now notice they have stopped being effective, please help me out.

setting the sensitivity on a Hue motion sensor which has url:

url_set_hue_command: http://192.168.1.212/api/dredactedq/{{ type }}/{{ id }}/{{ command }}

the endpoint should be

http://192.168.1.212/api/dredactedq/sensors/22/config {{sensitivity:2}}

I use a rest_command:

rest_command:
  set_hue_command: #not named sensitivy because the command can be used to set other entities/attributes also
    url: !secret url_set_hue_command
    method: put
    payload: '{{data}}'

and script:

script:
  set_hue_sensitivity:
    alias: Set Hue sensitivity
    mode: restart
    icon: mdi:cog
    sequence:
      service: rest_command.set_hue_command
      data:
        command: config
        type: sensors
        data: >
          {% set mapper =
            {'Low':'0',
             'Medium':'1',
             'High':'2'} %}
          {% set state = states('input_select.select_hue_sensitivity') %}
          {% set sensitivity = mapper[state] if state in mapper %}
          {"sensitivity": {{sensitivity}} }
        id: >
          {% set mapper =
            {'Laundry':'22',
             'Dining table':'52',
             'Auditorium':'44',
             'Attic':'12'} %}
          {% set state = states('input_select.select_hue_motion_sensor') %}
          {% set id = mapper[state] if state in mapper %}
          {{id}}

and

  set_hue_threshold:
    alias: Set Hue threshold
    mode: restart
    icon: mdi:cog
    sequence:
      service: rest_command.set_hue_command
      data:
        command: config
        type: sensors
        data: >
          {"tholddark": {{states('input_number.slide_hue_threshold')|int}} }
        id: >
          {% set mapper =
            {'Laundry':'25',
             'Dining table':'53',
             'Auditorium':'45',
             'Attic':'13'} %}
          {% set state = states('input_select.select_hue_motion_sensor') %}
          {% set id = mapper[state] if state in mapper %}
          {{id}}

the template in the script is 100% correct and renders an ‘id’ and ‘sensitivity’ /‘threshold’ which are passed to the script.

in the CLIP tool:


I have set script logging to debug, and see the scripts being executed, without changing the sensitivity at all. No errors.

I also have a direct script like:

  set_hue_sensitivity_direct:
    alias: Set Hue sensitivity direct
    mode: restart
    sequence:
      service: rest_command.set_hue_command
      data:
        command: config
        type: sensors
        data: >
          {"sensitivity": {{sensitivity}}}
        id: >
          {{id}}

which I can call in automations or scripts, and that too doesn’t work any longer.

strangely enough, I use a likewise script to change the rules (time settings) on a sensor

  set_hue_rule:
    url: !secret url_set_hue_rule
    method: put
    payload: '{{data}}'

and a rather complex set of scripts (we need to set 4 id’s) and that works just fine. So I know the address is correct. And the HUE Hub is working as it should too. As is shown in the clip tool too of course.

Has something changed lately in the rest_commands I need to adapt? I did check if the change from data_template: to data: causes the issue, but restoring data_template: still doesnt work.

Please have a look. Thanks!

Here’s what’s working for me (hasn’t changed in 1.5 years).

Hi Mariusthvdb,

Yes it still works fine for me. I believe I’m on the latest Hue v2 hub firmware version. Home Assistant wise I’m on 0.115.6.

  hue_command:
    url: 'http://HUE_BRIDGE_IP/api/API_KEY/{{ type }}/{{ id }}/{{ command }}'
    method: put
    payload: '{{ data }}'

And as part of an automation:

  action:
  - data:
      command: config
      data: '{ "sensitivity":1 }'
      id: 7
      type: sensors
    service: rest_command.hue_command

thanks!
and how odd, because as I see it that’s the exact code I still use…
only thing different is I am on 116.4

so maybe a rest_command change after all, or something in the scripting I miss maybe.

As you can see Ive manually change it in the CLIP and that works, so it must be the HA interfacing or formatting

rebuilding them all, made me find it: it was the double quoting I had glob_changed into single quotes… the data fields need the double quotes.

(tbh, dont understand why, when Iposted the first one above holding the double quotes, it didn’t work) Probably I posted from one of my backups, and not the current version…which was:

  set_hue_sensitivity:
    alias: Set Hue Indoors sensitivity
    mode: restart
    icon: mdi:cog
    sequence:
      service: rest_command.set_hue_command
      data:
        command: config
        type: sensors
        data: >
          {% set mapper =
            {'Low':'0',
             'Medium':'1',
             'High':'2'} %}
          {% set state = states('input_select.select_hue_sensitivity') %}
          {% set sensitivity = mapper[state] if state in mapper %}
          {'sensitivity': {{sensitivity}} }    # <---- incorrect single quotes here!!
        id: >
          {% set mapper =
            {'Laundry':'22',
             'Dining table':'52',
             'Auditorium':'44',
             'Attic':'12'} %}
          {% set state = states('input_select.select_hue_motion_sensor') %}
          {% set id = mapper[state] if state in mapper %}
          {{id}}

sorry for the confusion.

Thanks, so relieved this still works just fine…(again) :wink:

as an update to our recent discussion, HA 117 breaks this setup, because the python type in the templates isnt correct any longer.
Did yiuo already have a chance to check and change that. Might be a bug in the new template engine, (there’s an issue on the GitHub on that), but maybe we can mitigate it in the yaml we use?

this is the error:

TypeError: encoding without a string argument

use

homeassistant:
legacy_templates: true

to keep using them as they are, until things are fixed.

edit

Petro made some very relevant remarks here here:

thought it fixed it, but unfortunately not there yet.