StephanJoubert / home_assistant_solarman

Home Assistant component for Solarman collectors used with a variety of inverters.
Apache License 2.0
508 stars 190 forks source link

Allow to divide a register value by a number #501

Closed virtualdj closed 4 months ago

virtualdj commented 5 months ago

Add support for a new parameter scale_division in the YAML definition files which allows to divide the register(s) value by a constant number provided. The division is always done after the scaling happened.

This is useful for example for registers that display a value in minutes, but you want the sensor to be in hours: in that case, simply add scale_division: 60 and change the unit of measurement accordingly.

So this sensor:

- name: "Total Generation Time"
  class: ""
  state_class: "measurement"
  uom: "min"
  rule: 3
  registers: [0x0428,0x0427]
  icon: 'mdi:clock-outline'

can be transformed to this:

- name: "Total Generation Time"
  class: ""
  state_class: "measurement"
  uom: "h"
  scale_division: 60
  rule: 3
  registers: [0x0428,0x0427]
  icon: 'mdi:clock-outline'

If you want days from minutes, supply scale_division: 1440 (60 * 24) and so on... I took the opportunity to fix a bunch of typos in the customization readme, too.