Template Card Statistics Offset

Servus,

… i am lost, i spent hours on why the hell the template does not work.

I work on a Card Template with Statistics Card which supports offset ( like -1 ) .
The Problem is that the "offset: " Attribute is strict numeric. And i have found no way to input a numeric Value from a counter or number template (-0 to -12 ) .

All Templates i do for the Number Value seems to have only a state attribute which when retrieved seems to be strict string in any case .

the Number templates to turn a + into a - are numbers - i return strictly float() .

The retrieve of state seems to be the point.

I think somethink stupid why i am lost :slight_smile:

This is the Code :slight_smile:

type: custom:config-template-card
variables:
  test: -2
  test1: states['number.monthly_offset_value_card'].state
card:
  type: statistic
  entity: sensor.daily_imported_energy
  name: ${test1}
  period:
    calendar:
      period: month
      offset: ${test}
  stat_type: change
entities:
  - counter.monthly_offset_value

offset: $test works
offset: $test1 does not work because it returns ‘-2.0’ instead of -2.0

This is the Error:
expected int for dictionary value @ data[‘calendar’][‘offset’]. Got ‘-2.0’

Would help a lot.

thx, Dietmar

… I use Buttons to increase or decrease a counter, then a template which turns from positiv 0-12 to negativ 0 to -12 … a counter cannot be negativ somehow ) to be able to use it in the offset ( -0 to -12 ) per xx month . But .state returns String which the card does not accept .

At the end i would need a button to “drive” a offset numeric value -0 to -12 which i could use in the custom template.

It would cust be great it the statistics card would accept ‘-2.0’ also :slight_smile:

Best regards, Dietmar

Servus,

I do think that is a very ugly solution, but this is working.

type: custom:config-template-card
variables:
  meiner: states['number.monthly_offset_value_card'].state
card:
  type: statistic
  entity: sensor.daily_imported_energy
  name: ${meiner}
  period:
    calendar:
      period: month
      offset: >-
        ${meiner === '-0.0' ? -0 : meiner == '-1.0' ? -1 : meiner == '-2.0' ? -2
        : meiner == '-3.0' ? -3 : meiner == '-4.0' ? -4 : meiner == '-5.0' ? -5
        : meiner == '-6.0' ? -6 : meiner == '-7.0' ? -7 : meiner == '-8.0' ? -8
        : meiner == '-9.0' ? -9 : meiner == '-10.0' ? -10 : meiner == '-11.0' ?
        -11 : meiner == '-12.0' ? -12 : -0;}
  stat_type: change
entities:
  - counter.monthly_offset_value_card