For Netherlands; Sensor for hoog tarief and laag tarief that reacts as a switch

Hi,

I’m a quite a newbe, but looking for making a sensor that has 2 states (low and high). I should work with the Dutch laag tarief and hoog tarief for electric power.

I want to use it in automations to let high powerusers run only (or mostly) at the lower cost laag tarief

It depends a bit on where you live exactly, but roughly its every day from 23:00 till 6:00 next morning and the complete weekend.

Would be nice to have the icon to show what state its in.

Any sugestions how to build this sensor ?

try:

sensor.huidig_tarief:
    entity_id: sensor.time
    value_template: >
      {% if 7 < now().hour < 21 %} Hoog
      {% else %} Laag
      {% endif %}
    icon_template: >
      {% if is_state('sensor.huidig_tarief','Hoog') %} mdi:numeric-1-box-multiple-outline
      {% else  %} mdi:numeric-2-box-multiple-outline
      {% endif %}

is what it is over here, so check if it truly is 6 in your location.

the above is a template sensor, so you should precede it with:

sensor:
  - platform: template
    sensors:

depending on your config, this would be either in you configuration.yaml, but more likely in a dedicated folder for sensors, or even a package.
As long as you reference the sensor: in your configuration.yaml, and point it to the correct location.

If you have a ‘slimme-meter’, it should be able to provide you the current tariff-type. If you haven’t @Mariusthvdb suggestion looks like a neat alternative.

Thanx, will try that, over here its 23:00 till 7:00

But how do I put in the weekends all day ? Or did you already do ?

no, i forgot…

you should add the binary_sensor.workday_sensor to your setup, and then add this to the template:

  {% if 7 < now().hour < 21 and 
     is_state('binary_sensor.workday_sensor','on') %} Hoog
  {% else %} Laag
  {% endif %}

27

you can further enhance this with a few colors:

homeassistant:
  customize:
    sensor.huidig_tarief:
      templates:
        theme: >
          if (state === '1') return 'green';
          return 'orange';
        _stateDisplay: >
           if (state === '1') return 'Laag';
           return 'Hoog';

47

I read it directly from the smart meter, but for the customization that doesn’t matter.

You do need custom-ui for that and setup a few themes, green and orange in this case.

thank you a lot for all your help.
But I think I need al little more help with this.
Should I put everything somewhere in configuration.yalm or should I put it somewhere else ?

I do not realy understand templates yet

Well, you have some nice reading up to do then;-)
without templates you won’t get very far in HA.

Template sensors would be the place to start reading, and the docs on templating

Id say you’d better do it right from the beginning and read:

you can put everything in configuration.yaml, but it would make it a huge file, and very error prone.

for sensors create a subfolder in you /config (the folder where configuration.yaml is located.

add this:

sensor: !include_dir_merge_list sensors

to configuration.yaml and in the newly created folder you save files that contain all you sensors.

have a look:

1 Like

I did read those two, but still did not get it completely.

So far I got some relais working as switches, hue working, 4 1-wire temp sensors, some old klik-aan-klik-uit switches and some automations with time.

So did get some things working without templates (;

Put that one right on the bottom of my configuration.yalm

Oh, ok. A made sensor is a .yalm file. That helps a lot already

This is how it looks over here right now

well, that’s a great start isn’t it :wink:

btw, main reason for concern: your not safe…you should really setup security, because anything connects to anything and you want to do that safely.

now I see you use Toon (which I don’t) are you sure there’s no tariff there already setup?

Securety wise, setup a Duck.dns, but not using it jet. at this moment only possible to reach from within the home network (at least that is what I think :wink:

I did ask in a forum, but no answer jet.

and Toon is a rooted Toon :wink:

sure, but all components you install are communicating also. better be safe than sorry.
Especially when you start using rooted devices… Not sure what that means, but it sounds as if one has been fiddling with it.

Duckdns is a great tool/service, and is one of the tools freely available to the community. Browse the other topics here to find all the info and help you need

I also have a Toon and hoog/laag tarief. So I created a new template sensor that actual decides based on the meter output:

  - platform: template
    sensors:
      current_cost_state:
        friendly_name: Huidig tarief
        icon_template: mdi:currency-eur
        value_template: '{% if (float(states.sensor.toon_p1_power_use_high.state) ) > 0 -%}  Hoogtarief {%- else -%} Laagtarief {%- endif %}'

This might be of interest for you as well, since I see you also produce power probably with solar panels…

- platform: template
  sensors:
    current_power_in:
      friendly_name: "Totaal huidige afname"
      value_template: "{{ (float(states.sensor.toon_p1_power_use_high.state) + float(states.sensor.toon_p1_power_use_low.state)) | round(2) }}"
      unit_of_measurement: 'Watt'
      icon_template: mdi:flash
    current_power_out:
      friendly_name: "Totaal huidige levering"
      value_template: "{{ (float(states.sensor.toon_p1_power_prod_high.state) + float(states.sensor.toon_p1_power_prod_low.state)) | round(2) }}"
      unit_of_measurement: 'Watt'
      icon_template: mdi:flash

at first sight that might look alright, but it only holds if you don’t have solar panels producing power. In which case states.sensor.toon_p1_power_use_high might very well be < 0 while at high tariff.

Time is the only true determinator here.

don’t want to ‘know better’ but you could write your sensor like:

value_template: >
  {% if states('sensor.toon_p1_power_use_high') |float >  0 %} Hoogtarief
  {% else %} Laagtarief 
  {% endif %}

just that bit better readable and less error prone while editing.

And add this for the indicator:

     current_cost_state:
       friendly_name: Huidig tarief
       icon_template: mdi:currency-eur
       value_template: '{% if (float(states.sensor.toon_p1_power_use_high.state) + float(states.sensor.toon_p1_power_prod_high.state)) > 0 -%}  Hoogtarief {%- else -%} Laagtarief {%- endif %}'

sure… you’re right

have a little templating fun:

levering_of_verbruik:
  friendly_name_template: >
    {% if states('sensor.netto_verbruik')|int > 0 %} Verbruik
    {% else %} Levering
    {% endif %}
  icon_template: >
    {% if states('sensor.netto_verbruik')|int > 0 %} mdi:import
    {% else %} mdi:export
    {% endif %}
  value_template: >
    {{states('sensor.netto_verbruik')|int}}

sensor.netto_verbruik is taken directly from the smart meter.