Days since initial set date (Card)

Is there a method using the time/date sensor to create a card that counts up from a set initial date? I’m looking at logging some plant growth in my hot pepper garden.

I would like to create a simple card in lovelace that counts up days since planting based on a set initial date/time. Any help would be greatly appreciated.

You could use a template sensor with something like this:

{{ ((now().timestamp() - as_timestamp("2021-04-24")) /86400) | int }}

It won’t be accurate at daylight savings but I believe that won’t matter for your use case

Thank you. Sorry, very dumb question, where is this implemented? In the configuration.yaml? And how should this be denoted?

Correct.

sensor:
  - platform: template
    sensors:
      plant_age:
        friendly_name: "Plant age (2021-04-24)"
        value_template: {{ ((now().timestamp() - as_timestamp("2021-04-24")) /86400) | int }}

incase you hit a headache trying to make that code above a little more flexible…

sensor:
  - platform: template
    sensors:
      front_days_left:
        value_template: '{{ ((( states.input_datetime.front_room_end.attributes.timestamp - as_timestamp(now()) )) | int /60/1440) | round(0) }}'
        unit_of_measurement: 'Days'
        friendly_name: "Front - Days left"
        icon_template: mdi:calendar-star
        
      front_days_in:
        value_template: '{{ (((as_timestamp(now()) - states.input_datetime.front_room_start.attributes.timestamp  )) | int /60/1440) | round(0) }}'
        unit_of_measurement: 'Days'
        friendly_name: "Front - Days In"
        icon_template: mdi:calendar-clock    
      
      front_current_week_of_grow:
        friendly_name: "Current Week"
        icon_template: mdi:calendar-heart
        value_template: '{{ ((as_timestamp(now()) - (states.input_datetime.front_room_start.attributes.timestamp)) | int /60/1440/7 +1)  | round(0) }}'
       



input_datetime:
  front_room_start:
    name: 'Front Room Start'
    has_date: true
    has_time: false
    #: '2020-9-15' 

  front_room_end:
    name: 'Front Room End'
    has_date: true
    has_time: false
    #initial: '2020-11-15' 



input_number:
  weekcount_f:
    name: 'front week count'
    min: 1
    max: 12
    step: 1
    unit_of_measurement: 'weeks'
    icon: mdi:target   

automation:
- id: front_day_handler
  alias: 'front - auto dates'
  initial_state: true
  
  trigger:
    platform: state
    entity_id: input_datetime.front_room_start, input_number.weekcount_f
  
  action:
  - service: input_datetime.set_datetime
    entity_id: input_datetime.front_room_end
    data:
      date: "{{ (as_timestamp( states.input_datetime.front_room_start.state) + (24*3600)*7*( states.input_number.weekcount_f.state | int )) | timestamp_custom('%Y-%m-%d', True) }}"  
  
7 Likes

happy 420 everyone

1 Like