Day Counter for Homeassistant

cobshopgrow

Well-Known Member
Well, who dont like to know how many days the plants are in flower?
many ways to do it, If you have a homeassistant running anyway its quite easy to let him do the counting for you.

days.png

insert this in your configurations.yaml first.

YAML:
input_datetime:
  plant_blooming_start:
    name: Start of plant blooming
    has_date: true
    has_time: false
and this to your configurations.yaml
YAML:
sensor:
  - platform: template
    sensors:
      plant_blooming_days:
        friendly_name: 'Plant Blooming Days'
        value_template: >
          {% set bloom_start = states('input_datetime.plant_blooming_start') %}
          {% if bloom_start %}
            {% set bloom_date = strptime(bloom_start, '%Y-%m-%d') %}
            {{ ((now().replace(tzinfo=None)) - bloom_date).days }}
          {% else %}
            'unknown'
          {% endif %}
        icon_template: mdi:flower
        unit_of_measurement: 'Days'
after a restart you should have a "Plant Blooming Days" sensor counting you the days.
you can set the start date under "configurations" "devices" "helpers".

if you want a reset button for the days, like me, you need to add this to your configurations.yaml also
YAML:
input_boolean:
  reset_plant_blooming_counter:
    name: Reset Plant Blooming Counter
    initial: off
    icon: mdi:restart
and this to your automations.yaml
YAML:
- alias: "Reset Plant Blooming Days Counter"
  trigger:
    - platform: state
      entity_id: input_boolean.reset_plant_blooming_counter
      to: 'on'
  action:
    - service: input_datetime.set_datetime
      target:
        entity_id: input_datetime.plant_blooming_start
      data:
        date: "{{ now().strftime('%Y-%m-%d') }}"
    - service: input_boolean.turn_off
      target:
        entity_id: input_boolean.reset_plant_blooming_counter
restart and you will have a "Reset Plant Blooming Days Counter" Button also which sets you the day counter to zero.
simple but usefull, hope it helps.
 
Last edited:

Billy the Mountain

Well-Known Member
Well, who dont like to know how many days the plants are in flower?
many ways to do it, If you have a homeassistant running anyway its quite easy to let him do the counting for you.

View attachment 5341648

insert this in your configurations.yaml first.

YAML:
input_datetime:
  plant_blooming_start:
    name: Start of plant blooming
    has_date: true
    has_time: false
and this to your configurations.yaml
YAML:
sensor:
  - platform: template
    sensors:
      plant_blooming_days:
        friendly_name: 'Plant Blooming Days'
        value_template: >
          {% set bloom_start = states('input_datetime.plant_blooming_start') %}
          {% if bloom_start %}
            {% set bloom_date = strptime(bloom_start, '%Y-%m-%d') %}
            {{ ((now().replace(tzinfo=None)) - bloom_date).days }}
          {% else %}
            'unknown'
          {% endif %}
        icon_template: mdi:flower
        unit_of_measurement: 'Days'
after a restart you should have a "Plant Blooming Days" sensor counting you the days.
you can set the start date under "configurations" "devices" "helpers".

if you want a reset button for the days, like me, you need to add this to your configurations.yaml also
YAML:
input_boolean:
  reset_plant_blooming_counter:
    name: Reset Plant Blooming Counter
    initial: off
    icon: mdi:restart
and this to your automations.yaml
YAML:
- alias: "Reset Plant Blooming Days Counter"
  trigger:
    - platform: state
      entity_id: input_boolean.reset_plant_blooming_counter
      to: 'on'
  action:
    - service: input_datetime.set_datetime
      target:
        entity_id: input_datetime.plant_blooming_start
      data:
        date: "{{ now().strftime('%Y-%m-%d') }}"
    - service: input_boolean.turn_off
      target:
        entity_id: input_boolean.reset_plant_blooming_counter
restart and you will have a "Reset Plant Blooming Days Counter" Button also which sets you the day counter to zero.
simple but usefull, hope it helps.
Works like a charm, sure beats scrolling through a calendar, thanks!
 
Top