Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *******************Power Saver Fix efter 15 minuters elpriser********************
- OBS!! kopiera endast koden, ta inte med alla mina **********rubriker*********** och *************kommentarer*****************
- **************** Template sensorer ***************************
- **************** Sensor för powersaver uppdaterad för att använda mina nya nordpool template sensorer ***************
- template:
- - binary_sensor:
- - name: Power saver
- unique_id: powersaver
- device_class: problem
- state: >
- {{ not (this.attributes.schedule | selectattr("current") | map(attribute="onOff") | first | default(true)) }}
- attributes:
- schedule: >
- {% set data = namespace(schedule_items=[], activated=0) %}
- {# --- Part 1: Process Today's Data --- #}
- {% set today_prices = state_attr("sensor.today_lowest_price", "data") or [] %}
- {% if today_prices | length > 0 %}
- {% set data.activated = states("input_number.power_min_hours_on") | int(10) * 4 %}
- {% set minperc = (states("input_number.power_percent_over_min") | int(15) + 100.0) / 100.0 %}
- {% set maxprice = states("input_number.power_max_price") | float(999) %}
- {% set sorted_today = today_prices | sort(attribute="price") %}
- {% set breakprice = minperc * sorted_today[0].price %}
- {% for s in sorted_today %}
- {% set onOff = (s.price <= breakprice or data.activated > 0) and s.price < maxprice %}
- {% set current = as_datetime(s.start) < now() and as_datetime(s.end) > now() %}
- {% set data.schedule_items = data.schedule_items + [{"price": s.price, "time": as_timestamp(s.start) | timestamp_local, "onOff": onOff, "current": current }] %}
- {% set data.activated = data.activated - (1 if onOff else 0) %}
- {% endfor %}
- {% endif %}
- {# --- Part 2: Process Tomorrow's Data --- #}
- {% set tomorrow_prices = state_attr("sensor.tomorrow_lowest_price", "data") or [] %}
- {% if tomorrow_prices | length > 0 %}
- {% set data.activated = states("input_number.power_min_hours_on") | int(10) * 4 %}
- {% set sorted_tomorrow = tomorrow_prices | sort(attribute="price") %}
- {% set breakprice = minperc * sorted_tomorrow[0].price %}
- {% for s in sorted_tomorrow %}
- {% set onOff = (s.price <= breakprice or data.activated > 0) and s.price < maxprice %}
- {% set current = false %}
- {% set data.schedule_items = data.schedule_items + [{"price": s.price, "time": as_timestamp(s.start) | timestamp_local, "onOff": onOff, "current": current }] %}
- {% set data.activated = data.activated - (1 if onOff else 0) %}
- {% endfor %}
- {% endif %}
- {# --- Final Step: Combine and Sort Chronologically --- #}
- {{ data.schedule_items | sort(attribute="time") | list }}
- ************************ template sensorer för dagens och morgondagens elpriser för norpools integration ***********************
- - trigger:
- - trigger: time_pattern
- minutes: /10
- - trigger: homeassistant
- event: start
- action:
- - action: nordpool.get_prices_for_date
- data:
- config_entry: 01K6BFF0TVKT3M3RDYTQWVM38D ****************OBS BYT TILL DIN CONFIG ENTERY********************
- date: "{{ now().date() + timedelta(days=1) }}"
- areas: SE3
- currency: SEK
- response_variable: tomorrow_price
- sensor:
- - name: Tomorrow lowest price
- unique_id: se3_tomorrow_low_price
- state: >
- {% set data = namespace(prices=[]) %}
- {% for state in tomorrow_price['SE3'] %}
- {% set data.prices = data.prices + [(state.price / 1000)] %}
- {% endfor %}
- {{min(data.prices)}}
- attributes:
- data: >
- {% set data = namespace(prices=[]) %}
- {% for state in tomorrow_price['SE3'] %}
- {# Denna rad är den enda som är ändrad #}
- {% set data.prices = data.prices + [{'start': (state.start | as_datetime | as_local).isoformat(), 'end': (state.end | as_datetime | as_local).isoformat(), 'price': state.price/1000}] %}
- {% endfor %}
- {{data.prices}}
- - trigger:
- - trigger: time_pattern
- minutes: /10
- - trigger: homeassistant
- event: start
- action:
- - action: nordpool.get_prices_for_date
- data:
- config_entry: 01K6BFF0TVKT3M3RDYTQWVM38D ****************OBS BYT TILL DIN CONFIG ENTERY********************
- date: "{{ now().date() }}"
- areas: SE3
- currency: SEK
- response_variable: today_price
- sensor:
- - name: Today lowest price
- unique_id: se3_today_low_price
- state: >
- {% set data = namespace(prices=[]) %}
- {% for state in today_price['SE3'] %}
- {% set data.prices = data.prices + [(state.price / 1000)] %}
- {% endfor %}
- {{min(data.prices)}}
- attributes:
- data: >
- {% set data = namespace(prices=[]) %}
- {% for state in today_price['SE3'] %}
- {# Denna rad är den enda som är ändrad #}
- {% set data.prices = data.prices + [{'start': (state.start | as_datetime | as_local).isoformat(), 'end': (state.end | as_datetime | as_local).isoformat(), 'price': state.price/1000}] %}
- {% endfor %}
- {{data.prices}}
- ************************* APEX kort kod ************************************
- type: custom:apexcharts-card
- update_interval: 11m
- graph_span: 1d
- header:
- show: true
- title: Power Saver Today
- apex_config:
- chart:
- type: area
- legend:
- show: false
- fill:
- type: gradient
- gradient:
- shadeIntensity: 0.1
- opacityFrom: 0.55
- opacityTo: 1
- inverseColors: true
- stops:
- - 0
- - 90
- - 100
- span:
- start: day
- offset: "-0d"
- now:
- show: true
- color: rgb(138,43,226)
- label: Now
- yaxis:
- - id: price
- decimals: 2
- min: "|-0.1|"
- max: "|+0.1|"
- apex_config:
- title:
- text: kr/kWh
- forceNiceScale: true
- - id: powersaver
- show: false
- min: 0
- max: 1
- series:
- - entity: sensor.today_lowest_price
- yaxis_id: price
- type: line
- color: rgb(128,128,128)
- data_generator: |
- return entity.attributes.data.map(d => {
- return [new Date(d.start), d.price];
- });
- name: Elpris
- curve: stepline
- stroke_width: 3
- - entity: binary_sensor.power_saver
- data_generator: |
- return entity.attributes.schedule.map((entry) => {
- return [new Date(entry.time), entry.onOff ? 1 : 0];
- });
- yaxis_id: powersaver
- name: " "
- type: area
- color: rgba(0, 255, 0, 0.2)
- opacity: 0.1
- stroke_width: 0
- curve: stepline
- show:
- legend_value: false
- in_header: false
- name_in_header: false
- datalabels: false
Advertisement
Add Comment
Please, Sign In to add comment