Pregnancy Tracking Privately with Tempalate Sensors

Amazing. Thanks very much That got it working for me.

1 Like

Thanks for your work - we really like it.

I pimped it a bit as the first ultrasonic showed that we get twins.

The whole thing is now a bit more dynamic and adjusts itself based on start date (day of last period) & end date (due date).

Changes compared to your initial version:

  • Calculations are now done from-start-to-end starting with the day of the last period
  • Overall duration is given by input helpers “last period” and “due date” instead of using a generic duration of 280days / 40weeks for the calculation
  • Added additional fields to track stuff
    • Next (doctor) check: extracts date/time of next baby-check from calendar
    • Size of fetus: input helper which can be set via Lovelace
    • Day in week attribute: know you know where you are in the week
    • Image of twin-development can be added/shown when someone wants (attribute in pregnancy object)
  • Compatible with twin-pregnancies: Twin tend to be smaller, an offset (+/- weeks) can be set via an input helper.
  • Additional links for German speaking / Swiss couples
    • babywelten.ch
    • swissmom.ch
    • famigros
    • wireltern.ch
  • Simplified automation and removed need for additional helper

This is how my dashboard looks like:

== Code ==

=== Input Helpers ===

=== Sensors ===

- platform: template
  sensors:
    pregnancy_next_check:
      value_template: "{{ as_timestamp(states.calendar['baby_untersuch'].attributes.start_time) | timestamp_custom('%A, %d.%m.%Y %H:%M') }}"
    pregnancy_days:
      friendly_name: "Days in pregnancy"
      unit_of_measurement: 'days'
      value_template: "{{ (as_timestamp(now()) - as_timestamp(states.input_datetime.pregnancy_last_period.state)) | timestamp_custom('%j') | int }}"
    pregnancy_days_left:
      friendly_name: "Days left until due"
      unit_of_measurement: 'days'
      value_template: "{{ (strptime(states.input_datetime.pregnancy_due_date.state, '%Y-%m-%d') - now().replace(tzinfo=None)).days }}"
    pregnancy_weeks:
      friendly_name: "Pregnancy Week"
      unit_of_measurement: 'weeks'
      value_template: "{{ (((states.sensor.pregnancy_days.state | int) / 7) | round(0, 'floor')) }}"
      attribute_templates:
        days_in_week: "{{ (states.sensor.pregnancy_days.state | int) - ((states.sensor.pregnancy_weeks.state | int )*7) }}"
    pregnancy_percent:
      friendly_name: "Pregnancy Percent"
      unit_of_measurement: '%'
      value_template: "{{ (((states.sensor.pregnancy_days.state | int)*100) / ((states.sensor.pregnancy_days.state | int)+(states.sensor.pregnancy_days_left.state | int))) | int }}"
    pregnancy:
      friendly_name: "Pregnancy"
      unit_of_measurement: 'Trimester'
      value_template: |
        {% set x = (states.sensor.pregnancy_weeks.state | int) %}
        {{ 'First' if x <= 12 else ( 'Second' if x <=24 else 'Third' ) }}
      attribute_templates:
        days: "{{ states.sensor.pregnancy_days.state }}"
        weeks: "{{ states.sensor.pregnancy_weeks.state }}"
        months: "{{ ((states.sensor.pregnancy_days.state | int) / 30.5) | round(1, 'half') }}"
        trimester: "{{ states.sensor.pregnancy.state }}"
        percent: "{{ states.sensor.pregnancy_percent.state }}"
        fetus_size_image: "https://images.agoramedia.com/wte3.0/gcms/wbw_squares_baby_wk_{{ states.sensor.pregnancy_weeks.state }}.jpg"
        fetus_size_fruit_image: "https://images.agoramedia.com/wte3.0/gcms/wbw-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}-fruit.png"
        fetus_size_fruit: |
          {% set sizes = { 4: 'Strawberry Seed', 5: 'Orange Seed', 6: 'Sweet Pea', 7: 'Blueberry', 8: 'Raspberry',
                           9: 'Green Olive', 10: 'Prune', 11: 'Large Strawberry', 12: 'Lime', 13: 'Lemon',
                          14: 'Navel Orange', 15: 'Pear', 16: 'Avocado', 17: 'Large Onion', 18: 'Cucumber',
                          19: 'Mango', 20: 'Sweet Potato', 21: 'Large Banana', 22: 'Red Bell Pepper',
                          23: 'Grapefruit', 24: 'Pomegranate', 25: 'Eggplant', 26: 'Acorn Squash', 27: 'Cabbage',
                          28: 'Head of Lettuce', 29: 'Head of Cauliflower', 30: 'Bunch of Broccoli', 31: 'Coconut',
                          32: 'Cantaloupe', 33: 'Butternut Squash', 34: 'Pineapple', 35: 'Spaghetti Squash',
                          36: 'Bunch of Kale', 37: 'Canary Melon', 38: 'Mini Watermelon', 39: 'Honeydew Melon',
                          40: 'Small Pumpkin', 41: 'Pumpkin', 42: 'Watermelon' } %}
          {{ sizes[([4, (states("sensor.pregnancy_weeks")|int + states("input_number.pregnancy_size_offset")|int), 42]|sort)[1]] }}
        what_to_expect_link: "https://www.whattoexpect.com/pregnancy/week-by-week/week-{{ states.sensor.pregnancy_weeks.state }}.aspx"
        verywellfamily_link: |
          {% set pages =  { 1: '4158813', 2: '4158819', 3: '4158839', 4: '4158847', 5: '4158868',
                            6: '4158911', 7: '4158916', 8: '4158920', 9: '4158922', 10: '4158926',
                           11: '4158930', 12: '4158934', 13: '4158941', 14: '4158944', 15: '4158988',
                           16: '4158998', 17: '4159005', 14: '4158944', 15: '4158988', 16: '4158998',
                           17: '4159005', 18: '4159009', 19: '4159012', 20: '4159017', 21: '4159022',
                           22: '4159032', 23: '4159036', 24: '4159040', 25: '4159047', 26: '4159097',
                           27: '4159102', 28: '4159110', 29: '4159140', 30: '4159146', 31: '4159202',
                           32: '4159205', 33: '4159211', 34: '4159227', 35: '4159237', 36: '4159243',
                           37: '4159250', 38: '4159251', 39: '4159263', 40: '4159264' } %}
          {% set x = ([1, states('sensor.pregnancy_weeks')|int, 40]|sort)[1] %}
          https://www.verywellfamily.com/{{x|string}}-weeks-pregnant-{{pages[x]}}
        swissmom_link: |
          {% set x = ([6, states('sensor.pregnancy_weeks')|int, 40]|sort)[1] %}
          {% set page_id = (10086 - (x-1)*2) %}
          https://www.swissmom.ch/de/schwangerschaft/ihre-aktuelle-schwangerschaftswoche/{{x|string}}-ssw/ihr-baby-in-der-{{x|string}}-schwangerschaftswoche-{{page_id|string}}
        wireltern_link: |
          {% set x = ([3, states('sensor.pregnancy_weeks')|int, 40]|sort)[1] %}
          https://www.wireltern.ch/artikel/{{x|string}}-woche
        famigros_link: |
          {% set x = ([3, states('sensor.pregnancy_weeks')|int, 40]|sort)[1] %}
          https://famigros.migros.ch/de/schwangerschaft/schwangerschaftskalender/schwangerschaftswoche-{{x|string}}
        babywelten_twins_link: |
          {% set x = ([4, states('sensor.pregnancy_weeks')|int, 40]|sort)[1] %}
          {% set y = x-1 %}
          https://www.babywelten.ch/schwangerschaft/baby-foetus/zwillinge-mehrlinge/zwillinge-in-der-{{x|string}}-woche-ssw{{y|string}}
        twin_development_image: |
          {% set x = states('sensor.pregnancy_weeks')|int %}
          {% if x < 3 %}
          {% set y = "03" %}
          {% elif x <= 4 %}
          {% set y = "04" %}
          {% elif x <= 8 %}
          {% set y = "08" %}
          {% elif x <= 12 %}
          {% set y = "12" %}
          {% elif x <= 16 %}
          {% set y = "16" %}
          {% elif x <= 20 %}
          {% set y = "20" %}
          {% elif x <= 24 %}
          {% set y = "24" %}
          {% elif x <= 28 %}
          {% set y = "28" %}
          {% elif x <= 32 %}
          {% set y = "32" %}
          {% elif x <= 36 %}
          {% set y = "36" %}
          {% endif %}
          https://assets.babycenter.com/intl/de/i/slides/zwillinge/{{y|string}}weeks_twins_424x302.jpg

=== Lovelace Dashboard ===

 - title: Baby
    path: baby
    icon: mdi:baby-carriage
    badges: []
    cards:
      - type: custom:card-templater
        card:
          type: picture-elements
          image_template: '{{ states.sensor.pregnancy.attributes.fetus_size_fruit_image }}'
          elements:
            - type: state-label
              entity: sensor.pregnancy
              style:
                font-size: 20px
                top: 4%
                left: 50%
            - type: state-label
              entity: sensor.pregnancy
              prefix: 'It''s Week '
              attribute: weeks
              suffix: '!'
              style:
                font-size: 40px
                top: 11%
                left: 50%
            - type: state-label
              entity: sensor.pregnancy_weeks
              prefix: '(+ '
              attribute: days_in_week
              suffix: ' Days)'
              style:
                font-size: 20px
                top: 18%
                left: 50%
            - type: custom:text-element
              text: The fetus is about
              style:
                font-size: 16px
                top: 85%
                left: 50%
            - type: state-label
              entity: sensor.pregnancy
              prefix: 'the size of a '
              attribute: fetus_size_fruit
              suffix: '!'
              style:
                font-size: 16px
                top: 90%
                left: 50%
        entities:
          - sensor.pregnancy
      - type: gauge
        name: Baby Download Status
        entity: sensor.pregnancy_percent
        min: 0
        max: 100
        severity:
          green: 66
          yellow: 33
          red: 0
        needle: true
      - type: markdown
        content: >-
          ## Read about week {{ states.sensor.pregnancy.attributes.weeks }} on:

          * [swissmom.ch]({{ states.sensor.pregnancy.attributes.swissmom_link
          }})

          * [wireltern.ch]({{ states.sensor.pregnancy.attributes.wireltern_link
          }})

          * [famigros]({{ states.sensor.pregnancy.attributes.famigros_link }})

          * [babywelten.ch]({{
          states.sensor.pregnancy.attributes.babywelten_twins_link }})
          (twin-specific)
      - type: entities
        entities:
          - entity: sensor.pregnancy_next_check
            icon: mdi:stethoscope
            name: Next Pregnancy Check
          - entity: input_datetime.pregnancy_due_date
            name: Due date
          - entity: sensor.pregnancy_days
            icon: mdi:arrow-left-circle-outline
          - entity: sensor.pregnancy_days_left
            icon: mdi:arrow-right-circle-outline
          - entity: input_number.pregnancy_baby_size
            name: Size Baby
        title: Data

=== Automation ===

alias: 'Baby: Week Updated'
description: Triggered when the baby week changes
trigger:
  - platform: state
    entity_id: sensor.pregnancy_weeks
    to: null
condition: []
action:
  - service: notify.notify
    data:
      title: It's Pregnancy week {{ states('sensor.pregnancy_weeks') }}!
      message: Tap here to read all about what's up this week!
      data:
        clickAction: /lovelace/baby
1 Like

Love what you did with this. But it’s not handling the calculations correctly. Mine should be showing Week 4 Day 4 (first day of last period heper is set to May 4). Instead, it shows Week 5 Day 5 (and subsequently week 5’s fruit image).

Thanks for the input. I think it depends who you ask, we had this discussion as well and I also checked a few pregnancy online calculators (in EMEA environment).

The main question is: where do you start? My calculations consider the day of last period as day1 in pregnancy week 1. According to my tests around here the online calculators do the same.

Due dates are calculated by using the first day of the last period. In our case, it’s May 4th. May 4th-11th is week 1, but in the U.S., us health care professionals don’t consider you to be at that week until it’s been a complete week. So 37 weeks and 6 days isn’t 38 weeks, it’s 37 weeks. So technically, the first 7 days after the first day of the last period are Week 0. I can’t find any calculators online that differ from this either.

Now, this is how the U.S. does it. I’m not sure how other countries do it. Either way, any thoughts on how to start it at Week 0 instead of Week 1? I tried taking out the “+1” in the week template value, which fixed the week, but now it says “Week 5 Day 13” when it should be Week 5 Day 5. Sorry, I’m not the best with the value templates still.

Hey @tango259

Thanks for the followup. In the meantime I came to the same conclusions as you - seems that my calculations were wrong until now :wink:

I adjusted the way the weeks and days are calculated:

    pregnancy_weeks:
      friendly_name: "Pregnancy Week"
      unit_of_measurement: 'weeks'
      value_template: "{{ (((states.sensor.pregnancy_days.state | int) / 7) | round(0, 'floor')) }}"
      attribute_templates:
        days_in_week: "{{ (states.sensor.pregnancy_days.state | int) - ((states.sensor.pregnancy_weeks.state | int )*7) }}"

I also slightly modified the lovelace card:

type: custom:card-templater
card:
  type: picture-elements
  image_template: '{{ states.sensor.pregnancy.attributes.fetus_size_fruit_image }}'
  elements:
    - type: state-label
      entity: sensor.pregnancy
      style:
        font-size: 20px
        top: 4%
        left: 50%
    - type: state-label
      entity: sensor.pregnancy
      prefix: 'It''s Week '
      attribute: weeks
      suffix: '!'
      style:
        font-size: 40px
        top: 11%
        left: 50%
    - type: state-label
      entity: sensor.pregnancy_weeks
      prefix: '(+ '
      attribute: days_in_week
      suffix: ' Days)'
      style:
        font-size: 20px
        top: 18%
        left: 50%
    - type: custom:text-element
      text: The fetus is about
      style:
        font-size: 16px
        top: 85%
        left: 50%
    - type: state-label
      entity: sensor.pregnancy
      prefix: 'the size of a '
      attribute: fetus_size_fruit
      suffix: '!'
      style:
        font-size: 16px
        top: 90%
        left: 50%
entities:
  - sensor.pregnancy

This is how it looks here now:
image

What do you think?

Math is just math. I’m terrible at it. :laughing:

I noticed today it’s doing some weird rounding for some reason. It was saying “Week 7, -1 day” instead of “Week 6, Day 7”. I made a slight modification to Pregnancy Weeks.

    pregnancy_weeks:
      friendly_name: "Pregnancy Week"
      unit_of_measurement: 'weeks'
      value_template: "{{ (((states.sensor.pregnancy_days.state | int) / 8) | round(0, 'floor')) }}"
      attribute_templates:
        days_in_week: "{{ (states.sensor.pregnancy_days.state | int) - ((states.sensor.pregnancy_weeks.state | int )*7) }}"

The goal now is to add on to this awesome tracker. It’s great that my wife can understand the sizes when compared to fruit. There are a few sites out there that give comparisons to more “manly” things, such as cufflinks and a 10mm socket. Might take a bit to figure out how to do it, but I won’t learn if I don’t try!

I have an update. Adding the additional sites was actually pretty easy. I’ve added 3 more categories: Manly, Geeky, and Cravings. Go ahead and pick your poison!

###########################
### Pregnancy Dashboard ###
###########################
- platform: template
  sensors:
    pregnancy_next_check:
      value_template: "{{ as_timestamp(states.calendar['baby_tengowski'].attributes.start_time) | timestamp_custom('%I:%M%p on %a, %B %d') }}"
    pregnancy_days:
      friendly_name: "Days in pregnancy"
      unit_of_measurement: 'days'
      value_template: "{{ (as_timestamp(now()) - as_timestamp(states.input_datetime.pregnancy_last_period.state)) | timestamp_custom('%j') | int }}"
    pregnancy_days_left:
      friendly_name: "Days left until due"
      unit_of_measurement: 'days'
      value_template: "{{ (strptime(states.input_datetime.pregnancy_due_date.state, '%Y-%m-%d') - now().replace(tzinfo=None)).days }}"
    pregnancy_weeks:
      friendly_name: "Pregnancy Week"
      unit_of_measurement: 'weeks'
      value_template: "{{ (((states.sensor.pregnancy_days.state | int) / 8) | round(0, 'floor')) }}"
      attribute_templates:
        days_in_week: "{{ (states.sensor.pregnancy_days.state | int) - ((states.sensor.pregnancy_weeks.state | int )*7) }}"
    pregnancy_percent:
      friendly_name: "Pregnancy Percent"
      unit_of_measurement: '%'
      value_template: "{{ (((states.sensor.pregnancy_days.state | int)*100) / ((states.sensor.pregnancy_days.state | int)+(states.sensor.pregnancy_days_left.state | int))) | int }}"
    pregnancy:
      friendly_name: "Pregnancy"
      unit_of_measurement: 'Trimester'
      value_template: |
        {% set x = (states.sensor.pregnancy_weeks.state | int) %}
        {{ 'First' if x <= 12 else ( 'Second' if x <=24 else 'Third' ) }}
      attribute_templates:
        days: "{{ states.sensor.pregnancy_days.state }}"
        weeks: "{{ states.sensor.pregnancy_weeks.state }}"
        months: "{{ ((states.sensor.pregnancy_days.state | int) / 30.5) | round(1, 'half') }}"
        trimester: "{{ states.sensor.pregnancy.state }}"
        percent: "{{ states.sensor.pregnancy_percent.state }}"
        fetus_size_image: "https://images.agoramedia.com/wte3.0/gcms/wbw_squares_baby_wk_{{ states.sensor.pregnancy_weeks.state }}.jpg"
        fetus_size_fruit_image: "https://images.agoramedia.com/wte3.0/gcms/wbw-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}-fruit.png"
        fetus_size_fruit: |
          {% set sizes = { 4: 'Strawberry Seed', 5: 'Orange Seed', 6: 'Sweet Pea', 7: 'Blueberry', 8: 'Raspberry',
                          9: 'Green Olive', 10: 'Prune', 11: 'Large Strawberry', 12: 'Lime', 13: 'Lemon',
                          14: 'Navel Orange', 15: 'Pear', 16: 'Avocado', 17: 'Large Onion', 18: 'Cucumber',
                          19: 'Mango', 20: 'Sweet Potato', 21: 'Large Banana', 22: 'Red Bell Pepper',
                          23: 'Grapefruit', 24: 'Pomegranate', 25: 'Eggplant', 26: 'Acorn Squash', 27: 'Cabbage',
                          28: 'Head of Lettuce', 29: 'Head of Cauliflower', 30: 'Bunch of Broccoli', 31: 'Coconut',
                          32: 'Cantaloupe', 33: 'Butternut Squash', 34: 'Pineapple', 35: 'Spaghetti Squash',
                          36: 'Bunch of Kale', 37: 'Canary Melon', 38: 'Mini Watermelon', 39: 'Honeydew Melon',
                          40: 'Small Pumpkin', 41: 'Pumpkin', 42: 'Watermelon' } %}
          {{ sizes[([4, (states("sensor.pregnancy_weeks")|int + states("input_number.pregnancy_size_offset")|int), 42]|sort)[1]] }}
        fetus_size_manly_image: "https://babysizer.com/manly/{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}/manly-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}.jpg"
        fetus_size_manly: |
          {% set sizes = { 4: 'a 20 grit grain on a sheet of sandpaper', 5: 'the head on a common nail.', 6: 'a 6-32 screw.', 7: 'a dose of Viagra.', 8: 'a cufflink.',
                          9: 'a lug nut.', 10: 'a poker chip.', 11: 'a golf ball.', 12: 'a scoop of protein powder.', 13: 'a watch.',
                          14: 'a stick shift knob.', 15: 'a travel-size deodorant.', 16: 'a duct tape cardboard roll.', 17: 'a fist bump with a newborn.', 18: 'a multi-tool.',
                          19: 'a pair of sunglasses.', 20: 'a fat stack of cash.', 21: 'a rotary tool.', 22: 'a standard hatchet head.',
                          23: 'a can of WD-40.', 24: 'a Philly cheesesteak.', 25: 'the body of a facehugger.', 26: 'a pair of work gloves.', 27: 'a deflated basketball.',
                          28: 'a baseball cap.', 29: 'the skull of a T-800.', 30: '3 stacked frozen TV dinners.', 31: 'an American football.',
                          32: 'a hard hat.', 33: 'a US size 10 boat shoe.', 34: 'a baseball glove', 35: 'a 50 lb rubber hex dumbbell.',
                          36: 'a power drill.', 37: 'a 1980s brick phone.', 38: 'a chopped firewood log.', 39: 'a box of a dozen Krispy Kreme donuts.',
                          40: 'a badass knights helmet.' } %}
          {{ sizes[([4, (states("sensor.pregnancy_weeks")|int + states("input_number.pregnancy_size_offset")|int), 40]|sort)[1]] }}
        fetus_size_geeky_image: "https://babysizer.com/geeky/{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}/geeky-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}.jpg"
        fetus_size_geeky: |
          {% set sizes = { 4: 'a DIP switch toggle.', 5: 'a Nerd.', 6: 'a Battleship peg.', 7: 'a face on a standard D20 die.', 8: 'a blue pill or a red pill. You choose.',
                          9: 'the One Ring.', 10: 'a golden snitch.', 11: 'a LEGO minifigure.', 12: 'a Minecraft pixel.', 13: 'an arc reactor.',
                          14: 'an original 1977 Star Wars action figure.', 15: 'SpongeBob SquarePants.', 16: 'a can of SPAM.', 17: 'the Holy Hand Grenade of Antioch.', 18: 'a baby tribble.',
                          19: 'an adipose.', 20: 'a red Swingline stapler.', 21: 'a dragon egg.', 22: 'a Pip-Boy.',
                          23: 'a fertility idol.', 24: 'Mr. Burns teddy bear, Bobo.', 25: 'the head of Thors hammer.', 26: 'poor Yorik. A fellow of infinite jest, of most excellent fancy.', 27: 'a pork pie hat.',
                          28: 'a Nintendo.', 29: 'Gizmo.', 30: 'Kon.', 31: 'a Compsognathus.',
                          32: 'a deerstalker hat.', 33: 'a fanny pack.', 34: 'Tim.', 35: 'BMO.',
                          36: 'a 2L bottle of Mountain Dew.', 37: 'a 1980s brick phone.', 38: 'an Oscar statuette.', 39: 'the body of a 4/4 violin.',
                          40: 'Pikachu.' } %}
          {{ sizes[([4, (states("sensor.pregnancy_weeks")|int + states("input_number.pregnancy_size_offset")|int), 40]|sort)[1]] }}
        fetus_size_cravings_image: "https://babysizer.com/cravings/{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}/cravings-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}.jpg"
        fetus_size_cravings: |
          {% set sizes = { 4: 'a grain of table salt.', 5: 'a Pop Rocks crystal.', 6: 'a rainbow sprinkle.', 7: 'a Tic Tac.', 8: 'a peanut M&M.',
                          9: 'a tater tot.', 10: 'a Ferrero Rocher.', 11: 'a donut hole.', 12: 'a chicken nugget.', 13: 'a scoop of ice cream.',
                          14: 'an 8 oz filet mignon.', 15: 'a cinnamon roll.', 16: 'a can of pop, soda, soft drink, coke, or whatever you call it.', 17: 'a large order of fries.', 18: 'a tall, decaf, non-fat, Frappuccino with whipped cream and caramel drizzle.',
                          19: 'a hot dog.', 20: 'root beer.', 21: 'a Chipotle burrito.', 22: 'a bag of half a dozen bagels.',
                          23: 'a box of Mac & Cheese.', 24: 'a package of Oreos.', 25: 'a popped bag of microwave popcorn.', 26: 'a Double Gulp cup.', 27: 'a big bottle of Sriracha.',
                          28: 'a 1 pound basket of wings.', 29: 'a 1 gallon jug of milk.', 30: 'half of a large cheesecake from Cheesecake Factory', 31: 'an 11 lb (5 kg) jar of Nutella.',
                          32: 'a mega Chupa Chups lollipop.', 33: 'a store-bought loaf of sliced bread.', 34: 'a large bag of potato chips.', 35: 'a carton of one dozen eggs.',
                          36: 'a footlong sub.', 37: 'half a medium pizza.', 38: 'a bucket of fried chicken.', 39: 'a full rack of pork back ribs',
                          40: 'a 15 lb Thanksgiving turkey.' } %}
          {{ sizes[([4, (states("sensor.pregnancy_weeks")|int + states("input_number.pregnancy_size_offset")|int), 40]|sort)[1]] }}
        what_to_expect_link: "https://www.whattoexpect.com/pregnancy/week-by-week/week-{{ states.sensor.pregnancy_weeks.state }}.aspx"
        verywellfamily_link: |
          {% set pages =  { 1: '4158813', 2: '4158819', 3: '4158839', 4: '4158847', 5: '4158868',
                            6: '4158911', 7: '4158916', 8: '4158920', 9: '4158922', 10: '4158926',
                            11: '4158930', 12: '4158934', 13: '4158941', 14: '4158944', 15: '4158988',
                            16: '4158998', 17: '4159005', 14: '4158944', 15: '4158988', 16: '4158998',
                            17: '4159005', 18: '4159009', 19: '4159012', 20: '4159017', 21: '4159022',
                            22: '4159032', 23: '4159036', 24: '4159040', 25: '4159047', 26: '4159097',
                            27: '4159102', 28: '4159110', 29: '4159140', 30: '4159146', 31: '4159202',
                            32: '4159205', 33: '4159211', 34: '4159227', 35: '4159237', 36: '4159243',
                            37: '4159250', 38: '4159251', 39: '4159263', 40: '4159264' } %}
          {% set x = ([1, states('sensor.pregnancy_weeks')|int, 40]|sort)[1] %}
          https://www.verywellfamily.com/{{x|string}}-weeks-pregnant-{{pages[x]}}
        manly_link: "https://babysizer.com/manly/{{ states.sensor.pregnancy_weeks.state }}"
        geeky_link: "https://babysizer.com/geeky/{{ states.sensor.pregnancy_weeks.state }}"
        cravings_link: "https://babysizer.com/cravings/{{ states.sensor.pregnancy_weeks.state }}"

Why do you devide the days in the value_template by /8? a week has only 7 days IMHO :wink:

Additionally: anyone else having the problem that the text-element custom-card is no longer referenced from HACS?

No problems with the custom card, at least with the original dashboard. I copied the card to use it with the other size references and my text is squished.

I divided by 8 in order to get the Day number to show correctly. And it only works 6 out of 7 days. I have a very limited knowledge when it comes to math calculations in code. For me, Wednesday is the start of our week. So every Wednesday, it should show Day 0, and every Tuesday should show Day 7. For some reason when it was dividing by 7, my days were off a little. But when I divide by 8, it’s mostly correct, except I noticed this past Tuesday it said “Week 10 Day -1”. It’s not wrong, but it’s not right either. :man_shrugging:

I think I’ve found the issue - not sure anymore why I had a -1 in the days_in_week calculation - corrected it in all versions above:

    pregnancy_weeks:
      friendly_name: "Pregnancy Week"
      unit_of_measurement: 'weeks'
      value_template: "{{ (((states.sensor.pregnancy_days.state | int) / 8) | round(0, 'floor')) }}"
      attribute_templates:
        days_in_week: "{{ (states.sensor.pregnancy_days.state | int) - ((states.sensor.pregnancy_weeks.state | int )*7) }}"

Tested it and seems to be OK now:

Any better @tango259 ?

Did you copypaste what you meant to? Because both the quote and your new code blocks are it’s identical.

I have to say that this has become quite a robust project at this point. I’ve made a few more updates to the code to add some features.

  • :vertical_traffic_light: Minor change made to trimester calculation. 3rd trimester changed from 24 to 28 weeks.

  • :straight_ruler: Added a sensor for each week’s average length. (mostly because I was too lazy to keep adjusting the input number :laughing:)

  • :weight_lifting_man: Added a sensor for each week’s average weight.

  • :camera: Added a picture card to display the latest ultrasound or sonogram (stored locally).

  • :open_book: Added another option for size references. When I first found out my wife was pregnant, I got “A Dude’s Guide to Baby Size” by Taylor Calmus (the Dude Dad guy). Figured I’d add his references in as well. (They are text-only unless you downloaded a picture for each, added them to your storage, and referenced them that way.)

  • :baby_bottle: Added a fetal_development attribute to the pregnancy sensor which displays text regarding that week’s fetal development milestones. (Credit to Mayo Clinic)

  • :clock3: Raphi and I have been working to get the day_in_week calculation correct (maybe it’s just mine that’s messed up).

  • :construction: The 3 extra cards I have for baby sizes are still a little difficult to read, still trying to figure out how to fix that.

==== Config Code ====

###########################
### Pregnancy Dashboard ###
###########################
template:
  - sensor:
      - name: "Pregnancy Next Check"
        state: "{{ state_attr('calendar.baby_calendar', 'start_time') | as_timestamp | timestamp_custom('%-I:%M%p on %a, %B %d') }}"
      - name: "Pregnancy Days"
        unit_of_measurement: 'days'
        state: "{{ (now() - states('input_datetime.pregnancy_last_period') | as_datetime | as_local).days }}"
      - name: "Pregnancy Days Left"
        unit_of_measurement: 'days'
        state: "{{ (states('input_datetime.pregnancy_due_date') | as_datetime | as_local - now()).days }}"
      - name: "Pregnancy Weeks"
        unit_of_measurement: 'weeks'
        state: "{{ states('sensor.pregnancy_days') | int // 7 }}"
        availability: "{{ states('sensor.pregnancy_days') | is_number }}"
        attributes:
          days_in_week: "{{ states('sensor.pregnancy_days') | int % 7 }}"
        # This attribute purposfully calculates day of the week between 0 and 6, following U.S. healthcare standards.
      - name: "Pregnancy Percent"
        unit_of_measurement: '%'
        state: "{{ (((states('sensor.pregnancy_days') | int)*100) / ((states('sensor.pregnancy_days') | int)+(states('sensor.pregnancy_days_left') | int))) | int }}"
      - name: "Pregnancy Fetal Length"
        unit_of_measurement: 'inches'
        state: >-
          {% set sizes = {8: '3/4',
                          9: '1', 10: '1 1/4', 11: '1 1/2', 12: '2 1/4', 13: '3',
                          14: '3 1/2', 15: '4', 16: '4 1/2', 17: '5', 18: '5 1/2',
                          19: '6', 20: '10', 21: '10 1/2', 22: '11',
                          23: '11 1/2', 24: '11 3/4', 25: '13 1/2', 26: '14', 27: '14 1/2',
                          28: '14 3/4', 29: '15', 30: '15 3/4', 31: '16 1/4',
                          32: '16 3/4', 33: '17 1/4', 34: '17 3/4', 35: '18 1/4',
                          36: '18 3/4', 37: '19 1/4', 38: '19 1/2', 39: '20',
                          40: '20 1/4' } %}
          {{ sizes[([8, (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int), 40]|sort)[1]] }}
      - name: "Pregnancy Fetal Weight"
        state: >-
          {% set sizes = {8: '0.04 ounces',
                          9: '0.07 ounces', 10: '0.14 ounces', 11: '1/4 ounce', 12: '1/2 ounce', 13: '3/4 ounce',
                          14: '1 1/2 ounces', 15: '2 1/2 ounces', 16: '3 1/2 ounces', 17: '5 ounces', 18: '6 3/4 ounces',
                          19: '8 1/2 ounces', 20: '10 1/2 ounces', 21: '12 3/4 ounces', 22: '15 ounces',
                          23: '1 pound', 24: '1 1/4 pounds', 25: '1 1/4 pounds', 26: '1 3/4 pounds', 27: '2 pounds',
                          28: '2 1/4 pounds', 29: '2 1/2 pounds', 30: '3 pounds', 31: '3 1/4 pounds',
                          32: '3 3/4 pounds', 33: '4 1/3 pounds', 34: '4 3/4 pounds', 35: '5 1/4 pounds',
                          36: '5 3/4 pounds', 37: '6 1/2 pounds', 38: '6 3/4 pounds', 39: '7 1/4 pounds',
                          40: '7 3/4 pounds' } %}
          {{ sizes[([8, (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int), 40]|sort)[1]] }}
      - name: "Pregnancy"
        unit_of_measurement: 'Trimester'
        state: |
          {% set x = (states('sensor.pregnancy_weeks') | int) %}
          {{ 'First' if x <= 12 else ( 'Second' if x <=28 else 'Third' ) }}
        attributes:
          days: "{{ states('sensor.pregnancy_days') }}"
          weeks: "{{ states('sensor.pregnancy_weeks') }}"
          months: "{{ ((states('sensor.pregnancy_days') | int) / 30.5) | round(1, 'half') }}"
          trimester: "{{ states('sensor.pregnancy') }}"
          percent: "{{ states('sensor.pregnancy_percent') }}"
          fetus_size_image: "https://images.agoramedia.com/wte3.0/gcms/wbw_squares_baby_wk_{{ states('sensor.pregnancy_weeks') }}.jpg"
          fetus_size_fruit_image: "https://images.agoramedia.com/wte3.0/gcms/wbw-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}-fruit.png"
          fetus_size_fruit: |
            {% set sizes = { 4: 'Strawberry Seed', 5: 'Orange Seed', 6: 'Sweet Pea', 7: 'Blueberry', 8: 'Raspberry',
                            9: 'Green Olive', 10: 'Prune', 11: 'Large Strawberry', 12: 'Lime', 13: 'Lemon',
                            14: 'Navel Orange', 15: 'Pear', 16: 'Avocado', 17: 'Large Onion', 18: 'Cucumber',
                            19: 'Mango', 20: 'Sweet Potato', 21: 'Large Banana', 22: 'Red Bell Pepper',
                            23: 'Grapefruit', 24: 'Pomegranate', 25: 'Eggplant', 26: 'Acorn Squash', 27: 'Cabbage',
                            28: 'Head of Lettuce', 29: 'Head of Cauliflower', 30: 'Bunch of Broccoli', 31: 'Coconut',
                            32: 'Cantaloupe', 33: 'Butternut Squash', 34: 'Pineapple', 35: 'Spaghetti Squash',
                            36: 'Bunch of Kale', 37: 'Canary Melon', 38: 'Mini Watermelon', 39: 'Honeydew Melon',
                            40: 'Small Pumpkin', 41: 'Pumpkin', 42: 'Watermelon' } %}
            {{ sizes[([4, (states("sensor.pregnancy_weeks")|int + states("input_number.pregnancy_size_offset")|int), 42]|sort)[1]] }}
          fetus_size_manly_image: "https://babysizer.com/manly/{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}/manly-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}.jpg"
          fetus_size_manly: |
            {% set sizes = { 4: 'a 20 grit grain on a sheet of sandpaper', 5: 'the head on a common nail.', 6: 'a 6-32 screw.', 7: 'a dose of Viagra.', 8: 'a cufflink.',
                            9: 'a lug nut.', 10: 'a poker chip.', 11: 'a golf ball.', 12: 'a scoop of protein powder.', 13: 'a watch.',
                            14: 'a stick shift knob.', 15: 'a travel-size deodorant.', 16: 'a duct tape cardboard roll.', 17: 'a fist bump with a newborn.', 18: 'a multi-tool.',
                            19: 'a pair of sunglasses.', 20: 'a fat stack of cash.', 21: 'a rotary tool.', 22: 'a standard hatchet head.',
                            23: 'a can of WD-40.', 24: 'a Philly cheesesteak.', 25: 'the body of a facehugger.', 26: 'a pair of work gloves.', 27: 'a deflated basketball.',
                            28: 'a baseball cap.', 29: 'the skull of a T-800.', 30: '3 stacked frozen TV dinners.', 31: 'an American football.',
                            32: 'a hard hat.', 33: 'a US size 10 boat shoe.', 34: 'a baseball glove', 35: 'a 50 lb rubber hex dumbbell.',
                            36: 'a power drill.', 37: 'a 1980s brick phone.', 38: 'a chopped firewood log.', 39: 'a box of a dozen Krispy Kreme donuts.',
                            40: 'a badass knights helmet.' } %}
            {{ sizes[([4, (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int), 40]|sort)[1]] }}
          fetus_size_geeky_image: "https://babysizer.com/geeky/{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}/geeky-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}.jpg"
          fetus_size_geeky: |
            {% set sizes = { 4: 'a DIP switch toggle.', 5: 'a Nerd.', 6: 'a Battleship peg.', 7: 'a face on a standard D20 die.', 8: 'a blue pill or a red pill. You choose.',
                            9: 'the One Ring.', 10: 'a golden snitch.', 11: 'a LEGO minifigure.', 12: 'a Minecraft pixel.', 13: 'an arc reactor.',
                            14: 'an original 1977 Star Wars action figure.', 15: 'SpongeBob SquarePants.', 16: 'a can of SPAM.', 17: 'the Holy Hand Grenade of Antioch.', 18: 'a baby tribble.',
                            19: 'an adipose.', 20: 'a red Swingline stapler.', 21: 'a dragon egg.', 22: 'a Pip-Boy.',
                            23: 'a fertility idol.', 24: 'Mr. Burns teddy bear, Bobo.', 25: 'the head of Thors hammer.', 26: 'poor Yorik. A fellow of infinite jest, of most excellent fancy.', 27: 'a pork pie hat.',
                            28: 'a Nintendo.', 29: 'Gizmo.', 30: 'Kon.', 31: 'a Compsognathus.',
                            32: 'a deerstalker hat.', 33: 'a fanny pack.', 34: 'Tim.', 35: 'BMO.',
                            36: 'a 2L bottle of Mountain Dew.', 37: 'a 1980s brick phone.', 38: 'an Oscar statuette.', 39: 'the body of a 4/4 violin.',
                            40: 'Pikachu.' } %}
            {{ sizes[([4, (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int), 40]|sort)[1]] }}
          fetus_size_cravings_image: "https://babysizer.com/cravings/{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}/cravings-{{ (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int) }}.jpg"
          fetus_size_cravings: |
            {% set sizes = { 4: 'a grain of table salt.', 5: 'a Pop Rocks crystal.', 6: 'a rainbow sprinkle.', 7: 'a Tic Tac.', 8: 'a peanut M&M.',
                            9: 'a tater tot.', 10: 'a Ferrero Rocher.', 11: 'a donut hole.', 12: 'a chicken nugget.', 13: 'a scoop of ice cream.',
                            14: 'an 8 oz filet mignon.', 15: 'a cinnamon roll.', 16: 'a can of pop, soda, soft drink, coke, or whatever you call it.', 17: 'a large order of fries.', 18: 'a tall, decaf, non-fat, Frappuccino with whipped cream and caramel drizzle.',
                            19: 'a hot dog.', 20: 'root beer.', 21: 'a Chipotle burrito.', 22: 'a bag of half a dozen bagels.',
                            23: 'a box of Mac & Cheese.', 24: 'a package of Oreos.', 25: 'a popped bag of microwave popcorn.', 26: 'a Double Gulp cup.', 27: 'a big bottle of Sriracha.',
                            28: 'a 1 pound basket of wings.', 29: 'a 1 gallon jug of milk.', 30: 'half of a large cheesecake from Cheesecake Factory.', 31: 'an 11 lb (5 kg) jar of Nutella.',
                            32: 'a mega Chupa Chups lollipop.', 33: 'a store-bought loaf of sliced bread.', 34: 'a large bag of potato chips.', 35: 'a carton of one dozen eggs.',
                            36: 'a footlong sub.', 37: 'half a medium pizza.', 38: 'a bucket of fried chicken.', 39: 'a full rack of pork back ribs.',
                            40: 'a 15 lb Thanksgiving turkey.' } %}
            {{ sizes[([4, (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int), 40]|sort)[1]] }}
          fetus_size_dude_dad: |
            {% set sizes = { 4: 'a BB.', 5: 'a match head.', 6: 'a kernel of popcorn.', 7: 'a cheerio.', 8: 'a 10mm socket.',
                            9: 'a guitar pick.', 10: 'a lug nut.', 11: 'a condom.', 12: 'a jumbo marshmallow.', 13: 'a baseball.',
                            14: 'a tape measure.', 15: 'a beer can.', 16: 'a grenade.', 17: 'a bottle of sanitizer.', 18: 'cup of coffee.',
                            19: 'a fire alarm.', 20: 'fresh roll of toilet paper.', 21: 'a quart of oil.', 22: 'a pound of ground beef.',
                            23: 'Bose noise-canceling headphones.', 24: 'concession-stand nachos.', 25: 'a bowl of Olive Garden soup and breadsticks.', 26: 'a baseball glove.', 27: 'a gallon of paint.',
                            28: 'a milk jug.', 29: 'a human head.', 30: 'a garbage disposal', 31: 'a circular saw.',
                            32: 'a football.', 33: 'a car battery.', 34: 'a largemouth bass.', 35: 'a bicycle helmate.',
                            36: 'a 6lb brisket.', 37: 'a small, yippy dog.', 38: 'a Playmate lunch cooler.', 39: 'a Galápagos Penguine.',
                            40: 'a toolbox.' } %}
            {{ sizes[([4, (states('sensor.pregnancy_weeks')|int + states("input_number.pregnancy_size_offset")|int), 40]|sort)[1]] }}
          what_to_expect_link: "https://www.whattoexpect.com/pregnancy/week-by-week/week-{{ states('sensor.pregnancy_weeks') }}.aspx"
          verywellfamily_link: |
            {% set pages =  { 1: '4158813', 2: '4158819', 3: '4158839', 4: '4158847', 5: '4158868',
                              6: '4158911', 7: '4158916', 8: '4158920', 9: '4158922', 10: '4158926',
                              11: '4158930', 12: '4158934', 13: '4158941', 14: '4158944', 15: '4158988',
                              16: '4158998', 17: '4159005', 14: '4158944', 15: '4158988', 16: '4158998',
                              17: '4159005', 18: '4159009', 19: '4159012', 20: '4159017', 21: '4159022',
                              22: '4159032', 23: '4159036', 24: '4159040', 25: '4159047', 26: '4159097',
                              27: '4159102', 28: '4159110', 29: '4159140', 30: '4159146', 31: '4159202',
                              32: '4159205', 33: '4159211', 34: '4159227', 35: '4159237', 36: '4159243',
                              37: '4159250', 38: '4159251', 39: '4159263', 40: '4159264' } %}
            {% set x = ([1, states('sensor.pregnancy_weeks')|int, 40]|sort)[1] %}
            https://www.verywellfamily.com/{{x|string}}-weeks-pregnant-{{pages[x]}}
          manly_link: "https://babysizer.com/manly/{{ states('sensor.pregnancy_weeks') }}"
          geeky_link: "https://babysizer.com/geeky/{{ states('sensor.pregnancy_weeks') }}"
          cravings_link: "https://babysizer.com/cravings/{{ states('sensor.pregnancy_weeks') }}"
          mayo_clinic_link: "https://www.mayoclinic.org/healthy-lifestyle/pregnancy-week-by-week/in-depth/hlv-20049471"
          fetal_development: |
            {% set sizes = {4: "The rapidly dividing ball of cells — now known as a blastocyst — has begun to burrow into the uterine lining (endometrium). This process is called implantation.\n\nWithin the blastocyst, the inner group of cells will become the embryo. The outer layer will give rise to part of the placenta, which will nourish your baby throughout the pregnancy.",
                            5: "The fifth week of pregnancy, or the third week after conception, the levels of HCG hormone produced by the blastocyst quickly increase. This signals your ovaries to stop releasing eggs and produce more estrogen and progesterone. Increased levels of these hormones stop your menstrual period, often the first sign of pregnancy, and fuel the growth of the placenta.\n\nThe embryo is now made of three layers. The top layer — the ectoderm — will give rise to your baby's outermost layer of skin, central and peripheral nervous systems, eyes, and inner ears.\n\nYour baby's heart and a primitive circulatory system will form in the middle layer of cells — the mesoderm. This layer of cells will also serve as the foundation for your baby's bones, ligaments, kidneys and much of the reproductive system.\n\nThe inner layer of cells — the endoderm — is where your baby's lungs and intestines will develop.", 
                            6: "Growth is rapid this week. Just four weeks after conception, the neural tube along your baby's back is closing. The baby's brain and spinal cord will develop from the neural tube. The heart and other organs also are starting to form.\n\nStructures necessary to the formation of the eyes and ears develop. Small buds appear that will soon become arms. Your baby's body begins to take on a C-shaped curvature.", 
                            7: "Seven weeks into your pregnancy, or five weeks after conception, your baby's brain and face are growing. Depressions that will give rise to nostrils become visible, and the beginnings of the retinas form.\n\nLower limb buds that will become legs appear and the arm buds that sprouted last week now take on the shape of paddles.", 
                            8: "Eight weeks into your pregnancy, or six weeks after conception, your baby's lower limb buds take on the shape of paddles. Fingers have begun to form. Small swellings outlining the future shell-shaped parts of your baby's ears develop and the eyes become obvious. The upper lip and nose have formed. The trunk and neck begin to straighten.\n\nBy the end of this week, your baby might be about 1/2 inch (11 to 14 millimeters) long from crown to rump — about half the diameter of a U.S. quarter.", 
                            9: "In the ninth week of pregnancy, or seven weeks after conception, your baby's arms grow and elbows appear. Toes are visible and eyelids form. Your baby's head is large but still has a poorly formed chin.\n\nBy the end of this week, your baby might be a little less than 3/4 inch (16 to 18 millimeters) long from crown to rump — the diameter of a U.S. penny.", 
                            10: "By the 10th week of pregnancy, or eight weeks after conception, your baby's head has become more round.\n\nYour baby can now bend his or her elbows. Toes and fingers lose their webbing and become longer. The eyelids and external ears continue to develop. The umbilical cord is clearly visible.", 
                            11: "At the beginning of the 11th week of pregnancy, or the ninth week after conception, your baby's head still makes up about half of its length. However, your baby's body is about to catch up.\n\nYour baby is now officially described as a fetus. This week your baby's face is broad, the eyes widely separated, the eyelids fused and the ears low set. Buds for future teeth appear. Red blood cells are beginning to form in your baby's liver. By the end of this week, your baby's external genitalia will start developing into a penis or a clitoris and labia majora.\n\nBy now your baby might measure about 2 inches (50 millimeters) long from crown to rump — the length of the short side of a credit card — and weigh almost 1/3 ounce (8 grams).", 
                            12: "Twelve weeks into your pregnancy, or 10 weeks after conception, your baby is sprouting fingernails. Your baby's face now has taken on a more developed profile. His or her intestines are in the abdomen.\n\nBy now your baby might be about 2 1/2 inches (61 millimeters) long from crown to rump — the length of the short side of a U.S. bill — and weigh about 1/2 ounce (14 grams).", 
                            13: "Welcome to the 2nd Trimester! Thirteen weeks into your pregnancy, or 11 weeks after conception, your baby is beginning to make urine and release it into the surrounding amniotic fluid. Your baby also swallows some amniotic fluid.\n\nBones are beginning to harden in your baby's skeleton, especially in the skull and long bones. Your baby's skin is still thin and transparent, but it will start to thicken soon.",
                            14: "Fourteen weeks into your pregnancy, or 12 weeks after conception, your baby's neck has become more defined. Red blood cells are forming in your baby's spleen.\n\nYour baby's sex will become apparent this week or in the coming weeks.\n\nBy now your baby might be almost 3 1/2 inches (87 millimeters) long from crown to rump and weigh about 1 1/2 ounces (45 grams).", 
                            15: "Fifteen weeks into your pregnancy, or 13 weeks after conception, your baby is growing rapidly. Bone development continues and will soon become visible on ultrasound images. Your baby's scalp hair pattern also is forming.", 
                            16: "Sixteen weeks into your pregnancy, or 14 weeks after conception, your baby's head is erect. His or her eyes can slowly move. The ears are close to reaching their final position. Your baby's skin is getting thicker.\n\nYour baby's limb movements are becoming coordinated and can be detected during ultrasound exams. However, these movements are still too slight to be felt by you.\n\nBy now your baby might be more than 4 1/2 inches (120 millimeters) long from crown to rump and weigh close to 4 ounces (110 grams).", 
                            17: "Seventeen weeks into your pregnancy, or 15 weeks after conception, toenails begin developing.\n\nYour baby is becoming more active in the amniotic sac, rolling and flipping. His or her heart is pumping about 100 pints of blood each day.", 
                            18: "Eighteen weeks into your pregnancy, or 16 weeks after conception, your baby's ears begin to stand out on the sides of his or her head. Your baby might begin to hear sounds. The eyes are beginning to face forward. Your baby's digestive system has started working.\n\nBy now your baby might be 5 1/2 inches (140 millimeters) long from crown to rump and weigh 7 ounces (200 grams).",
                            19: "Nineteen weeks into your pregnancy, or 17 weeks after conception, growth slows.\n\nA greasy, cheeselike coating called vernix caseosa begins to cover your baby. The vernix caseosa helps protect your baby's delicate skin from abrasions, chapping and hardening that can result from exposure to amniotic fluid.\n\nFor girls, the uterus and vaginal canal are forming.", 
                            20: "Halfway into your pregnancy, or 18 weeks after conception, you might be able to feel your baby's movements (quickening). Your baby is regularly sleeping and waking. He or she might be awakened by noises or your movements.\n\nBy now your baby might be about 6 1/3 inches (160 millimeters) long from crown to rump and weigh more than 11 ounces (320 grams).", 
                            21: "Twenty-one weeks into your pregnancy, or 19 weeks after conception, your baby is completely covered with a fine, downy hair called lanugo. The lanugo helps hold the vernix caseosa on the skin.\n\nThe sucking reflex also is developing, enabling your baby to suck his or her thumb.", 
                            22: "Twenty-two weeks into your pregnancy, or 20 weeks after conception, your baby's eyebrows and hair are visible. Brown fat also is forming, the site of heat production.\n\nFor boys, the testes have begun to descend.\n\nBy now your baby might be 7 1/2 inches (190 millimeters) long from crown to rump and weigh about 1 pound (460 grams).",
                            23: "Twenty-three weeks into your pregnancy, or 21 weeks after conception, your baby begins to have rapid eye movements. Ridges also form in the palms of the hands and soles of the feet that will later create the foundation for fingerprints and footprints.\n\nYour baby might begin hiccuping, causing jerking movements.", 
                            24: "Twenty-four weeks into your pregnancy, or 22 weeks after conception, your baby's skin is wrinkled, translucent and pink to red because of visible blood in the capillaries.\n\nBy now your baby might be about 8 inches (210 millimeters) long from crown to rump and weigh more than 1 1/3 pounds (630 grams).", 
                            25: "Twenty-five weeks into your pregnancy, or 23 weeks after conception, your baby might be able to respond to familiar sounds, such as your voice, with movement.\n\nYour baby is spending most of his or her sleep time in rapid eye movement (REM), when the eyes move rapidly even though the eyelids are closed.", 
                            26: "Twenty-six weeks into your pregnancy, or 24 weeks after conception, your baby's lungs are beginning to produce surfactant, the substance that allows the air sacs in the lungs to inflate — and keeps them from collapsing and sticking together when they deflate.\n\nBy now your baby might be 9 inches (230 millimeters) long from crown to rump and weigh nearly 2 pounds (820 grams).", 
                            27: "This week marks the end of the second trimester. At 27 weeks, or 25 weeks after conception, your baby's nervous system is continuing to mature. Your baby is also gaining fat, which will help his or her skin look smoother.",
                            28: "Welcome to the 3rd Trimester! You're approaching the finish line! Twenty-eight weeks into your pregnancy, or 26 weeks after conception, your baby's eyelids can partially open and eyelashes have formed. The central nervous system can direct rhythmic breathing movements and control body temperature.\n\nBy now your baby might be nearly 10 inches (250 millimeters) long from crown to rump and weigh nearly 2 1/4 pounds (1,000 grams).", 
                            29: "Twenty-nine weeks into your pregnancy, or 27 weeks after conception, your baby can kick, stretch and make grasping movements.", 
                            30: "Thirty weeks into your pregnancy, or 28 weeks after conception, your baby's eyes can open wide. Your baby might have a good head of hair by this week. Red blood cells are forming in your baby's bone marrow.\n\nBy now your baby might be more than 10 1/2 inches (270 millimeters) long from crown to rump and weigh nearly 3 pounds (1,300 grams).", 
                            31: "Thirty-one weeks into your pregnancy, or 29 weeks after conception, your baby has finished most of his or her major development. Now it's time to gain weight — quickly.",
                            32: "Thirty-two weeks into your pregnancy, or 30 weeks after conception, your baby's toenails are visible.\n\nThe layer of soft, downy hair that has covered your baby's skin for the past few months (lanugo) starts to fall off this week.\n\nBy now your baby might be 11 inches (280 millimeters) long from crown to rump and weigh 3 3/4 pounds (1,700 grams).", 
                            33: "Thirty-three weeks into your pregnancy, or 31 weeks after conception, your baby's pupils can change size in response to a stimulus caused by light. His or her bones are hardening. However, the skull remains soft and flexible.", 
                            34: "Thirty-four weeks into your pregnancy, or 32 weeks after conception, your baby's fingernails have reached his or her fingertips.\n\nBy now your baby might be nearly 12 inches (300 millimeters) long from crown to rump and weigh more than 4 1/2 pounds (2,100 grams).", 
                            35: "Thirty-five weeks into your pregnancy, or 33 weeks after conception, your baby's skin is becoming smooth. His or her limbs have a chubby appearance.",
                            36: "Thirty-six weeks into your pregnancy, or 34 weeks after conception, the crowded conditions inside your uterus might make it harder for your baby to give you a punch. However, you'll probably still feel lots of stretches, rolls and wiggles.", 
                            37: "Thirty-seven weeks into your pregnancy, or 35 weeks after conception, your baby has a firm grasp.\n\nTo prepare for birth, your baby's head might start descending into your pelvis. If your baby isn't head down, your health care provider will talk to you about ways to deal with this issue.", 
                            38: "Thirty-eight weeks into your pregnancy, or 36 weeks after conception, the circumference of your baby's head and abdomen are about the same.\n\nYour baby's toenails have reached the tips of his or her toes. Your baby has mostly shed all of his or her lanugo.\n\nBy now your baby might weigh about 6 1/2 pounds (2,900 grams).", 
                            39: "Thirty-nine weeks into your pregnancy, or 37 weeks after conception, your baby's chest is becoming more prominent. For boys, the testes continue to descend into the scrotum. Fat is being added all over your baby's body to keep him or her warm after birth.",
                            40: "Congratulations! At forty weeks into your pregnancy, or 38 weeks after conception, you've reach the finish line! Your baby might have a crown-to-rump length of around 14 inches (360 millimeters) and weigh 7 1/2 pounds (3,400 grams). Remember, however, that healthy babies come in different sizes.\n\nDon't be alarmed if your due date comes and goes with no signs of labor starting. Your due date is simply a calculated estimate of when your pregnancy will be 40 weeks. It does not estimate when your baby will arrive. It's normal to give birth before or after your due date." } %}
            {{ sizes[([4, (states('sensor.pregnancy_weeks')|int + states('input_number.pregnancy_size_offset')|int), 40]|sort)[1]] }}

==== Lovelace Dashboard ====

  - theme: Backend-selected
    title: Baby
    path: baby
    icon: mdi:baby-carriage
    badges: []
    cards:
      - type: vertical-stack
        cards:
          - type: vertical-stack
            cards:
              - type: custom:card-templater
                card:
                  type: picture-elements
                  image_template: >-
                    {{ states.sensor.pregnancy.attributes.fetus_size_fruit_image
                    }}
                  elements:
                    - type: state-label
                      entity: sensor.pregnancy
                      style:
                        font-size: 20px
                        top: 4%
                        left: 50%
                    - type: state-label
                      entity: sensor.pregnancy
                      prefix: 'It''s Week '
                      attribute: weeks
                      suffix: '!'
                      style:
                        font-size: 40px
                        top: 11%
                        left: 50%
                    - type: state-label
                      entity: sensor.pregnancy_weeks
                      prefix: '(Day '
                      attribute: days_in_week
                      suffix: )
                      style:
                        font-size: 20px
                        top: 18%
                        left: 50%
                    - type: custom:text-element
                      text: The fetus is about
                      style:
                        font-size: 16px
                        top: 85%
                        left: 50%
                    - type: state-label
                      entity: sensor.pregnancy
                      prefix: 'the size of a '
                      attribute: fetus_size_fruit
                      suffix: '!'
                      style:
                        font-size: 16px
                        top: 90%
                        left: 50%
                entities:
                  - sensor.pregnancy
          - type: gauge
            name: Baby Download Status
            entity: sensor.pregnancy_percent
            min: 0
            max: 100
            severity:
              green: 66
              yellow: 33
              red: 0
            needle: true
            unit: '%'
          - type: markdown
            content: >
              ## Read about week {{ states.sensor.pregnancy.attributes.weeks }}
              on:

              * [What To Expect]({{
              states.sensor.pregnancy.attributes.what_to_expect_link }})

              * [Verywell Family]({{
              states.sensor.pregnancy.attributes.verywellfamily_link }})

              * [Mayo Clinic]({{
              states.sensor.pregnancy.attributes.mayo_clinic_link }})

              * [Manly]({{ states.sensor.pregnancy.attributes.manly_link }})

              * [Geeky]({{ states.sensor.pregnancy.attributes.geeky_link }})

              * [Cravings]({{ states.sensor.pregnancy.attributes.cravings_link
              }})
      - type: vertical-stack
        cards:
          - type: picture
            image: /local/ultrasound_week_8.jpeg
            tap_action:
              action: none
            hold_action:
              action: none
          - type: markdown
            content: >
              ## Week {{ states.sensor.pregnancy.attributes.weeks }}
              Developmental Milestones:

              {{ states.sensor.pregnancy.attributes.fetal_development }}
          - type: entities
            entities:
              - entity: sensor.pregnancy_next_check
                icon: mdi:stethoscope
                name: Next Pregnancy Check
              - entity: input_datetime.pregnancy_due_date
                name: Due date
              - entity: sensor.pregnancy_days
                icon: mdi:arrow-left-circle-outline
              - entity: sensor.pregnancy_days_left
                icon: mdi:arrow-right-circle-outline
              - entity: sensor.pregnancy
                name: Pregnancy Trimester
              - entity: sensor.pregnancy_fetal_length
                icon: mdi:ruler
              - entity: sensor.pregnancy_fetal_weight
                icon: mdi:weight
            title: Data
      - type: vertical-stack
        cards:
          - type: custom:card-templater
            card:
              type: picture-elements
              image_template: '{{ states.sensor.pregnancy.attributes.fetus_size_manly_image }}'
              elements:
                - type: state-label
                  entity: sensor.pregnancy
                  style:
                    font-size: 20px
                    top: 10%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy
                  prefix: 'It''s Week '
                  attribute: weeks
                  suffix: '!'
                  style:
                    font-size: 40px
                    top: 30%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy_weeks
                  prefix: '(Day '
                  attribute: days_in_week
                  suffix: )
                  style:
                    font-size: 30px
                    top: 45%
                    left: 50%
                - type: custom:text-element
                  text: The fetus is about
                  style:
                    font-size: 16px
                    top: 80%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy
                  prefix: 'the size of a '
                  attribute: fetus_size_manly
                  style:
                    font-size: 16px
                    top: 90%
                    left: 50%
            entities:
              - sensor.pregnancy
          - type: custom:card-templater
            card:
              type: picture-elements
              image_template: '{{ states.sensor.pregnancy.attributes.fetus_size_geeky_image }}'
              elements:
                - type: state-label
                  entity: sensor.pregnancy
                  style:
                    font-size: 20px
                    top: 10%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy
                  prefix: 'It''s Week '
                  attribute: weeks
                  suffix: '!'
                  style:
                    font-size: 40px
                    top: 30%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy_weeks
                  prefix: '(Day '
                  attribute: days_in_week
                  suffix: )
                  style:
                    font-size: 30px
                    top: 45%
                    left: 50%
                - type: custom:text-element
                  text: The fetus is about
                  style:
                    font-size: 16px
                    top: 80%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy
                  prefix: 'the size of a '
                  attribute: fetus_size_geeky
                  style:
                    font-size: 16px
                    top: 90%
                    left: 50%
            entities:
              - sensor.pregnancy
          - type: custom:card-templater
            card:
              type: picture-elements
              image_template: >-
                {{ states.sensor.pregnancy.attributes.fetus_size_cravings_image
                }}
              elements:
                - type: state-label
                  entity: sensor.pregnancy
                  style:
                    font-size: 20px
                    top: 10%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy
                  prefix: 'It''s Week '
                  attribute: weeks
                  suffix: '!'
                  style:
                    font-size: 40px
                    top: 30%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy_weeks
                  prefix: '(Day '
                  attribute: days_in_week
                  suffix: )
                  style:
                    font-size: 30px
                    top: 45%
                    left: 50%
                - type: custom:text-element
                  text: The fetus is about
                  style:
                    font-size: 16px
                    top: 80%
                    left: 50%
                - type: state-label
                  entity: sensor.pregnancy
                  prefix: 'the size of a '
                  attribute: fetus_size_cravings
                  style:
                    font-size: 16px
                    top: 90%
                    left: 50%
            entities:
              - sensor.pregnancy
1 Like

This is great @tango259, have nicked the dashboard/config for our dashboard (my partner is just shy of 29 weeks pregnant).

Wanted to share some additions I made to your codes

  1. Adding black outline to text

Added the text-shadow function to give the impression of a black outline, which can be helpful as the images make it somewhat hard to read sometimes. Vertical stack code below:

type: custom:card-templater
card:
  type: picture-elements
  image_template: '{{ states.sensor.pregnancy.attributes.fetus_size_manly_image }}'
  elements:
    - type: state-label
      entity: sensor.pregnancy
      style:
        text-shadow: '2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000'
        color: white
        font-size: 20px
        top: 10%
        left: 50%
    - type: state-label
      entity: sensor.pregnancy
      prefix: 'It''s Week '
      attribute: weeks
      suffix: '!'
      style:
        text-shadow: '2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000'
        color: white
        font-size: 40px
        top: 30%
        left: 50%
    - type: state-label
      entity: sensor.pregnancy_weeks
      prefix: '(Day '
      attribute: days_in_week
      suffix: )
      style:
        text-shadow: '2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000'
        color: white
        font-size: 30px
        top: 45%
        left: 50%
    - type: custom:text-element
      text: The fetus is about
      style:
        text-shadow: '2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000'
        color: white
        font-size: 16px
        top: 80%
        left: 50%
    - type: state-label
      entity: sensor.pregnancy
      prefix: 'the size of a '
      attribute: fetus_size_manly
      style:
        text-shadow: '2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000'
        color: white
        font-size: 16px
        top: 90%
        left: 50%
entities:
  - sensor.pregnancy
  1. Replaced the image with a custom gallery card

Custom card here, and allows you to keep a folder with images it will cycle through at a customized period:

Card code:

type: custom:gallery-card
entities:
  - sensor.baby
menu_alignment: Hidden
slideshow_timer: '5'
maximum_files_per_entity: false
show_reload: false

The sensor.baby is a folder sensor, make a folder under /www/baby/, and add the following to your configuration.yaml file:

sensor:
  - platform: folder
    folder: /config/www/baby
1 Like

I was too lazy to look into ways to make it more readable, but in reality it was actually relatively easy! :man_shrugging: Lol the black outline is a great idea and definitely helps. Alternatively, you can add a semi-transparent background to the strings using background-color: rgba(0,0,0,.7), where .7 is the transparency value. I think it’s moreso a matter of personal preference which way you decide to go, but both make the text more readable.

This is a super cool idea! Now I wish we could get an ultrasound more often. It’ll be great to add other pictures from things like baby showers and stuff too.

I did want to mention a couple things too.

  • There is an extra “a” in the lovelace cards that I went through and removed, but it’s not reflected in the code here. Currently it’ll show “the size of a a baseball cap.”, for example. All of the sizes are prefixed with the letter “a” in the template sensor code, so the letter isn’t needed in the card prefix.
  • Depending on when you added the code to your HA instance, you may have the legacy template setup. I edited the code yesterday to reflect the new, preferred template sensor setup.
  • I did make a GitHub repository for this as well, just to make updating code easier in the future.
  • And finally, I can’t take all the credit. @alexives is the original creator and @raphi did lot’s of work as well, among a few others. We’ve just built on to the original design. It’s an awesome project, and I refer to my dashboard exclusively now.

Figured I’d post this here as well, considering some of us may want it after the pregnancy is over.

The goal of this project was to create a pregnancy tracking dashboard that doesn’t track you and sell your data. Considering a majority of apps out there do this exact thing, here’s another add-on for HA that could be helpful once your newborn has arrived.

Right now you have to add it as an extension in HACS and host the database on something like Heroku. Eventually, it should be able to installed as an add-on in HA, once the ingress feature works again.

1 Like

Just buy one of those machines, duct tape it to her belly and add an ESP inside it and have it take an image every n seconds.
For bonus points you add a (few) servos to move the sensor around to get images from more angles and then combine them to a 3D image.

Come on! How hard can it be? :smiley:

4 Likes

Just noticed that during the day, the change in theme from dark to light changes text colour! I’ve just added “color: white” to the CSS styling (which I’ll amend in my original comment now).

There’s also an extra apostrophe in the middle card which I’ve amended and removed. :+1:

Hi @tango259

I am trying to setup your dashboard now, but get the below error

Unable to parse YAML: YAMLException: bad indentation of a mapping entry (2:10) 1 | - theme: Backend-selected 2 | title: Baby --------------^ 3 | path: baby 4 | icon: mdi:baby-carriage

Any ideas?

This is great by the way guys… Such a cool thing to do for the ladies :stuck_out_tongue: