diff --git a/README.md b/README.md index 768e7af..68f3b2d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Each sensor is given the following automatically: entity_id: sensor._ friendly_name: 's state: +nextoccur: years: ``` @@ -59,11 +60,13 @@ So, the two sensors we created above would come out as: sensor.birthday_john friendly_name: John’s birthday state: However many days it is until 17th August +nextoccur: 17/08/YYYY (either this year or next year as appropriate) years: However old John will be on his next birthday sensor.anniversary_our_wedding -friendly_name: Our wedding anniversary +friendly_name: Our wedding's anniversary state: However many days to 14th February +nextoccur: 14/02/YYYY (either this year or next year as appropriate) years: How many years you will have been married on that day ``` @@ -107,3 +110,22 @@ automation: data: message: "John's birthday is only a week away!" ``` + +## Example Lovelace representation +Utilising the attributes provided and the [custom lovelace card](https://github.com/custom-cards/secondaryinfo-entity-row) for adding secondary info to an entity row. + +```yaml +type: entities +show_header_toggle: false +title: Our Events +entities: + - entity: sensor.anniversary_our_wedding + secondary_info: '[[ {entity}.attributes.nextoccur ]] ( [[ {entity}.attributes.years ]] Years )' + type: 'custom:secondaryinfo-entity-row' +``` + +Will provide the following lovelace representation: + +![Lovelace example](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/b/a/ba44600d7f41b1525a3c835d11bcc3bd59815b23.png) + +(Thanks to [@myle](https://community.home-assistant.io/u/myle/summary) for this idea ) diff --git a/info.md b/info.md index 7b1215a..bcf9dbb 100644 --- a/info.md +++ b/info.md @@ -40,6 +40,7 @@ Each sensor is given the following automatically: entity_id: sensor._ friendly_name: 's state: +nextoccur: years: ``` @@ -49,11 +50,13 @@ So, the two sensors we created above would come out as: sensor.birthday_john friendly_name: John’s birthday state: However many days it is until 17th August +nextoccur: 17/08/YYYY (either this year or next year as appropriate) years: However old John will be on his next birthday sensor.anniversary_our_wedding -friendly_name: Our wedding anniversary +friendly_name: Our wedding's anniversary state: However many days to 14th February +nextoccur: 14/02/YYYY (either this year or next year as appropriate) years: How many years you will have been married on that day ``` @@ -97,3 +100,22 @@ automation: data: message: "John's birthday is only a week away!" ``` + +## Example Lovelace representation +Utilising the attributes provided and the [custom lovelace card](https://github.com/custom-cards/secondaryinfo-entity-row) for adding secondary info to an entity row. + +```yaml +type: entities +show_header_toggle: false +title: Our Events +entities: + - entity: sensor.anniversary_our_wedding + secondary_info: '[[ {entity}.attributes.nextoccur ]] ( [[ {entity}.attributes.years ]] Years )' + type: 'custom:secondaryinfo-entity-row' +``` + +Will provide the following lovelace representation: + +![Lovelace example](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/b/a/ba44600d7f41b1525a3c835d11bcc3bd59815b23.png) + +(Thanks to [@myle](https://community.home-assistant.io/u/myle/summary) for this idea ) diff --git a/python_scripts/date_countdown.py b/python_scripts/date_countdown.py index 7de23b8..33fb2f9 100644 --- a/python_scripts/date_countdown.py +++ b/python_scripts/date_countdown.py @@ -10,7 +10,7 @@ dateDay = int(dateSplit[0]) dateMonth = int(dateSplit[1]) dateYear = int(dateSplit[2]) -date = datetime.date(dateYear,dateMonth,dateDay) +date = datetime.date(dateYear , dateMonth , dateDay) thisYear = today.year nextOccur = datetime.date(thisYear , dateMonth , dateDay) @@ -24,13 +24,14 @@ elif today > nextOccur: nextOccur = datetime.date(thisYear+1 , dateMonth , dateDay) numberOfDays = (nextOccur - today).days - years = years+1 + years = years + 1 hass.states.set(sensorName , numberOfDays , { "icon" : "mdi:calendar-star" , "unit_of_measurement" : "days" , - "friendly_name" : "{}'s {}".format(name, type) , + "friendly_name" : "{}'s {}".format(name , type) , + "nextoccur" : "{}/{}/{}".format(nextOccur.day , nextOccur.month , nextOccur.year) , "years" : years } )