snarky-snark / home-assistant-variables

A custom Home Assistant component for declaring and setting generic variable entities dynamically.
Apache License 2.0
274 stars 16 forks source link

var.set call in node red errors #76

Closed highincolorado closed 2 years ago

highincolorado commented 2 years ago

I am trying to add attibutes to some variables and then use the node-red call service node to modify the attribute. I have tried many ways to format the call but nothing has worked so far. I even loaded the example data and made the call and got the same error message: "Call-service error. expected a dictionary for dictionary value @ data['attributes']

I admit to a lack of knowledge with how to format what I want but was hoping the example data would point me in a good direction. Is this broken or am I just not getting it? Any help? Thanks!

Screenshot 2022-06-23 111725 Screenshot 2022-06-23 112204 "

snarky-snark commented 2 years ago

The error message appears to be correct. You need to format the attributes as a dictionary. For example,

"attributes": {"attr1": 42, "attr2": "abcd"}
highincolorado commented 2 years ago

Ah curly brackets all the things I tried and that wasn't one. Many thanks. This worked:

{
   "attributes":{"ordered": 1}
}

One further question if I may, the following is the var defiinition, will the attribute I set in node red be overwritten when the tracked ink changes it's value?

  ink_office_canon_magenta:
    friendly_name: "Office Canon CLI-251XL M"
    initial_value: 0
    unit_of_measurement: "%"
    value_template: >-
      {% if is_state('sensor.canon_mx920_series_magenta', 'unavailable') or
            is_state('sensor.canon_mx920_series_magenta', 'unknown') -%}
        {{ (states('var.ink_office_canon_magenta')) }}
      {%- else -%}
        {{ (states('sensor.canon_mx920_series_magenta')) }}
      {% endif %}
    tracked_entity_id:
      - sensor.canon_mx920_series_magenta
    attributes:
      ordered: "0"
snarky-snark commented 2 years ago

Yes. From the docs:

If you set the attribute via NodeRed, then it will be reevaluated each time the tracked entity updates.