Energy Costs always returning 0

Hi all,

Why does this always return 0?

image

   - platform: template
     sensors:
       daily_energy_cost_all_shelly:
         value_template: "{{ (states('sensor.daily_energy_cost_peak_shelly') | float) + 
         (states('sensor.daily_energy_cost_offpeak_shelly') | float) }}"
         friendly_name: 'Today Cost Shelly' 
         unit_of_measurement: '€'

I think I have it set up properly:

   - platform: template
     sensors:
       daily_energy_cost_peak_shelly:
         unit_of_measurement: '€'
         friendly_name: 'Today Peak Tariff Cost Shelly' 
         value_template: "{{ (states('sensor.daily_energy_peak_shelly') | float * (states('input_number.peak_tariff') | float)) | round(2) }}" 
         #state_class: 'measurement'
   - platform: template
     sensors:
      daily_energy_cost_offpeak_shelly:
        unit_of_measurement: '€'
        value_template: "{{ (states('sensor.daily_energy_offpeak_shelly') | float * (states('input_number.offpeak_tariff') | float)) | round(2) }}"
        friendly_name: 'Today Offpeak Tariff Cost Shelly' 
        #state_class: 'measurement'

Any help would be appreciated. It’s probably something very simple

What happens when you put it into the template dev-tool.

Same thing: 0,0

These are the automations to set the tariff:

alias: ' - Utility Tariff Peak '
description: ''
trigger:
  - platform: time
    at: '13:00:00'
condition: []
action:
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id:
        - utility_meter.daily_energy
        - utility_meter.daily_energy_shelly
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id:
        - utility_meter.monthly_energy
        - utility_meter.monthly_energy_shelly
mode: single
initial_state: 'on'

and

alias: ' - Utility Tariff Offpeak 00:00'
trigger:
  - platform: time
    at: '23:00:00'
action:
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id:
        - utility_meter.daily_energy
        - utility_meter.daily_energy_shelly
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id:
        - utility_meter.monthly_energy
        - utility_meter.monthly_energy_shelly
initial_state: 'on'
mode: single

Maybe something wrong with the automation?

Test them one step at a time, first this

(states('sensor.daily_energy_cost_peak_shelly')

Then add the |float etc. You will find your error with a bit of trial and error.

Got it thank you

   - platform: template
     sensors:
       daily_energy_shelly_cost_peak:
         unit_of_measurement: '€'
         friendly_name: 'Today Peak Tariff Cost Shelly' 
         value_template: "{{ (states('sensor.daily_energy_shelly_cost_peak') | float * (states('input_number.peak_tariff') | float)) | round(2) }}" 
   - platform: template
     sensors:
      daily_energy_shelly_cost_offpeak:
        unit_of_measurement: '€'
        value_template: "{{ (states('sensor.daily_energy_shelly_offpeak') | float * (states('input_number.offpeak_tariff') | float)) | round(2) }}"
        friendly_name: 'Today Offpeak Tariff Cost Shelly' 
   - platform: template
     sensors:
       daily_energy_cost_all_shelly:
         value_template: "{{ (states('sensor.daily_energy_cost_shelly_peak') | float) + (states('sensor.daily_energy_shelly_cost_offpeak') | float) }}"
         friendly_name: 'Today Cost Shelly' 
         unit_of_measurement: '€'
1 Like