Project

Algemeen

Profiel

Homeassistant » Geschiedenis » Versie 3

Micha Kersloot, 06-11-2025 09:48

1 1 Micha Kersloot
h1. Homeassistant
2
3
h2. mp3tag
4
5 2 Micha Kersloot
File rename rule voor multi cd's:
6 1 Micha Kersloot
7
  \\vault\media\music\%albumartist%\%album%\$ifgreater(%discnumber%,0,CD$left(%discnumber%,1),)\$num(%track%,2)-%title%
8 2 Micha Kersloot
9
File rename rule voor single cd:
10
11
  \\vault\media\music\%albumartist%\%album%\$num(%track%,2)-%title%
12 3 Micha Kersloot
13
h2. Vaatwasser starten op goedkoopste moment
14
15
<pre><code class="yaml">
16
alias: Vaatwasser auto aan
17
description: ""
18
triggers:
19
  - type: not_opened
20
    device_id: 80425a2fa2441ab46768d855af2ca66e
21
    entity_id: d12a79d30e6e2a46f534677621f7f21d
22
    domain: binary_sensor
23
    trigger: device
24
conditions:
25
  - type: is_on
26
    condition: device
27
    device_id: 80425a2fa2441ab46768d855af2ca66e
28
    entity_id: 333a5fa27d684030aa4c4a02ef5721e0
29
    domain: binary_sensor
30
actions:
31
  - action: select.select_option
32
    metadata: {}
33
    data:
34
      option: >
35
        {# Configuration and Setup #} {% set prices =
36
        state_attr('sensor.electricity_prices', 'prices') or [] %} {% set
37
        window_size = 3 %} {% set end_time_hour = 6 %} {% set now_dt = now() %}
38
39
        {# The time against which price constraints are checked (rounded down to
40
        the nearest hour) #} {% set hour_check_dt = now_dt.replace(minute=0,
41
        second=0, microsecond=0) %}
42
43
        {# Initialize variables #} {% set ns = namespace(min_price_sum=99999,
44
        best_start_dt=none) %}
45
46
        {% if prices | length >= window_size %}
47
          {% for i in range(prices | length - window_size + 1) %}
48
            {% set current_window = prices[i:i + window_size] %}
49
            
50
            {# Convert the price timestamp to a datetime object #}
51
            {% set start_dt = as_datetime(current_window[0].timestamp) %}
52
            {% set end_dt = as_datetime(current_window[-1].timestamp) + timedelta(hours=1) %}
53
            
54
            {# Constraints Check (Start must be NOW or later, End must be <= 6AM) #}
55
            {% if start_dt >= hour_check_dt and end_dt.hour <= end_time_hour %}
56
              
57
              {% set current_sum = current_window | map(attribute='price') | map('float', 0) | sum %}
58
59
              {% if current_sum < ns.min_price_sum %}
60
                {% set ns.min_price_sum = current_sum %}
61
                {% set ns.best_start_dt = start_dt %}
62
              {% endif %}
63
            {% endif %}
64
          {% endfor %}
65
        {% endif %}
66
67
        {# Final Output: Calculate, round, and format the relative minute
68
        difference #} {% if ns.best_start_dt is not none %}
69
          {# Calculate the time difference in seconds from current time (now_dt) to the start of the best whole hour (best_start_dt) #}
70
          {% set total_minutes_float = (ns.best_start_dt - now_dt).total_seconds() / 60 %}
71
          
72
          {# Core Logic: Round to the nearest 30 minutes #}
73
          {% set rounded_minutes = ((total_minutes_float / 30) | round(0) * 30) | int(0) %}
74
          
75
          {% set hours = (rounded_minutes / 60) | int(0) %}
76
          {% set minutes = (rounded_minutes % 60) | int(0) %}
77
          
78
          {# Format as HH:MM string #}
79
          {{ "%d:%02d" | format(hours, minutes) }}
80
        {% else %}
81
          {# Fallback to "0:00" (Start Now) #}
82
          "0:00"
83
        {% endif %}
84
    target:
85
      entity_id: select.011020388881000662_bsh_common_option_startinrelative
86
  - device_id: 80425a2fa2441ab46768d855af2ca66e
87
    domain: button
88
    entity_id: e4f5abe989bc54eb50887e631509c5d0
89
    type: press
90
mode: single
91
92
</code></pre>