Currently Map card show a “name” composed from an entity’s name (up to 3 characters).
There is a related Discussion - " Map card: add an ability to show a state of an entity instead of showing a name".
Meanwhile, there are 2 working solutions:
- Generating “friendly_name”.
- Using card-mod.
1. Generating “friendly_name”:
Consider this code:
input_number:
some_number:
...
sensor:
- platform: template
sensors:
some_marker:
friendly_name_template: >-
{% set VALUE = states("input_number.some_number") -%}
{%- if VALUE|length > 3 and VALUE[2] in ['.',','] -%}
{%- set VALUE = VALUE|float(default=0)|round(0) -%}
{%- endif -%}
{{ VALUE|string|list|join(' ') }}
value_template: ...
attribute_templates:
latitude: ...
longitude: ...
The idea is to compose a “friendly_name” (legacy format is used for a template sensor) based on some numerical value.
The template takes 3 first characters from the value and compose a string.
If the 3rd character is a delimiter than a rounding is performed.
Note: the code may not be optimal; also it does not work for negatives…
2. Card-mod:
The idea is to hide a displayed name and replace it with some user-defined string:
type: map
entities:
- entity: sensor.some_marker
card_mod:
style:
ha-map:
$:
.leaflet-marker-icon:
ha-entity-marker $: |
.marker {
font-size: 0px !important;
}
.marker::after {
content: "{{states('input_number.some_number')}}";
font-size: 10px !important;
}
Unfortunately, the card-mod code is not stable: it works in a “dashboard edit mode”, may be lost after a page refresh.
Here is test example for both methods:
entities
input_number:
test_map_markers_with_values_1: &ref_number
min: 0
max: 100
step: 0.1
mode: box
test_map_markers_with_values_2: *ref_number
test_map_markers_with_values_3: *ref_number
##########################################################
sensor:
- platform: template
sensors:
test_map_markers_with_values_1:
friendly_name_template: &ref_friendly_name_template >-
{% set HELPER_NAME = 'input_number.' + this.entity_id.split('.')[1] -%}
{%- set VALUE = states(HELPER_NAME) -%}
{%- if VALUE|length > 3 and VALUE[2] in ['.',','] -%}
{%- set VALUE = VALUE|float(default=0)|round(0) -%}
{%- endif -%}
{{ VALUE|string|list|join(' ') }}
value_template: ok
attribute_templates: &ref_attr_1
latitude: -25.100481554029
longitude: -129.37401816254
test_map_markers_with_values_2:
friendly_name_template: *ref_friendly_name_template
value_template: ok
attribute_templates: &ref_attr_2
latitude: 25.100481554029
longitude: 129.37401816254
test_map_markers_with_values_3:
friendly_name_template: *ref_friendly_name_template
value_template: ok
attribute_templates: &ref_attr_3
latitude: -5.100481554029
longitude: -9.37401816254
##########################################################
test_map_markers_with_values_4:
value_template: ok
attribute_templates: *ref_attr_1
test_map_markers_with_values_5:
value_template: ok
attribute_templates: *ref_attr_2
test_map_markers_with_values_6:
value_template: ok
attribute_templates: *ref_attr_3
card
type: vertical-stack
cards:
- type: entities
entities:
- entity: input_number.test_map_markers_with_values_1
name: value 1
- entity: input_number.test_map_markers_with_values_2
name: value 2
- entity: input_number.test_map_markers_with_values_3
name: value 3
- type: map
title: friendly_name
entities:
- entity: sensor.test_map_markers_with_values_1
- entity: sensor.test_map_markers_with_values_2
- entity: sensor.test_map_markers_with_values_3
- type: map
title: card-mod
entities:
- entity: sensor.test_map_markers_with_values_4
- entity: sensor.test_map_markers_with_values_5
- entity: sensor.test_map_markers_with_values_6
card_mod:
style:
ha-map:
$:
.leaflet-marker-icon:
ha-entity-marker[entity-id='sensor.test_map_markers_with_values_4'] $: |
.marker {
font-size: 0px !important;
}
.marker::after {
content: "{{states('input_number.test_map_markers_with_values_1')}}";
font-size: 15px !important;
}
ha-entity-marker[entity-id='sensor.test_map_markers_with_values_5'] $: |
.marker {
font-size: 0px !important;
}
.marker::after {
content: "{{states('input_number.test_map_markers_with_values_2')}}";
font-size: 15px !important;
}
ha-entity-marker[entity-id='sensor.test_map_markers_with_values_6'] $: |
.marker {
font-size: 0px !important;
}
.marker::after {
content: "{{states('input_number.test_map_markers_with_values_3')}}";
font-size: 15px !important;
}
Update 15.10.23: this mod is not needed since 2023.10 - a possibility of displaying states was added (discussion, PR)