Zodiac Sign Sensor

I created a Western Astrology Zodiac Sign Sensor because as much as I love code and science, I enjoy taking a break with a good bit of whimsy, often esoteric .

All styling is inherited from the UI so should look ok whatever your theme.

Coming soon:

  • Tarot card sensor
  • Mood avatar

Screenshot of how it appears in various standard lovelace cards and ‘custom header’:

To install create a sensor with @123’s post below which is better code than mine.
[Removed code]

I’m aware that this may not be 100% accurate. Very happy to know if someone has a better way of doing this, especially if it adjusts for leap years.

4 Likes

Very nice :slight_smile: Will look into leap year but it comes again in 4 years…
BTW You can remove

entity_id: sensor.date

as it is now deprecated in template sensors

Updated, thanks

For this simple Template Sensor, you aren’t obligated to create an automation to update it. You can simply add sensor.date to the template and it will be automatically assigned a listener (in other words, it will behave like in previous versions where you used entity_id: sensor.date).

- platform: template
  sensors:
    zodiac:
      friendly_name: Zodiac Sign
      value_template: >-
        {% set x = states('sensor.date') %}
        {% set yday = now().timetuple().tm_yday %}
        {% if yday < 20 %} Capricorn
        {% elif yday < 50 %} Aquarius
        {% elif yday < 80 %} Pisces
        {% elif yday < 110 %} Aries
        {% elif yday < 141 %} Taurus
        {% elif yday < 172 %} Gemini
        {% elif yday < 204 %} Cancer
        {% elif yday < 235 %} Leo
        {% elif yday < 266 %} Virgo
        {% elif yday < 296 %} Libra
        {% elif yday < 326 %} Scorpio
        {% elif yday < 356 %} Sagittarius
        {% elif yday < 366 %} Capricorn
        {% else %} Error
        {% endif %}
      icon_template: >
        {% set sign = states('sensor.zodiac') %}
        {% if sign in ['Error', 'unavailable', 'unknown'] %}
          mdi:alert-circle
        {% else %}
          mdi:zodiac-{{ sign | lower}}
        {% endif %}


EDIT

Corrected typo; changed mid to mdi.

3 Likes

Yes Taras 123,
Your icon_template is elegant (as Jinja can be)… but only for English language.
Thanks, JR

True but nowhere in this thread is there a design requirement to support multiple languages so that’s why I reduced icon_template.

If there’s a need to handle any language, I would use a dictionary to store the names.


:face_with_hand_over_mouth: :blush:

Don’t you love when auto-correct thinks it’s doing you a favor by changing mdi to mid? :slight_smile:

Thanks for reporting it; corrected.

0.116 Has a Zodiac Sensor
Thanks @JulienTant, is it leapyear compatible?
Please consider calling it ‘Western Zodiac’, since over 1/5th of the world’s population expects something else.

how to have the view as in the first post because I paste this code and I have all in red

The error message reports:

No card type configured

It’s not a card it’s a Template Sensor. If you didn’t paste it into the sensor: domain of your configuration.yaml file (or sensors.yaml file if that’s where your sensors are defined) then you pasted it in the wrong place.

To use this with the new Zodiac integration and get a card like mine, use this in your card:

type: button
tap_action:
  action: toggle
entity: sensor.zodiac
show_state: true
show_name: false