I got myself this nice card with general information about my cucumber plants:
Except, what I really need is not to use the input_datetime.grow_start_date but the sensor.planned_veg_start_date, which will give me the accurate result for the number of the weeks that have passed. Both the input_datetime and the sensor.planned_veg_start_date are in the image.
I’m trying to play around with code and I reached this:
But, it is not event correct from the syntax point of view. I’m sure this would be evident for anyone with Yaml basics, as opposed to me, with no clue of what is happening.
Can someone help me fixing this? Thank you in advance.
#------------------------------------------------------------------------------------------------------
#
# Sensor - sensor.current_week_of_grow. 604800 = 86400*7 or the number of
# seconds in a week. This is setup to add to configuration.yaml. Will default to 0
# if the entities are unavailable. Convert now and planned start date to unixtime
# to get seconds.
#
#-------------------------------------------------------------------------------------------------------
sensor:
- platform: template
sensors:
current_week_of_grow:
friendly_name: "Current Week of Grow"
icon_template: mdi:calendar
value_template: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.planned_veg_start_date'))) | int(0) / 604800 + 1) | round(0, default=1) }}"
You should know that the entity_id option was eliminated from the Template Sensor integration a long time ago. Unless you are using an extremely old version of Home Assistant, you can remove it from the sensor’s configuration.
Thank you very much for giving me an hand, and sorry for the late reply. After re-installing my HA due to another issue, I finally was able to test it, and it is working almost perfectly. I just don’t know why it gives “week 13” as a result, because, since the Veg start date is 2022-06-05, it was supposed to still being week 12. Week 13 should start at the 28th August. Any idea why this is happening?
Thank you very much!
Here is my yaml for sensor.planned_veg_start_date:
The formula you posted adds one week to the computed result. I included it in my example because that’s what you had. However, why are you adding an extra week to the calculation?
Thank you again for hanging on
I dont even remember why the " + 1" is there, but I tried to take it out and it now shows Week “12”, and it was supposed to show week “13”.
So, in order to make it more concrete, since the Veg start date is 2022-06-05, the outputs should be as follows:
“Week 1” - from 2022-06-05 to 2022-06-11
“Week 2” - from 2022-06-12 to 2022-06-18
“Week 3” - from 2022-06-19 to 2022-06-25
“Week 4” - from 2022-06-26 to 2022-07-02
“Week 5” - from 2022-07-03 to 2022-07-09
“Week 6” - from 2022-07-10 to 2022-07-16
“Week 7” - from 2022-07-17 to 2022-07-23
“Week 8” - from 2022-07-24 to 2022-07-30
“Week 9” - from 2022-08-31 to 2022-08-06
“Week 10” - from 2022-08-07 to 2022-08-13
“Week 11” - from 2022-08-14 to 2022-08-20
“Week 12” - from 2022-08-21 to 2022-08-27
“Week 13” - from 2022-08-28 to 2022-09-03
If I use the code with the “+ 1” I still get the “week 13” - which is correct at the moment, but started earlier than expected (at least in 25th August, instead of 28th August). What could be causing this issue?
This is the solution, I tried it out and it is giving me the “13” as supposed. I tested the Veg date and now it works all around.
Thank you so much for giving me an hand!