Skip to content

Commit

Permalink
Merge pull request #2 from mf-social/feature/seconday-info
Browse files Browse the repository at this point in the history
Added secondary info
  • Loading branch information
Marc Forth authored Oct 25, 2019
2 parents 70a4d06 + db4a4f4 commit d67ee66
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Each sensor is given the following automatically:
entity_id: sensor.<type>_<name>
friendly_name: <name> 's <type>
state: <Days to the date from today>
nextoccur: <Date of next occurance>
years: <Number of years it will be>
```

Expand All @@ -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
```

Expand Down Expand Up @@ -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 )
24 changes: 23 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Each sensor is given the following automatically:
entity_id: sensor.<type>_<name>
friendly_name: <name> 's <type>
state: <Days to the date from today>
nextoccur: <Date of next occurance>
years: <Number of years it will be>
```

Expand All @@ -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
```

Expand Down Expand Up @@ -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 )
7 changes: 4 additions & 3 deletions python_scripts/date_countdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
)

0 comments on commit d67ee66

Please sign in to comment.