I want 2023-04-20 shown as 20 april and “4” shown as april
How can I do this ?
{% set mon = ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Avg", "Sep", "Okt", "Nov", "Dec"] %}
{{ (as_timestamp(now()) | timestamp_custom('%d')) }} {{ (mon[now().month-1])}}
21 Apr
so…
in my config yaml I made
- platform: template
sensors:
datumdagcijfervolledigemaanduitgeschreven:
friendly_name: "Datum"
entity_id: sensor.p1_meter_5c2faf04a1f2_peak_demand_current_month
value_template: >
{% set mon = ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"] %}
{{ (as_timestamp(now()) | timestamp_custom('%d')) }} {{ (mon[now().month-1])}}
so my sensor is giving me the date.
Now i want it in a card. How I do this ?
I have
- type: custom:mushroom-template-card
primary: "{{states.datumdagcijfervolledigemaanduitgeschreven.last_changed}}"
but I can see nothing
Since you are using the mushroom-template-card
you put it directly in the secondary info (or primary), you don’t need the sensor in the config yaml.
type: custom:mushroom-template-card
primary: Hello, {{user}}
secondary: >-
{% set mon = ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Avg", "Sep",
"Okt", "Nov", "Dec"] %}
{{ (as_timestamp(now()) | timestamp_custom('%d')) }} {{ (mon[now().month-1])}}
icon: mdi:home
Ok thanks.
and off-topic…
how can I get the value of a sensor in the primary ?
For example:
type: custom:mushroom-template-card
primary: '{{ states("sensor.lumi_lumi_weather_temperature_2") | round (1) }} °C'
secondary: >-
{% set mon = ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Avg", "Sep",
"Okt", "Nov", "Dec"] %}
{{ (as_timestamp(now()) | timestamp_custom('%d')) }} {{ (mon[now().month-1])}}
icon: mdi:home
- type: vertical-stack # knoppen onder elkaar
cards:
- type: custom:mushroom-template-card
secondary: Maandpiek
- type: custom:mushroom-template-card
primary: '{{ states("sensor.sensor.p1_meter_5c2faf04a1f2_peak_demand_current_month") }}'
secondary: >-
{% set mon = ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"] %}
{{ (as_timestamp(now()) | timestamp_custom('%d')) }} {{ (mon[now().month-1])}}
entity: sensor.p1_meter_5c2faf04a1f2_peak_demand_current_month.last_changed
``
primary gives me "unknown"
Check in developer tools what the sensor gives you:
Also have a look at this.
and how to show yesterday ? “21 april”
secondary: >-
{% set mon = ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"] %}
{{ ([now().day-1)) }} {{ (mon[now().month-1])}}