Hello Community,
i’m struggeling to get a card change on specific time. I have the following code for a custom card (it’s from this thread https://www.reddit.com/r/homeassistant/comments/n1ci34/latest_dashboard_check_out_my_car_telemetry_card/, really nice and thanks @makeitttwork).
type: 'custom:vertical-stack-in-card'
cards:
- type: markdown
content: '<ha-icon icon="mdi:account-multiple"></ha-icon> Family'
style: |
ha-card {
#background: rgba(0,0,0,0);
font-size: 20px;
}
- type: horizontal-stack
cards:
- type: 'custom:button-card'
entity: person.mad
aspect_ratio: 4/4
show_name: false
show_icon: false
styles:
card:
- padding: 4%
- background-image: url("/local/xxx.png")
- background-size: 99%
- background-repeat: no-repeat
- background-position: top center
custom_fields:
location:
- text-transform: capitalize
- position: absolute
- left: 4%
- top: 4%
- color: >-
[[[ if (states["device_tracker.sm_g973f"].state == "not_home")
return "#e45649"; else return "#50A14F"; ]]]
battery:
- align-self: right
- position: absolute
- right: 4%
- top: 4%
- color: >-
[[[ if (states["sensor.sm_g973f_akkufullstand"].state <= 30)
return "#e45649"; if
(states["sensor.sm_g973f_akkufullstand"].state <= 50) return
"#ffa229"; else return "#50A14F"; ]]]
custom_fields:
location: |
[[[
if (states["device_tracker.sm_g973f"].state == "not_home")
return `<ha-icon
icon="mdi:home-export-outline"
style="width: 22px; height: 22px;">
</ha-icon>`
else
return `<ha-icon
icon="mdi:home"
style="width: 22px; height: 22px;">
</ha-icon>`
]]]
battery: |
[[[
return `<ha-icon
icon="mdi:battery"
style="width: 20px; height: 20px;"></ha-icon
<span>${states['sensor.sm_g973f_akkufullstand'].state}%</span>`
]]]
- type: 'custom:button-card'
entity: person.xxx
aspect_ratio: 4/4
show_name: false
show_icon: false
styles:
card:
- padding: 4%
- background-image: url("/local/xxx.png")
- background-size: 99%
- background-repeat: no-repeat
- background-position: top center
custom_fields:
location:
- text-transform: capitalize
- position: absolute
- left: 4%
- top: 4%
- color: >-
[[[ if (states["device_tracker.sm_g960f"].state == "not_home")
return "#e45649"; else return "#50A14F"; ]]]
battery:
- align-self: right
- position: absolute
- right: 4%
- top: 4%
- color: >-
[[[ if (states["sensor.sm_g960f_akkufullstand"].state <= 30)
return "#e45649"; if
(states["sensor.sm_g960f_akkufullstand"].state <= 50) return
"#ffa229"; else return "#50A14F"; ]]]
custom_fields:
location: |
[[[
if (states["device_tracker.sm_g960f"].state == "not_home")
return `<ha-icon
icon="mdi:home-export-outline"
style="width: 22px; height: 22px;">
</ha-icon>`
else
return `<ha-icon
icon="mdi:home"
style="width: 22px; height: 22px;">
</ha-icon>`
]]]
battery: |
[[[
return `<ha-icon
icon="mdi:battery"
style="width: 20px; height: 20px;"></ha-icon
<span>${states['sensor.sm_g960f_akkufullstand'].state}%</span>`
]]]
- type: map
entities:
- device_tracker.google_maps_xxxxxxxxxxxxxxxxxxxxxxx
- device_tracker.google_maps_xxxxxxxxxxxxxxxxxxxxxxx
dark_mode: >-
[[[ if (states["sensor.time_hour_formatted"].state <= 7)
return "true"; if
(states["sensor.time_hour_formatted"].state >= 20) return
"true"; else return "false"; ]]]
I want to change the dark mode depending on the time. sensor.time_hour_formatted is the actual hour (from 0-24), and the code after dark_mode: is from me thinking it should be like this (derived from the code above from makeitttwork). But it doesn’t work.
I’m not really good in templating, can anybody give me a hint how it should look like?
Thanks in Advance
Mike