TheFes / cheapest-energy-hours

Jinja macro to find the cheapest energy prices
GNU General Public License v3.0
85 stars 9 forks source link

how do I get this to run every 15 minutes #130

Closed rhgiter closed 5 months ago

rhgiter commented 8 months ago
 - trigger:
      -  platform: time
         at:
           - '13:28'
           - '13:58'
           - '15:28'
           - '18:25'
           - '19:28'
           - '20:28'
           - '21:28'
    sensor:
      - unique_id: f8853830-opva
        name: Opvaskemaskine Start Tid aften og nat
        device_class: timestamp
        state: >
          {%- set sensor = 'sensor.energi_data_service' -%}
          {% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=3.5, start='21:00', end='06:00', include_tomorrow=true, look_ahead=true) `}}
TheFes commented 8 months ago

Why would you want to update it every 15 minutes? What's your goal here?

rhgiter commented 8 months ago

if the cheapest hour for my dishwasher starts at 22:00 and i set it to pause mode at 22:01 your programit starts 22:30, and then it would be better 22:15 or ex, 22.05

TheFes commented 8 months ago

just add setting the dishwasher to pause mode as an additional trigger

rhgiter commented 8 months ago

how ? with the above I get at sensor with the time stamp when dishwasher starts at the cheapest point (name: Opvaskemaskine Start Tid aften og nat) and my automation start at that time

TheFes commented 8 months ago

You are using a trigger based template sensor. You can add any trigger you can use in an automation as well.

I assume your dishwasher has some mode which allows it to be started automatically. That state will be shown in HA in some sensor provided by the dishwasher integration. You can add that state change as a trigger to the trigger section of the sensor

rhgiter commented 8 months ago

no I use a plug to turn the dishwasher on / off

Den ons. 6. mar. 2024 kl. 08.04 skrev Martijn van der Pol < @.***>:

You are using a trigger based template sensor. You can add any trigger you can use in an automation as well.

I assume your dishwasher has some mode which allows it to be started automatically. That state will be shown in HA in some sensor provided by the dishwasher integration. You can add that state change as a trigger to the trigger section of the sensor

— Reply to this email directly, view it on GitHub https://github.com/TheFes/cheapest-energy-hours/issues/130#issuecomment-1980215572, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOR4UGCAKTWYOO27F5XQVFDYW25XPAVCNFSM6AAAAABEHZ2XESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBQGIYTKNJXGI . You are receiving this because you authored the thread.Message ID: @.***>

TheFes commented 8 months ago

Then trigger on that plug turning off

TheFes commented 8 months ago

Do you have it working now?

rhgiter commented 8 months ago

No, because I cant make a condition that checks if it in the cheapest hours.

alias: opvaskemaskine billigste periode nat (4) tænd Nordpool .
description: ""
trigger:
  - platform: time
    at: sensor.opvaskemaskine_start_tid_aften_og_nat
condition:
  - condition: state
    entity_id: switch.opvaskemaskine
    state: "off"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.opvaskemaskine
mode: restart
TheFes commented 8 months ago

Template sensor

 - trigger:
      -  platform: time
         at:
           - '18:25'
           - '19:28'
           - '20:28'
           - '20:59'
      - platform: state
        entity_id: switch.opvaskemaskine
        to: "off"
    sensor:
      - unique_id: f8853830-opva
        name: Opvaskemaskine Start Tid aften og nat
        device_class: timestamp
        state: >
          {%- set sensor = 'sensor.energi_data_service' -%}
          {% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=3.5, start='21:00', end='06:00', include_tomorrow=true, look_ahead=true) `}}

That should work in combination with your automation (unless you turn the switch off after midnight)

rhgiter commented 8 months ago

Thanks i was doing it my ui automation. I will try this - Thanks :-)

rhgiter commented 8 months ago

it dont work image

image

same

image

TheFes commented 8 months ago

Please don't paste images of code. Place the code itself and use code tags so the right formatting is applied. In your top screenshot the indentation is wrong. The second trigger should be indented the same as the time trigger.

Why are you using so many times to reload the template? And if it should start between 6:00 and 17:00 I would not suggest to refresh it anymore after 6:00

The second example looks correct and should not give the same error.

rhgiter commented 8 months ago

I think i have put the code in the right place. now i will check if it works soon. i have to refresh it more than one time, because dishwasher and washine machine runs maybe 2 or more a day

TheFes commented 8 months ago

The state trigger using the switch will already achieve that

rhgiter commented 8 months ago

sorry , but it dont work. it only turns on ex. 13:30 14.00 14.30 not after 5 minutes

TheFes commented 8 months ago

Not sure what you mean here? Why should it turn on after 5 minutes?

rhgiter commented 8 months ago

Not sure what you mean here? Why should it turn on after 5 minutes?

If the cheapest hour is between 13.00 and 14.00 , and I turn off my dishwasher 13.01 (so it will be ready to start at the cheapest hour) - then It would be great if it starts 13.05 (now it turns on 13.30)

TheFes commented 8 months ago

It should do that.

rhgiter commented 8 months ago

but it dont work , when i testet it

  - trigger:
      -  platform: time
         at:
           - '05:58'
           - '06:28'
           - '06:58'
           - '07:28'
           - '07:58'
           - '08:28'
           - '08:58'
           - '09:28'
           - '09:58'
           - '10:28'
           - '10:58'
           - '11:28'
           - '11:58'
           - '12:28'
           - '12:58'
           - '13:28'
           - '13:58'
           - '14:28'
           - '14:58'
           - '15:28'
           - '15:58'

      -  platform: state
         entity_id: switch.vaskemaskine
         to: "off"

    sensor:
      - unique_id: f8853830-1
        name: Vaskemaskine 1 Start Tid dag
        device_class: timestamp
        state: >
          {%- set sensor = 'sensor.energi_data_service' -%}
          {% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=1, start='06:00', end='17:00', look_ahead=true) }}  
TheFes commented 8 months ago

can you send me the output of this:

{%- set sensor = 'sensor.energi_data_service' -%}
{% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
{{ cheapest_energy_hours(sensor=sensor, hours=1, start='06:00', end='17:00', look_ahead=true, debug=true) }} 
rhgiter commented 8 months ago

{"version":"5.4.1","output":"2024-03-14T13:00:00+01:00","error":false,"non_default_user_input":{"sensor":"sensor.energi_data_service","hours":1.0,"start":"06:00","end":"17:00","look_ahead":true},"set_by_macro":{"start":"2024-03-14T10:05:14+01:00","end":"2024-03-14T17:00:00+01:00","time_key":"hour","value_key":"price","no_weight_points":2},"defaults_used":{"value_on_error":null,"attr_today":"raw_today","attr_tomorrow":"raw_tomorrow","attr_all":"prices","datetime_in_data":true,"data_minutes":60,"mode":"start","time_format":null,"include_today":true,"include_tomorrow":false,"lowest":true,"latest_possible":false,"price_tolerance":0,"precision":5,"price_factor":1,"weight":null,"kwh":null,"program":null,"plot_sensor":"sensor.energy_plots","plot_attr":"energy_plots","split":false},"data_used":{"today_count":24,"tomorrow_count":0,"all_count":0,"data_count":24,"values_count":13,"datapoints_source":{"datapoints":1,"datapoints_hour":1},"datapoints_used":{"datapoints":2,"datapoints_hour":2.0}}}````
TheFes commented 8 months ago

I did find a bug in how the start times were determined, that might be reason why it wasn't working properly. This is fixed in v5.4.2. which I just released. Possibly this will fix your issue as well.

rhgiter commented 8 months ago

perfect .-) I will try it later - I will give you feedback

edit

it worked 14.05 but not 14.10 and 14.15 image

TheFes commented 8 months ago

Not sure what I'm looking at here. Is this the switch? Or the binary sensor?

TheFes commented 8 months ago

Please let me know if this is correct.

Is that correct?

rhgiter commented 8 months ago

Not sure what I'm looking at here. Is this the switch? Or the binary sensor?

I will only show you that the plug for washing machine turned on 14.05 but not 14.10 and 14.15

rhgiter commented 8 months ago

Please let me know if this is correct.

  • You have a "dumb" dishwasher/washing machine behind a smart plug.
  • You want to schedule turning on these devices based on the cheapest time window by starting the device, then turning the smart plug off and turning the plug on again when the energy is cheapest
  • You want to do this within a certain time frame (so eg between 6:00 and 17:00)

Is that correct?

That thats all correct.

TheFes commented 8 months ago

And how is that plug turned on? I've only seen the YAML config for the template sensor giving the best time. What is your automation to turn that switch on?

rhgiter commented 8 months ago

I use the entity your script make

description: ""
trigger:
  - platform: time
    at: sensor.vaskemaskine_1_start_tid_dag
condition:
  - condition: state
    entity_id: input_select.vaskemaskine_1_2_3_4_timer
    state: "1"
  - condition: state
    entity_id: switch.vaskemaskine
    state: "off"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.vaskemaskine
  - service: input_select.set_options
    data:
      options: 0
    target:
      entity_id: input_select.vaskemaskine_1_2_3_4_timer
mode: restart
TheFes commented 8 months ago

okay, there is nothing there turning the switch off. What switched it off again after 1 minute

TheFes commented 8 months ago

or was that for testing purposes?

TheFes commented 8 months ago

and what does the input_select do?

rhgiter commented 8 months ago

okay, there is nothing there turning the switch off. What switched it off again after 1 minute

I turn the machine off with a button

rhgiter commented 8 months ago

and what does the input_select do?

I have a button where I can select the washing time 1 - 2 - 3 - 4 hours. and 4 automations as the above so it is the cheapest 1,2,3 or 4 hours.

TheFes commented 8 months ago

I would suggest to try this:

Template sensor

  - trigger:
      -  platform: state
         entity_id: switch.vaskemaskine
         to: ~
    sensor:
      - unique_id: f8853830-1
        name: Vaskemaskine 1 Start Tid dag
        device_class: timestamp
        state: >
          {%- set sensor = 'sensor.energi_data_service' -%}
          {% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=1, start='06:00', end='17:00', look_ahead=true) }}
        availability: "{{ is_state('switch.vaskemaskine', 'off') }}"

Automation:

description: ""
trigger:
  - platform: time
    at: sensor.vaskemaskine_1_start_tid_dag
condition:
  - condition: state
    entity_id: input_select.vaskemaskine_1_2_3_4_timer
    state: "1"
action:
  - service: switch.turn_on
    target:
      entity_id:
        - switch.vaskemaskine
  - service: input_select.set_options
    data:
      options: 0
    target:
      entity_id: input_select.vaskemaskine_1_2_3_4_timer
mode: single
rhgiter commented 8 months ago

ok Thanks, I will try later

rhgiter commented 8 months ago

I would suggest to try this:

Template sensor

  - trigger:
      -  platform: state
         entity_id: switch.vaskemaskine
         to: ~
    sensor:
      - unique_id: f8853830-1
        name: Vaskemaskine 1 Start Tid dag
        device_class: timestamp
        state: >
          {%- set sensor = 'sensor.energi_data_service' -%}
          {% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=1, start='06:00', end='17:00', look_ahead=true) }}
        availability: "{{ is_state('switch.vaskemaskine', 'off') }}"

Automation:

description: ""
trigger:
  - platform: time
    at: sensor.vaskemaskine_1_start_tid_dag
condition:
  - condition: state
    entity_id: input_select.vaskemaskine_1_2_3_4_timer
    state: "1"
action:
  - service: switch.turn_on
    target:
      entity_id:
        - switch.vaskemaskine
  - service: input_select.set_options
    data:
      options: 0
    target:
      entity_id: input_select.vaskemaskine_1_2_3_4_timer
mode: single

Hi , I have tested it , but it dont work, turn on once , but no again ;-/

TheFes commented 8 months ago

That doesn't tell me much. How does the history of the template sensor look?

TheFes commented 5 months ago

Closing this issue due to lack of response