Help with deconz_configure and variables

Hi, I’m trying to get variables/parameters in to the deconz_configure service in the data-part. This however gives an error:

The test-code:

- service: deconz.configure
  data_template:
    entity: light.mini_lampen
    field: "/action"
    data:
      "on":true
      "bri":{{ state_attr('variable.verlichting_mini_waarden', 'doelhelderheid')}}
      "ct":{{ state_attr('variable.verlichting_mini_waarden', 'doelkleurtemperatuur')}}

In the developer-options, the code translates into:
service: deconz.configure

data_template:
  entity: light.mini_lampen
  field: "/action"
  data:
    "on":true
    "bri":100
    "ct":300

The error thrown is:

2021-01-11 10:03:32 ERROR (SyncWorker_30) [homeassistant.util.yaml.loader] while parsing a flow mapping
  in "/config/automations/lights/mini_afstandsbediening.yaml", line 86, column 24
expected ',' or '}', but got '<scalar>'
  in "/config/automations/lights/mini_afstandsbediening.yaml", line 86, column 90

From what I can tell, it isn’t parsing the variables, but sending the raw data directly. Any suggestions/help are more than welcome :slight_smile:

You forgot the quotes around the template, try this:

- service: deconz.configure
  data:
    entity: light.mini_lampen
    field: "/action"
    data:
      on: true
      bri: "{{ state_attr('variable.verlichting_mini_waarden', 'doelhelderheid') }}"
      ct: "{{ state_attr('variable.verlichting_mini_waarden', 'doelkleurtemperatuur') }}"

But why do you need the deconz configure service for this, instead of setting brightness and color temperature through a normal light turn on service call?

Hi,
Thank you for your reply.
It parses okay now, but I get an error when it is executed:

2021-01-11 13:21:12 ERROR (MainThread) [homeassistant.components.automation.mini_lampen] Mini lampen: Choose at step 1: choice 1: Error executing script. Invalid data for call_service at pos 1: expected dict for dictionary value @ data['data']
2021-01-11 13:21:12 ERROR (MainThread) [homeassistant.components.automation.mini_lampen] Mini lampen: Error executing script. Invalid data for choose at pos 1: expected dict for dictionary value @ data['data']
2021-01-11 13:21:12 ERROR (MainThread) [homeassistant.components.automation.mini_lampen] While executing automation automation.mini_lampen
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 404, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 596, in _async_choose_step
    await self._async_run_script(script)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 670, in _async_run_script
    await self._async_run_long_action(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 419, in _async_run_long_action
    long_task.result()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1399, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 218, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 341, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 337, in _exec
    v = func(v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: expected dict for dictionary value @ data['data']

I am migrating towards the deconz.configure service because that service provides a nicer flow towards new values (in transition) for some reason. So for example when my colour temperature is moving from ‘200’ to 400’ in 5 minutes at certain sun-events. (using the light.on service it sometimes ‘stutters’ towards the new values over time. My tests with using the deconz.configure give better results)

Did you try without the on: true line? The deconz configure swrvice call works fine for me like this, with different parameters.

I get the same error without the on: true line. I also tried with on: “true” (against better judgement), but that also provides nothing.

Any other ideas? :slight_smile:

Can you show your current code please?

Hi,

This is the single automation I’m currently using for the buttons in one room.
I have a Gira batteryless switch. It has four buttons. The left buttons and right buttons are currently the same for the room I’m testing in.
The automation is currently based on sequences (copy-pasted it from the forum somewhere), which isn’t strictly necessary of course, since only one action is there.

The buttons and their function:
1xxx top left switch
2xxx bottom left switch
3xxx top right switch
4xxx bottom right switch

x002 button released after a short press
x001 button being pressed for a long time
x003 button released after being pressed for a long time

The code

- id: 'mini_lampen'
  alias: 'Mini lampen'
  initial_state: 'on'
  mode: 'restart'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: mini_wandschakelaar
  action:
    - choose:
      # Lampen aan
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event in ( 1002, 3002 ) }}"
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: light.mini_lampen
              brightness: '{{ state_attr(''variable.verlichting_mini_waarden'', ''doelhelderheid'')}}'
              color_temp: '{{ state_attr(''variable.verlichting_mini_waarden'', ''doelkleurtemperatuur'')}}'
#          - service: deconz.configure
#            data_template:
#              entity: light.mini_lampen
#              field: "/action"
#              data:
#                on: true
#                bri: "{{ state_attr('variable.verlichting_mini_waarden', 'doelhelderheid') }}"
#                ct: "{{ state_attr('variable.verlichting_mini_waarden', 'doelkleurtemperatuur') }}"
      # Feller
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event in ( 1001, 3001 ) }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.mini_lampen
              field: "/action"
              data: {"bri_inc":254, "transitiontime":50}
      # Dimmen
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event in ( 2001, 4001 ) }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.mini_lampen
              field: "/action"
              data: {"bri_inc":-254, "transitiontime":50}
      # Stop feller/dimmen
      - conditions:
          - condition: template
            value_template:  "{{ trigger.event.data.event in ( 1003, 2003, 3003, 4003 ) }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.mini_lampen
              field: "/action"
              data: {"bri_inc":0}
      # Uit
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event in ( 2002, 4002 ) }}"
        sequence:
          - service: light.turn_off
            data_template:
              transition: 4
              entity_id:
                - light.mini_lampen

Background:
My variable.verlichting_mini_waarden variable is being updated periodically based on the position of the sun (based on suncalc "start of sunrise, end of sunrise, etc. etc. etc.). Another automation is applied when the light is on, to slowly change to the new setting. (so when the variable is changed a command is sent to the light to move towards the new values in a period of 10 minutes, so that it isn’t directly visible). My end-goal is to also do this with the deconz.configure service

Did you take a look at the adaptive lighting custom component? It does exactly that and it works quite well for me.

I don’t know why the service call doesn’t work for you, you could try putting it in a dict by enclosing it in curly brackets and separate it with a comma, the same as you did for the other deconz configure services.

See here my working service:

Thank you for looking in to it further.
I gave the adaptive lighting a go, but the lights remain way too bright for me.

Simple example. At 0730 this morning the lights go to 57% brightness (I set the max to 70%). It is still completely dark outside. (I manually set it to 27% which is what I prefer)

I think the integration looks at the position of the sun relative to the horizon and not the to the angle towards my house. (A sunrise in the summer behaves completely different than it does in the winter)

The suncalc libraries which are used with the Deconz daylight virtual sensor do take that in account.

Long story short. That integration is not for me. At least. It isn’t in this stage. If it would be customisable further than it does now, it would be great for me :slight_smile:

Maybe a sunrise/sunset offset (which is configurable already) could help for adaptive lighting in your use case.

Did you try to put the data into a dict with curly brackets yet?

I could look into the offset and change that a few times per year, but it doesn’t seem ideal. I’ll look into that too.

I tried it like this:

entity: light.mini_lampen
field: "/action"
data: { 'on': true, 'bri': {{ state_attr('variable.verlichting_mini_waarden', 'doelhelderheid') }}, 'ct': 500 }
#                                                                          ^^^

If I put that in the developer assistance - services part (not sure what it’s called in English - where you can test out service calls) it falls over the comma between mini_waarden and doelhelderheid.

Fout bij het parseren van YAML: entity: light.mini_lampen field: "/action" data: { 'on': true, 'bri': {{ state_attr('variable.verlichting_mini_waarden', 'doelhelderheid') }}, 'ct': 500 }

I think that is my issue. I have a comma in my variable field (due to the state_attr syntax) as my value is an attribute.

Hi,

I got it working.
The issue probably lies in the fact that the my templates has comma values.

- id: 'mini_lampen'
  alias: 'Mini lampen'
  initial_state: 'on'
  mode: 'restart'
  variables:
    kleurtemperatuur: >
      {{ state_attr('variable.verlichting_mini_waarden', 'doelkleurtemperatuur') | int }}
    helderheid: >
      {{ state_attr('variable.verlichting_mini_waarden', 'doelhelderheid') | int }}
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: mini_wandschakelaar
  action:
    - choose:
      # Lampen aan
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event in ( 1002, 3002 ) }}"
        sequence:
          - service: deconz.configure
            data_template:
              entity: light.mini_lampen
              field: "/action"
              data: {"on": true, "bri": "{{ helderheid }}", "ct": "{{ kleurtemperatuur }}"}

So, by first defining the attributes as a template dedicated for the run of the automation, I can use it.

The usage of the ‘Adaptive Lighting’ integration doesn’t make sense for my situation. I had to set the offset of the sunset an sunrise to two hours to get near what I want. If I look at the github page of the custom integration and see the graphs, they go to 100% brightness far too fast for my taste. But I guess it’s very personal and it also depends on your types of lights I think.

For now I have a working situation.
Thank you for your time @Burningstone

1 Like