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

HA Automation trigger.to_state.attribute spacing instead of underscore #60

Closed
Florian14490 opened this issue Feb 11, 2023 · 6 comments · Fixed by #65
Closed

HA Automation trigger.to_state.attribute spacing instead of underscore #60

Florian14490 opened this issue Feb 11, 2023 · 6 comments · Fixed by #65
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Florian14490
Copy link

Hello,

Thanks voor the good integration, works perfect !
I have one problem with trigger state.

Some state attributes have spacing instead of underscore between words.
That means that my automation not giving the correct info, it give me error.
I use folllowing : {{trigger.to_state.attributes.TGTG Price}} , its not working because of spacing between TGTG and Price.

Following is working: {{trigger.to_state.attributes.friendly_name}}, it has the underscore between friendly and name.

Example attributes of sensor:
Item ID: '75581'
Item URL: https://share.toogoodtogo.com/item/75581
TGTG Price: 4.99 EUR
Original value: 14.99 EUR
unit_of_measurement: pcs
icon: mdi:storefront-outline
friendly_name: TGTG 't Bakkershuys

The attributes with underscores are working but I cant get the attributes with spacing instead of underscore,=.

Is there a simple tip or trick to get them in my automation?
Example: {{ trigger.to_state.attributes.TGTG Price}}

Hope the here from you.
Already Thanks,

@tjorim
Copy link
Collaborator

tjorim commented Feb 12, 2023

From the documentation here.
When an attribute contains spaces, you can retrieve it like this:
state_attr('sensor.tgtg_*', 'TGTG Price').

@tjorim tjorim closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2023
@Florian14490
Copy link
Author

Florian14490 commented Feb 13, 2023 via email

@tjorim
Copy link
Collaborator

tjorim commented Feb 15, 2023

Agreed, reopening this issue! Although it's not in the developer docs, and I have other integrations that don't seem to use snake_case either, we could change/fix it here. Will be picked up when I'm back from holiday next week (or if anyone feels like giving it a shot).

Btw, @Florian14490, feel free to provide your automation as an example. It would be nice to have a few in the documentation here!

@tjorim tjorim added enhancement New feature or request good first issue Good for newcomers labels Feb 15, 2023
@tjorim tjorim reopened this Feb 15, 2023
@Florian14490
Copy link
Author

@tjorim , yes offcourse.
Here is the automation I use. All trigger attributes data without the spacing (with underscores) are working correct and sending the right data of the triggers in my notify message. All trigger attributes with the spaces (without underscores) are not sending data of the triggers.

alias: TooGoodToGo Notification K + F (stock sensor)
description: TooGoodToGo Notify K + F (stock sensor)
trigger:

  • platform: state
    entity_id: >-
    sensor.tgtg_xxx,sensor.tgtg.xxx,sensor.tgtg.xxx,sensor.tgtg.xxx
    from: "0"
    condition: []
    action:
  • service: notify.mobile_app_tel_florian
    data:
    message: >-
    Beschikbaar: {{trigger.to_state.state}}, Voor: € {{
    state_attr("trigger.entity_id", 'TGTG Price')}}, Start:
    {{trigger.to_state.attributes.Pickup start}}
    title: "{{trigger.to_state.attributes.friendly_name}}"
    data:
    clickAction: "{{trigger.to_state.attributes.Item URL}}"
    group: tgtg
    tag: "{{trigger.entity_id}}"
    mode: parallel
    max: 10

@tjorim tjorim linked a pull request Feb 19, 2023 that will close this issue
@tjorim
Copy link
Collaborator

tjorim commented Feb 19, 2023

@Florian14490

Could you please try version 5.1.0? I released it as beta.
Please check the new attribute names and let me know what you think (and if it works as expected now).
In HACS you can look for tgtg, click the three dots in the corner and redownload:
image

@Florian14490
Copy link
Author

Florian14490 commented Feb 20, 2023

@tjorim
Morning,
Just checked it while breakfast.
It works perfect now with the new attribute names.

Thank you verry much to put work in it.

Have a nice day
Grtz Florian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants