Sensor result as entity name - to specify which day of week is day 2, day3 etc

I have created (I think its called) a template sensor for Day 2 day 3 day 4 etc to specify which day of the week it is (as from the current today…)

E.g. "{{ (as_timestamp(now())+(60*60*72))|timestamp_custom('%A') }}" is the one for day 3.

I use Solcast forecasts for day 2 day 3 etc.

I want a neat way to display the Solcast forecast (it is a number of kWh’s) with e.g. Tuesday Solcast as the title. I’m thinking is there a way (preferably in the UI) to rename the Solcast Day 3 using the Xday Solcast format? It doesn’t seem to like it when I paste the above code into the entity name in UI (I think this is “friendly name”).

Any ideas from less of a novice than me would be welcome as my googling didn’t get me anywhere.

You need to add the template to the yaml configuration of the sensor.

template:
  - sensor:
      - name: "{{ (now() + timedelta(days=1)).strftime('%A') }} Solcast"
        unique_id: tomorrow_solcast
        state: ...
2 Likes

Thanks so much. However the sensor I’m changing the name of is created by the Solcast integration so I don’t know how to get at it in yaml, only in UI??

Will I just have create a new sensor that copies the value of the Solcast sensor and then name it (in yaml) as above, or is there any way to rename the original Solcast sensor?

AFAIK, you cannot apply a dynamic name directly to the original sensor. You will need to set up a template sensor that mirrors the value in question.

If you only need this for display purposes, there are a number of custom cards like Mushroom or Custom Button Card that support templating and could be used to achieve that goal.

That’s great, thank you for your help – I will have a look at the mushroom cards because I have recently uploaded them :slight_smile:

I have been looking for how to do this for a while. thanks!

Now… How do I use that sensor in a card? I admit to being a bit of a noob with HA, but, I can’t seem to find the sensor when I search for the unique_id I specified.

  - sensor:
      - name: "{{ (now() + timedelta(days=2)).strftime('%A') }} cloud cover"
        unique_id: pirateclouds_2d
        state: "{{ sensor.pirateweathersensors_cloud_coverage_2d }}"
        icon: >
          {% if states('sensor.pirateweathersensors_cloud_coverage_2d' > 70 -%}
            mdi:weather-cloudy
          {% elif states('sensor.pirateweathersensors_cloud_coverage_2d' < 30 -%}
            mdi:weather-sunny
          {% else %}
            mdi:weather-partly-cloudy
          {%- endif %}

So, I put that in my configuration.yaml and restarted, now I click on the magnifying glass and “pirateclouds” comes back “nothing found”

Your state template is causing the entity to error.

state: "{{ states('sensor.pirateweathersensors_cloud_coverage_2d') }}"

Thanks

I updated it to

"{{ states('sensor.pirateweathersensors_cloud_coverage_2d') }}"

And it parses appropriately in dev tools, then I did a restart and I still can’t find the pirateclouds_2d entity

You also need to fix the templates from the icon.

  1. Missing closing parentheses
  2. Missing int filters.

I’m really sorry to be bothering you with such simple things… Is there an easier way to find errors in this stuff?

I’m new to HA, most of my programming experience I at least get error messages from a compiler or interpreter…

Also, I got the closing parentheses, but where do I need an int filter?

Current (still failing) version:

  - sensor:
      - name: "{{ (now() + timedelta(days=2)).strftime('%A') }} cloud cover"
        unique_id: pirateclouds_2d
        state: "{{ states('sensor.pirateweathersensors_cloud_coverage_2d') }}"
        icon: >
          {% if states('sensor.pirateweathersensors_cloud_coverage_2d') | int > 70 -%}
            mdi:weather-cloudy
          {% elif states('sensor.pirateweathersensors_cloud_coverage_2d') | int < 30 -%}
            mdi:weather-sunny
          {% else %}
            mdi:weather-partly-cloudy
          {%- endif %}

The u ique id is not the entity id and I don’t think you can search for it… The entity id is derived from the name, so I would not dare to guess if this works and what the entity might be if it did. But I’m not surprised it woun’t show up by searching for pirateclouds. Try seaching for cloud.

Tht is the int filter. It should be something like

| int(0)

Where 0 is the value it will use if what is before it is not a number (unknown for instance)

Thank you!

Got it, and implemented it, but I still can’t find this sensor.

Am I supposed to be able to refer to it by unique_id just like I could with other sensors by their entity_id?

No, that was my point. I do not think you can create sensors with dynamic names this way, Because what would be the entity id that is derived from the name, and would it be the same the next time you reboot? And would the entity id stay the same while the name changes without rebooting? HA will likely think you try to load a whole different sensor with the same unique id.

I thought that’s what the whole business with templating in the name field was supposed to accomplish…?

I guess I’ll look into mushroom cards.

Thanks!

I know that what’s what asked, and what seems like a solution. But has anyone actually succeeded? Templating a name in a card on the front end is a whole lot more sensible then to try templating the friendly name of a sensor at the server side. I do not think this is a case that the devs ever accounted for.

Yes it works.

The unique ID does not set the original entity ID, that will be set by the name rendered by the template when the entity is created. IIRC, the only time the unique ID is used to populate the entity ID is when no name is provided.

You can manually change the entity ID to whatever you want in the entity’s settings:

But does the name change real time and update on screen, or only when loaded? And if it works, the word pirateclouds would not help finding the entity. That is why I suggested searching for cloud, as that should be in the name and in the entity id.

The name updates whenever the template is rendered, but there may be some lag due to frontend caching.

It is nice that is works. But I wouldn’t have expected it to as changing a name in templates would for me usually lead to HA thinking it is a different sensor, and create another entity. Does the unique_id prevent that? Because I usually set it but still have trouble changing names of sensors when you cannot also set the entity id in the template by hand.

Ah, I can find Saturday_cloud_coverage, but not pirateclouds_2d…

If I wanted to always get 2 days in advance, so I could have my entities displayed as:
Today
Tomorrow
Saturday
Sunday…

But have the days of the week be dynamically determined, so that when I looked tomorrow it would be Sunday, Monday rather than Saturday, Sunday…

Could I do that by setting the friendly name as the templated version and keeping the name as a fixed string?