Olen / homeassistant-plant

Alternative Plant component of home assistant
350 stars 23 forks source link

Concept for plants without sensors #133

Closed wehrstedt closed 4 months ago

wehrstedt commented 9 months ago

I have some flowers without sensor and would like to handle them with this Integration, too, because i like the concept and the idea of this integreation and it would be awesome to have every flower state united in one tool. I know that having sensors is much more accurate than "water your plants every 5 days".

Is there any concept implemented or planned? I was thinking about

Olen commented 9 months ago

I don't think I am going to implement this, as it sounds like something completely different from what this integration does. You can either set up a local "plant watering"-calendar, and a few buttons/scripts/automations to modify entries in the calendar.

You could even expand that a step further, and create an automation that "fakes" a moisture-sensor based on the age of the "last watered" calendar entry. E.g. a template-sensor that will show 100% if calendar.plant_watered is today, 80% if calendar.plant_watered is yesterday, 60% if calendar.plant_watered is two days ago etc.

Or, if you water your plants every sunday, just create a template sensor that is < {low}% on sundays and > {low}% on all other days.

That will trigger the problem state, and any notifications you have bound to that will also work as expected.

Olen commented 8 months ago

Just for my own convenience - I'll probably implement something similar for a few plants where I don't have a sensor.

Create an input_datetime.myplant_last_watered

Create a button.water_myplant

Create a template sensor sensor.myplant_soil_moisture The following is just a rough version that "counts down" from "max" to "min" over "frequency" days. Can obviously be improved.

{% set last = states('input_datetime.plant_last_watered')[:10] %}
{% set num_days = (today_at() - last | as_datetime | as_local).days %}
{% set max = 80 %}
{% set min = 0 %}
{% set frequency = 7 %}
{% set daily = (max - min) / frequency %}  
{% set current = int(max - (num_days * daily)) %}
{% if current < min %}
{% set current = min %}
{% endif %}
{{ current }}

This can then be used as the source sensor for a plant.

Create an automation:

alias: Water My Plant
trigger:
  - platform: state
    entity_id:
      - input_button.water_myplant
action:
  - service: input_datetime.set_datetime
    data:
      datetime: "{{ now().timestamp() | timestamp_local }}"
    target:
      entity_id: input_datetime.myplant_last_watered

So when you have watered your plant, just press the button and the fake moisture-sensor resets to "max", and starts counting down for every day.