home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.17k stars 30.2k forks source link

Trend integration not working on sensor with "monetary" device class #121287

Open Taomyn opened 3 months ago

Taomyn commented 3 months ago

The problem

I have a sensor that is device_class "monetary", which I can add as new trend helper, but it will not allow me to choose the sensor's value for the trend helper to monitor. The helper simply stays as "unknown".

I'm not sure if it's caused by this, but I cannot edit the trend to change the value it monitors, there does not seem to be a field showing it, only the name of the trend sensor.

What version of Home Assistant Core has the issue?

core-2024.7.0 to core-2024.7.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Trend

Link to integration documentation on our website

https://www.home-assistant.io/integrations/trend

Diagnostics information

No response

Example YAML snippet

sensor:
      - unique_id: guichet_95_fuel_price
        device_class: monetary
        name: 95 Fuel Price
        icon: mdi:gas-station
        value_template: "{{ value_json['items'][0]['Price95Fuel'] }}"
        unit_of_measurement: "€"

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 3 months ago

Hey there @jpbede, mind taking a look at this issue as it has been labeled with an integration (trend) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `trend` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign trend` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


trend documentation trend source (message by IssueLinks)

Taomyn commented 1 month ago

Disappointed that this isn't being looked at, especially for a new feature as there must have been support to get it added - why would monetary values not be something to watch the trend of, considering we're able to monitor all sorts of consumption by our smart homes.

jpbede commented 1 month ago

The trend sensor works independently of any device class. It just considers the state or a attribute. How does the configuration of your trend sensor look like?

Taomyn commented 1 month ago

Not sure the best way to show, but is this enough:

image

The attributes available don't show one for the value which is why it's value shows empty when I try to display it:

image

The entity I am monitoring is:

image

Which I can display:

image image

Taomyn commented 1 month ago

This month's update allowed me to set the "state_class" to "measurement" which seemed the best option to use, but it still does not show me the main attribute of the entity i.e. the actual value.

The YAML to create the entity is:

    sensor:
      - unique_id: guichet_95_fuel_price
        device_class: monetary
        state_class: measurement
        name: 95 Fuel Price
        icon: mdi:gas-station
        value_template: "{{ value_json['items'][0]['Price95Fuel'] }}"
        unit_of_measurement: "€"
jpbede commented 1 month ago

Just leave the attribute field empty, it will then use the state value, additionally you would need to set a minimum gradient.

Please read https://www.home-assistant.io/integrations/trend#using-multiple-samples how to set and calculate the minimum gradient.

Taomyn commented 1 month ago

I appreciate the help but I don't think I'm fully getting this, sorry. Don't know if this helps explain what I'm after, but this sensor checks for the current value every 4 hours, but it could be days/weeks before it ever changes. I was hoping that "trend" would simply tell me that the current value is either an increase or a decrease of the previous change regardless of when that was. So if last month the value went up but has remained the same since, it continues to show as an increase.

jpbede commented 1 month ago

I understand what you want, but the trend integration needs to know when it's an increase/decrease, that's what the gradient is for. The gradient tells us how much the source sensor needs to deviate between samples to trigger.

I'm thinking about of simplifying this integration, but I don't know when I've time to do this