Actions
Homeassistant¶
mp3tag¶
File rename rule voor multi cd's:
\\vault\media\music\%albumartist%\%album%\$ifgreater(discnumber,0,CD$left(discnumber,1),)\$num(track,2)-%title%
File rename rule voor single cd:
\\vault\media\music\%albumartist%\%album%\$num(track,2)-%title%
Vaatwasser starten op goedkoopste moment¶
alias: Vaatwasser auto aan
description: ""
triggers:
- type: not_opened
device_id: 80425a2fa2441ab46768d855af2ca66e
entity_id: d12a79d30e6e2a46f534677621f7f21d
domain: binary_sensor
trigger: device
conditions:
- type: is_on
condition: device
device_id: 80425a2fa2441ab46768d855af2ca66e
entity_id: 333a5fa27d684030aa4c4a02ef5721e0
domain: binary_sensor
actions:
- action: select.select_option
metadata: {}
data:
option: >
{# Configuration and Setup #} {% set prices =
state_attr('sensor.electricity_prices', 'prices') or [] %} {% set
window_size = 3 %} {% set end_time_hour = 6 %} {% set now_dt = now() %}
{# The time against which price constraints are checked (rounded down to
the nearest hour) #} {% set hour_check_dt = now_dt.replace(minute=0,
second=0, microsecond=0) %}
{# Initialize variables #} {% set ns = namespace(min_price_sum=99999,
best_start_dt=none) %}
{% if prices | length >= window_size %}
{% for i in range(prices | length - window_size + 1) %}
{% set current_window = prices[i:i + window_size] %}
{# Convert the price timestamp to a datetime object #}
{% set start_dt = as_datetime(current_window[0].timestamp) %}
{% set end_dt = as_datetime(current_window[-1].timestamp) + timedelta(hours=1) %}
{# Constraints Check (Start must be NOW or later, End must be <= 6AM) #}
{% if start_dt >= hour_check_dt and end_dt.hour <= end_time_hour %}
{% set current_sum = current_window | map(attribute='price') | map('float', 0) | sum %}
{% if current_sum < ns.min_price_sum %}
{% set ns.min_price_sum = current_sum %}
{% set ns.best_start_dt = start_dt %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{# Final Output: Calculate, round, and format the relative minute
difference #} {% if ns.best_start_dt is not none %}
{# Calculate the time difference in seconds from current time (now_dt) to the start of the best whole hour (best_start_dt) #}
{% set total_minutes_float = (ns.best_start_dt - now_dt).total_seconds() / 60 %}
{# Core Logic: Round to the nearest 30 minutes #}
{% set rounded_minutes = ((total_minutes_float / 30) | round(0) * 30) | int(0) %}
{% set hours = (rounded_minutes / 60) | int(0) %}
{% set minutes = (rounded_minutes % 60) | int(0) %}
{# Format as HH:MM string #}
{{ "%d:%02d" | format(hours, minutes) }}
{% else %}
{# Fallback to "0:00" (Start Now) #}
"0:00"
{% endif %}
target:
entity_id: select.011020388881000662_bsh_common_option_startinrelative
- device_id: 80425a2fa2441ab46768d855af2ca66e
domain: button
entity_id: e4f5abe989bc54eb50887e631509c5d0
type: press
mode: single
20 dagen geleden bijgewerkt door Micha Kersloot · 3 revisions