Add attribute to input_* helpers

Currently it’s possible to add an input_* helper and set it’s value. What is not possible, is to set/store attributes on them.

The only option currently available to store multiple data points related to one “thing”, is to create multiple helpers.

Use case:

  • Scenario: I want to keep track of my EV charging sessions. For this, I want to keep track of a certain amount of values when a charging session starts. For example; current energy level in the batter (in kWh), the SoC (in %), the EVCS meter total (in kWh), the value of another energy meter (in kWh) and the timestamp. This information is then used when the charging session is completed to calculate the duration, amount of energy consumed, charging efficiency, …
  • Needed (currently):
    • input_number.ev_xyz_energy
    • input_number.ev_xyz_soc
    • input_number.ev_xyz_evcs
    • input_number.ev_xyz_iotawatt
    • input_datetime.ev_xyz_session
  • Needed (If attributes can be set):
    • input_number.ev_xyz_charging (containing SoC)
      attributes:
      • energy
      • evcs
      • iotawatt
      • start

As you can see, when having attributes on input_* helpers, there’s a lot less to entities to maintain, keeping everything nice and tidy.

Example service call:

action: input_number.set_value
target:
  entity_id: "input_number.ev_xyz_charging"
  data:
    value: "{{ states('sensor.ev_xyz_soc') }}"
    attributes:
      energy: "{{ states('sensor.ev_xyz_energy') }}"
      evcs: "{{ states('sensor.victron_evcs_total_energy') }}"
      iotawatt: "{{ states('sensor.iotawatt_energy_wh') | float(0) / 1000 }}"
      start: "{{ now() }}"

Where are you getting the numbers from in the first place?
You could combine them all in a sensor with attributes.

Example: Template - Home Assistant
This is a binary sensor but it could be a sensor with energy and evcs attributes instead of lat/lon.

Oh… and I believe there was an idea to stop using attributes.
Look at the weather entity and a lot of sensors with attributes has now become several sensors.

I can indeed create a template sensor that neatly collect all information. Yet when the charging session stops, and I want to make calculations based on the starting values (e.g. how much energy was used according to the EVCS, how fast did the car charge, …) that template sensor has since then moved on and I don’t know it’s state at the start of the session.

Triggered template sensors…

That’s indeed a nice workaround. Thanks!

I don’t think the feature request will pass, so it’s probably better to try and find a way around the issue.
This should be OK until we get template devices (if ever)

Still hope enough people vote for it so it may eventually get implemented.

The trigger template sensor kinda works, but unfortunately they don’t retain state when HA would reboot. And since at home I do slow AC charging, that might happen every now and then.

Edit; it seems it does for sensor and binary sensor. I’ll give it a go and see how it works.

I’m not that long to actually know the legacy here, but my understanding is that HA used to use attributes extensively – in the way you’re describing. BUT, attributes were considered cumbersome (to use? extract data? track?) and there was a move to split attributes to separate entities and “group” them into devices. I may be wrong here, anyway…

I don’t mind separate entities, but I still have a need for “grouping” them → hence I’d hope “devices” were much easier to work with in HA.

Check this out:

EDIT:

Actually, when I think about it, it makes sense to have separate entities – as each can have its own “attributes” (or: “metadata”) – like if the value is a temperature, the helper (entity) can have metadata that says that (and what unit) → while if it was just an attribute of a bigger entity, then we’d have to have a way to set “attributes on attributes” :slight_smile:

Separate entities are now preferred for values that are expected to change often. Things that don’t change often, e.g. a mac address, are still allowed to be attributes.

Having said that you can still add whatever attributes you want using manual customisation. https://www.home-assistant.io/integrations/homeassistant/#manual-customization