Manual Tariff sensor

Hi,

I’m trying to add a sensor in HA to show my electricity unit cost, which alternates depending on the time of day - just twice.

I’m not a confident programmer, yet so far I have got everything in HA working, by copying and modifying other people’s code or following guides and youtube!

However I cannot work out how to add a sensor to my config.yaml without it giving me a whole load of errors. All it needs to do is appear as a sensor with a price in £p/kWh that alternates between off and on peak - 2am to 6am being off peak.

Can anyone help me with what to add to the yaml and where?

thank you in advance.

Put this in your configuration.yaml file

template:
  - sensor:
      - name: "Energy Cost"
        icon: "mdi:power-plug"
        unit_of_measurement: "£p/kWh"
        state: "{{ 0.15 if 2 <= now().hour < 6 else 0.3 }}"

You did not say what your rates were so I assumed:

Off peak: 0.15
Peak: 0.3

Change these values in the template to your actual values.

thank you so much. Every single other post on the matter had slightly different implementation of

  • template
  • sensors:
    etc

or whatever, and I kept getting errors in the config file.