As a computational biologist and professor in Philadelphia, I’ve always been fascinated by how technology can help us understand and combat public health crises. When the COVID-19 pandemic hit, I knew I wanted to leverage my expertise in statistics and Home Assistant (HA) to track the virus’s spread locally. Here’s how I did it, and how you can adapt this method to your area. ### The Goal: Estimate Local COVID-19 Cases and Risk Levels My primary objectives were twofold: 1. Estimate the true number of COVID-19 cases in my area based on the number of deaths. 2. Calculate the minimum number of people that could gather without anyone being infected, helping determine if it’s safe to venture out. ### The Methodology Drawing inspiration from a Medium article by Tomas Pueyo, I focused on key epidemiological metrics: - Deaths: A more reliable metric than cases due to inconsistent testing. - Time Lag: The average time between infection and death (17.3 days). - Doubling Time: How quickly cases are increasing. - Case Fatality Rate (CFR): The percentage of infections that result in death. Using HA’s templating engine, I created interactive sensors to model these metrics. Here’s a snippet of the Jinja template I used: jinja {% set deaths = 1 %} {% set lag = 17.3 %} {% set doubling_time = 6.18 %} {% set CFR = 0.04 %} {% set doubings_during_lag = lag/doubling_time %} {% set true_cases_lagged = deaths/CFR %} {{ doubling_time }} days ago there were ~{{true_cases_lagged | round}} true cases. {% set true_cases_now = true_cases_lagged*(2**doubings_during_lag) %} During that time there were {{doubings_during_lag | round(1) }} doublings. This means there are {{ true_cases_now | round }} cases now. ### Creating Actionable Insights Once I had the number of estimated cases, I calculated the risk of infection in different group sizes. This involved determining the likelihood that at least one person in a group was infected, using logarithms to find the maximum safe group size for a given risk threshold (I chose 1%). Here’s how I modeled it: jinja {% set current_cases = states.sensor.current_covid_cases.state | float %} {% set population = 5370926 | float %} {% set risk = 0.01 %} {% set current_healthy_rate = (1-(current_cases/population)) %} A crowd size of {{ current_max_size | round }} is the largest crowd where the risk of 1 or more infected people is below {{100*risk}}%. ### Putting It All Together I integrated these calculations into HA using template sensors and input numbers. This setup allowed me to experiment with different death counts and see how they affected estimated cases and safe group sizes. I even created an entities card to display all relevant information in one place. ### Why This Matters While there are existing COVID-19 integrations for HA, they often provide country-level data, which isn’t granular enough for local decision-making. By focusing on my specific area, I could tailor the model to Philadelphia’s unique circumstances. ### A Word of Caution While this model is a powerful tool for understanding the pandemic, it’s not a substitute for official guidelines. Always follow recommendations from your local health authorities. Social distancing and staying home are the most effective ways to curb the spread. ### Looking Ahead I plan to revisit this model weekly to track changes in death rates and adjust my parameters accordingly. By continuously refining the model, I hope to better understand how our community is faring and how we can collectively bend the curve. If you’re interested in replicating this approach, I’d be happy to collaborate or provide guidance. Let’s use our skills to make a difference in the fight against COVID-19. Stay safe, stay informed, and stay home when necessary! ![]()
![]()