How to create dynamic sensor

Good afternoon,

Few days know searching how to perform this action without success… Sure the solution exist but how to put in place no ideas.

I have a old electric box without any smart connections, during night (after 23.00) I pay electricity 1.11 and during daytime (after 7.00) I pay electricity 1.15.

I would like to create a sensor which return 1.15 during day and 1.11 during night.

I try to create sensor in configuration.yaml but without success. I don’t know where to start and how to start (automation, scripts, custom sensor).

I will be very glad if someone can help me to figure it out.

Thanks a lot

Lauent

I believe this could work.

{% if(states("sensor.time")[0:2] | int == 23 or states("sensor.time")[0:2] | int <= 6) %}
1.11
{% else %} 
1.15
{% endif %}

What you are describing is a template sensor. Make sure to put your currency in the quotes after “unit_of_measurement:”.

#configuration.yaml

template:
  - sensor:
      - name: "Electricity Cost"
        unit_of_measurement: " " 
        state: >
          {{ 1.11 if now().hour <= 6 or now().hour > 22 else 1.15 }}