-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblueprint-2.9-trivia.yaml
164 lines (151 loc) · 5.31 KB
/
blueprint-2.9-trivia.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
blueprint:
name: API Ninja Tags - Trivia
description: >
Show a trivia question every hour, with the answer only being revealed after 30 minutes! The answer only reveals on the second half hour of every question.... you have 30 minutes to guess on the hour before the tag updates!
### Requirements:
- The [OpenEpaperLink HA Integration](https://github.com/OpenEPaperLink/Home_Assistant_Integration).
- An [API Ninjas API Key](https://api-ninjas.com/register). it's free!
### Installation:
- Add the [rest sensor](https://github.com/chunkysteveo/OpenEPaperLink-HA-API-Ninja-Tags/blob/main/ha-configuration.yaml) to your home assistant configuration file and replace `'YOUR_SECRET_KEY_FROM_API_NINJAS'` with your API key (or set it in your secrets file)
- Reload HA.
- Select the tag(s) you want to display the Questions on.
### Customizing:
- For a nicer font add [`GothamRnd-Bold.ttf`](https://github.com/chunkysteveo/OpenEPaperLink-HA-API-Ninja-Tags/raw/refs/heads/main/GothamRnd-Bold.ttf) and set the path in the optional font file field.
domain: automation
input:
displays:
name: E-Paper Displays
description: One or more ESLs
selector:
device:
filter:
- integration: open_epaper_link
optional:
name: Optional
icon: "mdi:cog"
collapsed: true
input:
font_file:
name: Font file
description: Font file with path
default: ppb.ttf
selector:
text: {}
time_pattern:
name: Time Pattern
description: When to trigger this automation
default: "/30"
selector:
text: {}
trigger:
- trigger: time_pattern
minutes: !input time_pattern
variables:
font_file: !input font_file
action:
- action: open_epaper_link.drawcustom
alias: Draw trivia
target:
device_id: !input displays
data:
background: white
rotate: 0
payload:
- type: icon
value: message-question
x: 1
"y": 1
size: 32
color: red
- type: text
value: >-
{% set topic_object = {
"artliterature": "Art & Literature",
"language": "Language",
"sciencenature": "Science & Nature",
"general": "General Knowledge",
"fooddrink": "Food & Drink",
"peopleplaces": "People & Places",
"geography": "Geography",
"historyholidays": "History & Holidays",
"entertainment": "Entertainment",
"toysgames": "Toys & Games",
"music": "Music",
"mathematics": "Mathematics",
"religionmythology": "Religion & Mythology",
"sportsleisure": "Sports & Leisure",
"question": "Question",
"": "Trivia"
} %} {% set topic_key =
state_attr('sensor.api_ninja_trivia','category') | string |
default("question") %} {{topic_object[topic_key]}}
font: "{{ font_file }}"
x: 35
"y": >-
{% set cat_len = state_attr('sensor.api_ninja_trivia','question') |
length | int %} {{ 1 if cat_len < 16 else 7 | int }}
size: >-
{% set cat_len = state_attr('sensor.api_ninja_trivia','question') |
length | int %} {{ 30 if cat_len < 16 else 23 | int }}
color: red
# anchor: lt
y_padding: 0
spacing: 2
- type: text
value: "{{state_attr('sensor.api_ninja_trivia','question') | string }}"
font: "{{ font_file }}"
x: 15
"y": 38
size: >-
{% set string_len = state_attr('sensor.api_ninja_trivia','question')
| length | int %} {% if string_len <= 50 %}
22
{% elif string_len <= 60 %}
18
{% elif string_len <= 100 %}
16
{% elif string_len <= 150 %}
12
{% elif string_len <= 200 %}
10
{% else %}
8
{% endif %}
color: black
# anchor: lt
max_width: 266
y_padding: 0
spacing: 2
- type: text
value: |-
{% if now().minute < 30 %}
...???
{% else %}
{{state_attr('sensor.api_ninja_trivia','answer') | string }}
{% endif %}
font: "{{ font_file }}"
x: 5
size: |-
{% if now().minute < 30 %}
28
{% else %}
{% set string_len = state_attr('sensor.api_ninja_trivia','answer') | length | int %}
{% if string_len <= 20 %}
28
{% elif string_len <= 50 %}
20
{% elif string_len <= 60 %}
18
{% elif string_len <= 100 %}
16
{% elif string_len <= 150 %}
12
{% else %}
8
{% endif %}
{% endif %}
color: red
# anchor: lt
max_width: 291
y_padding: 8
spacing: 2