Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes have null as value #77

Open
majkers opened this issue Jun 29, 2022 · 15 comments
Open

Attributes have null as value #77

majkers opened this issue Jun 29, 2022 · 15 comments

Comments

@majkers
Copy link

majkers commented Jun 29, 2022

Hi,

here is my config:

var:
  gaz1:
    friendly_name: "Rachunek za gaz"
    entity_picture: '/local/rachunki/pgnig.png'  
    initial_value: '2022-07-11'
    attributes:
      do_zaplaty: '449,70 zł'
      czy_oplacony: 'nie'

And this is what I see in HA:

image

So attributes get null as value...

@majkers
Copy link
Author

majkers commented Jun 29, 2022

Maybe this is related?

invalid key: "OrderedDict([('449,70 zł', None)])" in "/config/configuration.yaml", line 807, column 0

@snarky-snark
Copy link
Owner

Perhaps a text encoding issue? What happens if you change '449,70 zł' to '449,70?

@majkers
Copy link
Author

majkers commented Jun 30, 2022

No, still the same

@vigilcoma
Copy link

Have the same issue with attributes

@snarky-snark
Copy link
Owner

Have the same issue with attributes

If you post more details about your problem, we may have a better chance of determining the cause.

@vigilcoma
Copy link

vigilcoma commented Jul 6, 2022

Have this config

var:
  lexman_1_data:
    friendly_name: "Lexman 1 data"
    initial_value: '{"current_light": ""}'
    attributes:
      scene_1: '{{ {"counter": 1} }}'
      scene_2: '{{ {"counter": 2} }}'
      scene_3: '{{ {"counter": 3} }}'
      scene_4: '{{ {"counter": 4} }}'

Wanted to store simple json

@snarky-snark
Copy link
Owner

Okay, I think I know what is happening here. Variable attributes are templates, and they are only updated when a tracked event fires. Neither of your variables specify any tracked events, so the attributes are never evaluated.

You can fix this by specifying the following tracked event which will update your variable attributes when home assistant starts.

tracked_event_type: homeassistant_start

Alternatively, you can set the attributes using the var.set service.

As an aside, this behavior can be inferred from the documentation, but it is not obvious. A proper fix for this is to create a separate attribute_templates property for templates and leave attributes for values only.

@majkers
Copy link
Author

majkers commented Jul 11, 2022

OK but how about reloading this integration? By watching this event, reloading rom YAML section won't work right? This is essential for my and the reason why I wanted to switch to your integration from similar...

@snarky-snark
Copy link
Owner

@majkers
Copy link
Author

majkers commented Jul 18, 2022

OK but how can I pass component attribute?

@snarky-snark
Copy link
Owner

I am not sure what you are asking.

@majkers
Copy link
Author

majkers commented Jul 19, 2022

This event (COMPONENT_LOADED) requires additional data to be passed -> component (Domain of the integration that has just been initialized. Example: light.) How can I pass it from your integration?

@snarky-snark
Copy link
Owner

The domain of the Variable component is var.

@majkers
Copy link
Author

majkers commented Jul 20, 2022

Yes I know that but how can I pass this param via var integration?
tracked_event_type: COMPONENT_LOADED
and then what?

@snarky-snark
Copy link
Owner

Ah, I see. That is not supported at the moment.

There might be another way to solve your problem, but I'm not sure I understand your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants