-
Notifications
You must be signed in to change notification settings - Fork 7
/
case3-final.yaml
56 lines (55 loc) · 2 KB
/
case3-final.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
type: vertical-stack
cards:
- type: markdown
content: >-
**Question**: How can I format sensor.time from military to standard (AM-PM).
[Reference](https://github.com/ExperienceLovelace/ha-floorplan/discussions/302)
title: Case 3
- type: custom:floorplan-card
full_height: false
config:
stylesheet: /local/floorplan/discussions/case3/case3.css
image: /local/floorplan/discussions/case3/case3.svg
console_log_level: debug
defaults:
hover_action: hover-info
tap_action: more-info
rules:
# Reload button
- element: button.reload
tap_action:
action: fire-dom-event
browser_mod:
service: browser_mod.javascript
data:
code: lovelace_reload();
# Original value
- name: OriginalClockValue
element: customprefix.text3
entities:
- sensor.time_fake
state_action:
- service: floorplan.text_set
service_data: ${"Original:" + " " + entity.state}
# Case - Short Version
- name: ConvertClockToAmPmShort
element: customprefix.text1
entities:
- sensor.time_fake
state_action:
- service: floorplan.text_set
service_data: ${util.date.strftime('%I:%M %p', new Date("1970-01-01 " + entity.state))}
# Case - Normal Version
- name: ConvertClockToAmPm
element: customprefix.text2
entities:
- sensor.time_fake
state_action:
- service: floorplan.text_set
service_data:
text: |
>
console.log(entity.state);
const dateTimeString = "1970-01-01 " + entity.state // You'll need to provide a date string to new Date()
const dateTimeParsed = new Date(dateTimeString); // New date object created here
return util.date.strftime('%I:%M %p', dateTimeParsed);