mirror of
https://github.com/thejeffreystone/home-assistant-configuration.git
synced 2025-08-18 11:56:44 +00:00
Updated to V5 Version - Hassio Style
Lots of updates here. Updated my Readme - Added Affiliate Links, added some more information, better organized devices Updated gitignore with paths realtive to my hassio config Combined my switches and lights into single yaml files instead of the directory structure previously Added zigbee2mqtt.yaml to packages - contains automations and such for zigbee2mqtt Archived my previous version in the V4-config branch.
This commit is contained in:
39
config/python_scripts/special_events.py
Executable file
39
config/python_scripts/special_events.py
Executable file
@@ -0,0 +1,39 @@
|
||||
today = datetime.datetime.now().date()
|
||||
|
||||
name = data.get('name')
|
||||
type = data.get('type')
|
||||
sensorName = "sensor.{}_{}".format(type , name.replace(" " , "_"))
|
||||
|
||||
dateStr = data.get('date')
|
||||
dateSplit = dateStr.split("/")
|
||||
|
||||
dateDay = int(dateSplit[0])
|
||||
dateMonth = int(dateSplit[1])
|
||||
dateYear = int(dateSplit[2])
|
||||
date = datetime.date(dateYear,dateMonth,dateDay)
|
||||
|
||||
thisYear = today.year
|
||||
nextOccur = datetime.date(thisYear , dateMonth , dateDay)
|
||||
|
||||
numberOfDays = 0
|
||||
years = int(thisYear) - dateYear
|
||||
|
||||
|
||||
if today < nextOccur:
|
||||
numberOfDays = (nextOccur - today).days
|
||||
|
||||
elif today > nextOccur:
|
||||
nextOccur = datetime.date(thisYear+1 , dateMonth , dateDay)
|
||||
numberOfDays = int((nextOccur - today).days)
|
||||
years = years+1
|
||||
|
||||
|
||||
hass.states.set(sensorName , numberOfDays ,
|
||||
{
|
||||
"icon" : "mdi:calendar-star" ,
|
||||
"unit_of_measurement" : "days" ,
|
||||
"friendly_name" : "{}'s {}".format(name, type) ,
|
||||
"years" : years
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user