Hello,
I am trying to create 2 new entities for my HomeAssistant instance which should display the (named) month/day of the week so that I can use these for my automations.
Following several guides and forum posts I managed to write below code in my configuration.yaml file.
Both entities show an ‘Off’ state and I figured this is because somewhere earlier in my configuration.yaml file I have written “binary_sensor:” along with some other configurations.
What sensor type would I need to use to get the values as names? Also pointers towards documentation for this is very much appreciated as I couldn’t find it Other feedback is also more than welcome.
You can just use strftime to convert the time into day and month:
{{ now().strftime('%A') }} .... Gives you Monday, Tuesday, etc
{{ now().strftime('%B') }} .... Gives you January, February, etc
So putting the following in templates.yaml:
- trigger:
- platform: time
at: "00:00:00"
- platform: homeassistant
event: start
sensor:
- name: Day of Week
unique_id: week_day
state: >-
{{ now().strftime('%A') }}
Note that I put these sort of things on a trigger that only update once a day or when HA restarts. Otherwise HA would update the sensor every minute, which is reasonably unlikely to change throughout the day. Therefore if you just paste this in and use Developer Tools to reload “Template Entities”, it will stay undefined until midnight or you restart HA; it will be fine from then on.
Above is correct but to answer some of your questions…
the type would be sensor vice binary_sensor as you say you currently have.
However… you are using the Legacy format.
You would do well to convert it to the modern Template format which @michaelblight is using above.
In that case the integration is actually template not sensor. So if you were to put the above into configuration.yaml you would simply add template: above and indent everything else two spaces.