diff --git a/README.md b/README.md index 35a780e..dfebaa6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/cheapest_energy_hours.jinja b/cheapest_energy_hours.jinja index e29fd31..d486464 100644 --- a/cheapest_energy_hours.jinja +++ b/cheapest_energy_hours.jinja @@ -50,6 +50,7 @@ include_tomorrow=false, lowest=true, look_ahead=false, + precision=5, no_weight_points=1, weight=none, program=none, @@ -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)) -%}