forked from lolouk44/homeassistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cheat Sheet.yaml
executable file
·106 lines (87 loc) · 5.21 KB
/
Cheat Sheet.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Add travel time to next bus time (https://community.home-assistant.io/t/adding-two-time-based-sensors/68267)
# Get a time string that contains todays date and the next bus time
{% set nextbus = "08:35" %}
{% set time_string = now().strftime("%Y-%m-%d ")+nextbus %}
# Convert that to a time_string into a datetime object and get the current time in seconds
{% set next_bus_time = strptime(time_string,"%Y-%m-%d %H:%M").timestamp() %}
# get the estimated bus route time in seconds
{% set trip_time = (states('sensor.home_to_work') | int * 60) %}
# Add the bus time and the trip time, return the estimated arrival time
{{ ( next_bus_time + trip_time ) | timestamp_custom("%H:%M") }}
#count how many lights are on:
{% set lights = [
states.light.kitchen_lights,
states.light.living_room_main,
states.light.conservatory,
states.light.staircase ] %}
{% set lights_on = lights | selectattr('state','eq','on') | list %}
{{ lights_on | length }} of {{ lights | length }} lights are on.
{%- macro bigCarList() %}
{%- set value_json = state_attr('image_processing.tensorflow_pruebas_calle', 'matches') %}
{%- for car in value_json.car %}
{{- (car.box[3] - car.box[1]) > 0.4 }}{{ '' if loop.last else ',' }}
{%- endfor %}
{%- endmacro %}
{{ bigCarList().split(',') | reject('eq','False') | list | count}}
This makes a macro that returns a string of true/falses. I.E. 'True,False,True,False,False'. Then it splits the string on the comma to get a list of strings. I.E. ['True','False','True','False','False']. After that, it rejects any string in the list that is equal to false. So we end up with a shorter list of just trues. I.E. ['True','True']. Lastly, we count the number of items in the list, which will be the number of times that this statement returned true (car.box[3] - car.box[1]) > 0.4
{% set last_triggered = states.sensor.wfc_thermo.attributes.last_triggered %}
{% set time_since = as_timestamp(now()) - as_timestamp(last_triggered) %}
{% macro phrase(value, name) %}
{%- set value = value | int %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{%- if (as_timestamp(now()) | timestamp_custom('%m',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%m',true) | int) > 0 -%}
{{ phrase((as_timestamp(now()) | timestamp_custom('%m',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%m',true) | int) , 'month')}},
{%- endif -%}
{%- if (as_timestamp(now()) | timestamp_custom('%d',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%d',true) | int) > 0 -%}
{{ phrase((as_timestamp(now()) | timestamp_custom('%d',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%d',true) | int) , 'day')}},
{%- endif -%}
{%- if (as_timestamp(now()) | timestamp_custom('%H',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%H',true) | int) > 0 -%}
{{ phrase((as_timestamp(now()) | timestamp_custom('%H',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%H',true) | int) , 'hour')}},
{%- endif -%}
{%- if (as_timestamp(now()) | timestamp_custom('%M',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%M',true) | int) > 0 -%}
{{ phrase((as_timestamp(now()) | timestamp_custom('%M',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%M',true) | int) , 'minute')}},
{%- endif -%}
{%- if (as_timestamp(now()) | timestamp_custom('%S',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%S',true) | int) > 0 -%}
{{ phrase((as_timestamp(now()) | timestamp_custom('%S',true) | int) - (as_timestamp(last_triggered) | timestamp_custom('%S',true) | int) , 'second')}} ago
{%- endif -%}
apple_watch_people_at_home:
friendly_name: Apple Watch People At Home
value_template: >-
{% if states.sensor.gigz_smart_location.state == "Home" and states.sensor.iryna_smart_location.state == "Home" %}
👫
{% elif states.sensor.gigz_smart_location.state == "Home" %}
🧍♂️
{% elif states.sensor.iryna_smart_location.state == "Home" %}
🧍♀️
{% else %}
🔒
{% endif %}
apple_watch_home_mode:
friendly_name: Apple Watch Home Mode
value_template: >-
{% if states.sensor.home_mode.state == "Morning" or states.sensor.home_mode.state == "Away Morning" %}
☕️
{% elif states.sensor.home_mode.state == "Home" or states.sensor.home_mode.state == "Away" %}
☀️
{% elif states.sensor.home_mode.state == "Evening" or states.sensor.home_mode.state == "Away Evening" %}
🌙
{% else %}
💤
{% endif %}
apple_watch_home_health_alert:
friendly_name: Apple Watch Home Health Alert
value_template: >-
{% if states.sensor.smart_home_health.state == "Attention Needed" %}
⚠️
{% endif %}
apple_watch_packages_progress:
friendly_name: Apple Watch Packages Progress
icon_template: "mdi:package-variant-closed"
value_template: >-
{% if states.sensor.mail_amazon_packages.state | int == 0 %}
1.0
{% else %}
{{ (states.sensor.mail_amazon_packages_delivered.state | float) / (states.sensor.mail_amazon_packages.state | float) }}
{% endif %}