skagmo / ha_vwid

Volkswagen ID component for Home Assistant
71 stars 25 forks source link

Separate sensors for attributes #20

Open Emacee opened 2 years ago

Emacee commented 2 years ago

Hi,

Currently I'm using this integration together with some template sensors in my configuration.yaml file to split the attributes into separate sensor. That makes it possible to track the history of all the separate sensors. Is it possible to easily integrate this functionality into the integration already? I know how to 'code' in YAML (after googling for some examples) but coding in Phyton is a bit above my league. If someone can help me out so I can contribute to this, that would be very helpful.

skagmo commented 2 years ago

It would be possible, however this is a design decision I've done to avoid a lot of sensors that is not necessarily used, as there are very many values returned by the VW API. Sensors use a lot more resources and fills up the database vs. attributes.

If I ever add it, I think there should be a configuration option to select which values should be separate sensors.

I can leave your issue open for a while if someone wants to contribute on this matter.

jcsogo commented 2 years ago

While I understand that you don't want to poll the space with a lot of devices, at the same time you are forcing everybody to create those through templates to create the sensors to be used in lovelace or other integrations. I think that it would make sense to have directly provided:

Optional could be all the others, although I think that there are some others quite interesting there. Some of those would be switches and others binary sensors, so not much space in the recorder.

About the recorder issue. I think it should be up for the user to deal with the size of the DB and the time that the data is stored. I would like to have that as an easily configuration in HA not requiring to deal with the config file, but that is not part of this discussion.

GroundAttack commented 2 years ago

I just have the SOC after installing on HA. Fortunately, its the one I need. I assume that's all that's available at the moment. Am I correct?

GroundAttack commented 2 years ago

Oops! Just spotted how to use a sensor template to create the entities I need.

Emacee commented 2 years ago

This is the code that I'm using for the different sensors, taken from the attributes.

template:
  - sensor:
      - name: volkswagen_id_3_cruising_range
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'TotalRangeKm') }}"
        unit_of_measurement: "km"
        state_class: measurement
        unique_id: vwid3cr
      - name: volkswagen_id_3_charge_power_kw
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'ChargePowerKW') }}"
        unit_of_measurement: "kW"
        state_class: measurement
        unique_id: vwid3cpkw
      - name: volkswagen_id_3_charge_remaining_time
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'RemainingChargingTimeToCompleteMin') }}"
        unit_of_measurement: "minuten"
        state_class: measurement
        unique_id: vwid3ctrm
      - name: volkswagen_id_3_climatisation_remaining_time
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'RemainingClimatisationTimeMin') }}"
        unit_of_measurement: "minuten"
        state_class: measurement
        unique_id: vwid3clima
      - name: volkswagen_id_3_target_temperature
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'TargetTemperatureC') }}"
        unit_of_measurement: "°C"
        unique_id: vwid3temp
      - name: volkswagen_id_3_external_power
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'ExternalPower') }}"
        unique_id: vwid3extpwr
      - name: volkswagen_id_3_plug_connection
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'PlugConnectionState') }}"
        unique_id: vwid3plug
      - name: volkswagen_id_3_charge_state
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'ChargingState') }}"
        unique_id: vwid3chargestate
      - name: volkswagen_id_3_max_charging_power
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'MaxChargeCurrentAC') }}"
        unique_id: vwid3maxpwer
        unit_of_measurement: "kW"
      - name: volkswagen_id_3_charge_rate_kmph
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'ChargeRateKmph') }}"
        unit_of_measurement: "km/u"
        state_class: measurement
        unique_id: vwid3maxpwerkm
      - name: volkswagen_id_3_target_soc
        state: "{{ state_attr('sensor.volkswagen_id3_soc', 'TargetSOCPct') }}"
        unit_of_measurement: "%"
        state_class: measurement
        unique_id: vwid3targetsoc