Skip to content

Commit

Permalink
Add parameter for precision
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFes committed Oct 23, 2023
1 parent 4ac1d68 commit 4dab3e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Optional parameters are listed below:
|---|---|---|---|---|
|`lowest`|boolean|`true`|`false`|Boolean to select if the marco should find the lowest price, set to `false` to find the highest price|
|`mode`|string|`"start"`|`"average"`|see [seperate section](#output-modes)|
|`precision`|integer|`5`|`2`|The number of decimals used for the price output|
|`look_ahead`|boolean|`false`|`true`|When set to true, only the hours as of the current hour are taken into account. This overrides the `start` time if that time is earlier than the current hour.
|`time_format`|string|`none`|`"time24"`|You can use `time12` for the 12-hour format including `AM` or `PM`, `time24` for the 24-hour format, or any custom format using the variables from the python strftime method ([cheatsheet](https://strftime.org))
|`value_on_error`|any|error description|`as_datetime('2099-12-31)`|You can optionally provide a value to be outputted in case there is an error. This can be useful if you eg want it to use as state in a template sensor which has `device_class: timestamp` which will run in error if the state value is not as expected. Or if you output the data on your dashboard in a markup card and want to provide your own message.
Expand Down
13 changes: 7 additions & 6 deletions cheapest_energy_hours.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
include_tomorrow=false,
lowest=true,
look_ahead=false,
precision=5,
no_weight_points=1,
weight=none,
program=none,
Expand Down Expand Up @@ -229,15 +230,15 @@
{%- set b = output.weighted_average -%}
{%- set min, max = list | min, list | max -%}
{%- if output.average is none or ((a < b) if lowest else (a > b)) -%}
{%- set output.list = list -%}
{%- set output.min = min | round(5) -%}
{%- set output.max = max | round(5) -%}
{%- set pr = precision | default(5) -%}
{%- set output.list = list | map('round', pr) | list -%}
{%- set output.min = min | round(pr) -%}
{%- set output.max = max | round(pr) -%}
{%- set output.weighted_average = a | round(5) -%}
{%- set output.average = list | average | round(5) -%}
{%- set output.average = list | average | round(pr) -%}
{%- set output.start = _format_date(values[i].time, time_format | default(none)) -%}
{%- set output.end = _format_date(values[i].time + timedelta(hours=h), time_format | default(none)) -%}
{%- set index_min = output.list.index(output.min) -%}
{%- set index_max = output.list.index(max) -%}
{%- set index_min, index_max = list.index(min), list.index(max) -%}
{%- set output.time = values[i:i+last_values] | map(attribute='time') | list -%}
{%- set output.time_min = _format_date(output.time[index_min], time_format | default(none)) -%}
{%- set output.time_max = _format_date(output.time[index_max], time_format | default(none)) -%}
Expand Down

0 comments on commit 4dab3e7

Please sign in to comment.