Hot tub template sensor problem

Hi @tom_l - I didn’t want to start a new topic because my query is very similar. I’m trying to setup a sensor for a cost calculation for my hot tub.
This is in my configuration.yaml (just below the default stuff) and nothing else in the file. But after a fully HA restart, the sensor doesn’t appear. I’m using docker for my instance, just because I have a NAS that’s always on, so it was easier.

Anything standout why I can’t find the sensor? Thanks.

template:
  - sensor:
      - friendly_name: 'Hot Tub Cost'
        unit_of_measurement: '£'
        value_template: '{{ "{:.2f}".format((states (0.17) | float) * ((states
  ("sensor.hms_tubs_pump_1_energy_daily") | float ) + (states
  ("sensor.hms_tubs_pump_2_energy_daily") | float ) + (states
  ("sensor.hms_tubs_heater_energy_daily") | float ))) | round(2) }}'

Yes. You have a mishmash of old and new formats. You also abused the single line template format. There will be errors in your logs about both of these.

Try this:

template:
  - sensor:
      - name: 'Hot Tub Cost'
        unit_of_measurement: '£'
        state: >
          {{ "{:.2f}".format((states (0.17) | float) * 
          ((states("sensor.hms_tubs_pump_1_energy_daily") | float ) + 
          (states("sensor.hms_tubs_pump_2_energy_daily") | float ) + 
          (states("sensor.hms_tubs_heater_energy_daily") | float ))) | round(2) }}
1 Like

Ahhh, yes, that makes sense. I’m cobbling together stuff from all over the place to try and get it working. Your changes have made it appear now. Much appreciated! Have a great weekend

1 Like

Hey, @tom_l (and anyone else reading this) - I’m not getting data through from the sensor. If I remove (states (0.17) | float) * then I get a value through. What’s the correct way to enter an integer hardcoded? The 0.17 is my cost of electricity per kw.

If I try to add a value in I get ‘unknown’. I’ve tried creating ‘helper’ with a number type - the value is correct but if I try adding that to the sensor (states ("input_number.sensort_energy_tarrif") | float) * it goes back to ‘unknown’

I didn’t actually look that closely at your template. It is definitely not correct. Try this:

template:
  - sensor:
      - name: 'Hot Tub Cost'
        unit_of_measurement: '£'
        state: >
          {{ "{:.2f}".format(
            0.17 * ( states("sensor.hms_tubs_pump_1_energy_daily") | float(0) +                 
            states("sensor.hms_tubs_pump_2_energy_daily") | float(0) + 
            states("sensor.hms_tubs_heater_energy_daily") | float(0) ))
          }}
1 Like

That’s the ticket! I was just about to ask if there’s a playground to try these things…just dawned on me as I was typing that out - dev tools -> template lets you check these things, I’ll go to town on that a lot more going forward. You’ve a been a true legend helping me with this. Thanks very much.

1 Like