rogro82 / hass-variables

Home Assistant variables component
236 stars 59 forks source link

variable, attributes_template does not work #53

Closed gribouk closed 3 years ago

gribouk commented 3 years ago

Dear All,

I am trying to use variable objects for my project, but the attributes_template do not work for some reason. I made a small example which yelds no result and I fail to understand why:

    detectors_list:
        value: 0
        attributes:
            list: "binary_sensor.dining1"

this I call from developer's tools, services, variable.set_variable with data below

variable: detectors_list
value_template: 2
attributes: >  
  { 
    "list": "{{ variable.attributes.list }}" 
  }

No metter what I try, the attributes do not change. Would anyone give me a hint why?

The error message from the log:

Logger: homeassistant Source: custom_components/variable/init.py:219 First occurred: 23:57:58 (1 occurrences) Last logged: 23:57:58

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/config/custom_components/variable/init.py", line 219, in async_set_variable attributes = json.loads( File "/usr/local/lib/python3.8/json/init.py", line 341, in loads raise TypeError(f'the JSON object must be str, bytes or bytearray, ' TypeError: the JSON object must be str, bytes or bytearray, not Wrapper

Mariusthvdb commented 3 years ago

Check https://github.com/rogro82/hass-variables/issues/47 for the answer

enkama commented 3 years ago

Also in your previous comment on #47 (Which you deleted) you even mentioned my repository at https://github.com/Wibias/hass-variables . In the README.MD over there is the right & updated format that you need to use.

Mariusthvdb commented 3 years ago

@wibias, was that a post for me? don't recall deleting anything tbh.

gribouk commented 3 years ago

Yes, there was one. But the context has chaned and I had to change the message....

As I discovered, the integration does work if dowloaded from here: https://github.com/Wibias/hass-variables, but DO NOT TEST IT FROM /developer-tools/service. I have no explanation for that, but if you test it from there, no metter what data you feed with your request - it does not template the attributes, explicit values only. When tested from the actuall script/trigger - everything works fine. It took me 3-4 hours of life to discover that. Maybe, in future they correct this, but as of tooday, 28.12.21, it stays like this...

enkama commented 3 years ago

@Mariusthvdb The post was from @gribouk got an email notification from that.