Hi everyone,
This is my first serious post. I thought I’d share a small project I just worked on for my astrologer partner: a sensor that calculates the current Planetary Hour.
The first challenge was calculating the length of each planetary hour on the current day, since there are 12 planetary hours regardless of daylength. Because the inbuilt sun.sun
component only has a time for the following sunrise and sunset, but we need to know the daylength of the current day, I made use of @pnbruckner’s enhanced sun component:
Firstly the sensors to calculate planetary hour length, the current planetary hour’s number and name, in sensors.yaml
:
# Planetary hour calculations
- platform: template
sensors:
plan_hr_len:
friendly_name: "Planetary hour length today"
entity_id: sensor.date
unit_of_measurement: "seconds"
value_template: >
{{ states('sensor.daylight') | float / 12 * 3600 }}
plan_hr_no:
friendly_name: "Planetary hour number"
entity_id: sensor.time
value_template: >
{% if states.sensor.sunrise.state is defined
and states.sensor.plan_hr_len.state is defined
and states.sensor.plan_hr_len.state | int > 0 %}
{{ ( as_timestamp(now()) - as_timestamp(states('sensor.sunrise') )
/ ( states('sensor.plan_hr_len') | float ) )
| round (0, "ceil") }}
{% else %}
Initialising
{% endif%}
plan_hr_name:
friendly_name: "Planetary hour name"
entity_id: sensor.time
value_template: >-
{% set plan_order = ['Moon', 'Saturn', 'Jupiter', 'Mars',
'Sun', 'Venus', 'Mercury'] %}
{% set day_planets = [0, 3, 6, 2,
5, 1, 4] %}
{% set hour = (( day_planets[now().weekday() | int] )
+ ( states('sensor.plan_hr_no') | int) - 1 )
% plan_order | length %}
{{ plan_order[hour] }}
This allows me to create a lovelace card for the current planetary hour, but also to integrate the changeover of each PH into an automation, to play a custom chime for each planet at the start of that planet’s hour. First a custom script to send the correct sound file to a Sonos speaker to play (in scripts.yaml
). The script will send a URL filename such as Jupiter.mp3
to the speaker:
# Script to play sound file with Sonos
planetary_hour_chime:
alias: "Play Planetary hour chime"
sequence:
- service: sonos.snapshot
data_template:
entity_id: "{{ sonos_entity }}"
- service: sonos.unjoin
data_template:
entity_id: "{{ sonos_entity }}"
- service: media_player.volume_set
data_template:
entity_id: "{{ sonos_entity }}"
volume_level: "{{ volume }}"
- service: media_player.play_media
data_template:
entity_id: "{{ sonos_entity }}"
media_content_id: 'http://example.com:8123/local/{{ states("sensor.plan_hr_name") }}.mp3'
media_content_type: 'music'
- delay: "{{ delay }}"
- wait_template: "{{ not is_state(sonos_entity, 'playing') }}"
timeout: '00:06:00'
- service: sonos.restore
data_template:
entity_id: "{{ sonos_entity }}"
Finally an automation to play the correct chime when a planet’s hour starts (in automations.yaml
):
- id: 'some_big_number_XXXXX'
alias: Planetary Hour
description: 'Chime Planetary Hour on Change'
trigger:
- entity_id: sensor.plan_hr_name
platform: state
condition:
- after: 07:00
before: '21:05'
condition: time
- condition: state
entity_id: group.inhabitants
state: home
- after: sunrise
before: sunset
before_offset: 0:15
condition: sun
action:
- data:
delay: 00:00:6
sonos_entity: media_player.room_1, media_player.room_2
volume: 0.6
service: script.planetary_hour_chime
If you’re astrologically inclined and this is useful, please let me know!