[{"data":1,"prerenderedAt":4597},["ShallowReactive",2],{"articles-tag-home-assistant":3},[4,1047],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"date":11,"updated":11,"tags":12,"readingTime":18,"cover":8,"body":19,"_type":1041,"_id":1042,"_source":1043,"_file":1044,"_stem":1045,"_extension":1046},"/blog/home-assistant-mqtt-and-the-timezone-confusion-i-made-myself","blog",false,"","Home Assistant, MQTT That Clicked, and Two Timezone Bugs","Returning to Home Assistant after nearly a decade away, getting solar monitoring back online with MQTT, and debugging two timezone issues I introduced.","2026-03-09",[13,14,15,16,17],"home-assistant","mqtt","homelab","solar-tracker","timescaledb","7 min read",{"type":20,"children":21,"toc":1032},"root",[22,30,35,42,56,77,83,88,93,99,104,119,124,144,149,377,382,395,401,406,411,416,422,427,432,437,450,531,536,542,547,573,578,627,662,794,845,871,891,943,948,992,1005,1011,1016,1021,1026],{"type":23,"tag":24,"props":25,"children":26},"element","p",{},[27],{"type":28,"value":29},"text","About eight or nine years ago, I tried to set up Home Assistant as a Z-Wave hub. I don't remember the details of what went wrong, only that it went wrong, and I walked away frustrated and stuck with a Vera hub I've been using ever since. The UI on the Vera is bad. It has always been bad. I kept it because I didn't want to go through the setup process again.",{"type":23,"tag":24,"props":31,"children":32},{},[33],{"type":28,"value":34},"That changed this past weekend.",{"type":23,"tag":36,"props":37,"children":39},"h2",{"id":38},"why-i-came-back",[40],{"type":28,"value":41},"Why I Came Back",{"type":23,"tag":24,"props":43,"children":44},{},[45,47,54],{"type":28,"value":46},"The short version is solar monitoring. My Raspberry Pi running Solar Assistant died a while back, and then, as I covered ",{"type":23,"tag":48,"props":49,"children":51},"a",{"href":50},"/blog/well-i-embarrassed-myself-even-sooner-than-expected-a-modular-psu-cables-tale",[52],{"type":28,"value":53},"in my last post",{"type":28,"value":55},", I made the situation worse by frying an SSD with the wrong PSU cables. Rather than rebuild the old setup from scratch, a friend pushed me toward Home Assistant. I had been putting it off for obvious reasons.",{"type":23,"tag":24,"props":57,"children":58},{},[59,61,67,69,75],{"type":28,"value":60},"The longer version is in ",{"type":23,"tag":48,"props":62,"children":64},{"href":63},"/blog/solar-monitoring-part-1-the-python-build",[65],{"type":28,"value":66},"part one",{"type":28,"value":68}," and ",{"type":23,"tag":48,"props":70,"children":72},{"href":71},"/blog/solar-monitoring-part-2-the-typescript-rebuild",[73],{"type":28,"value":74},"part two",{"type":28,"value":76}," of the solar monitoring series, where I go into the full stack rebuild. For this post I want to focus on the Home Assistant experience itself, specifically two parts of it: MQTT, and the timezone confusion that made my dashboards look completely wrong for the better part of a day.",{"type":23,"tag":36,"props":78,"children":80},{"id":79},"the-setup-wasnt-what-i-expected",[81],{"type":28,"value":82},"The Setup Wasn't What I Expected",{"type":23,"tag":24,"props":84,"children":85},{},[86],{"type":28,"value":87},"I set Home Assistant up on an existing machine over the weekend. Within a day I had it running, my solar poller reconnected, and data flowing through an MQTT broker into Home Assistant sensors. A day. The last time I attempted this it took longer than that to decide I was done.",{"type":23,"tag":24,"props":89,"children":90},{},[91],{"type":28,"value":92},"Home Assistant has changed a lot in the years I wasn't paying attention. The onboarding is clean. The integrations catalog is massive. The built-in Energy Dashboard has features I would have spent weeks building by hand previously. I'm still figuring out some of it, but the barrier to getting something useful running is genuinely low now.",{"type":23,"tag":36,"props":94,"children":96},{"id":95},"mqtt-finally-made-sense",[97],{"type":28,"value":98},"MQTT Finally Made Sense",{"type":23,"tag":24,"props":100,"children":101},{},[102],{"type":28,"value":103},"MQTT is a protocol I had seen the name of for years without ever finding the time to actually look into. Publish-subscribe message bus, sensors push values, consumers listen to topics. That was roughly where my knowledge stopped.",{"type":23,"tag":24,"props":105,"children":106},{},[107,109,117],{"type":28,"value":108},"Home Assistant changes that dynamic. When you install the Mosquitto broker add-on and connect the MQTT integration, the ",{"type":23,"tag":48,"props":110,"children":114},{"href":111,"rel":112},"https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery",[113],"nofollow",[115],{"type":28,"value":116},"MQTT auto-discovery",{"type":28,"value":118}," mechanism does most of the work. Any device or service that publishes a configuration payload to the right topic becomes a Home Assistant entity automatically. No YAML. No manual entity setup. The device announces itself, Home Assistant listens, the sensor appears.",{"type":23,"tag":24,"props":120,"children":121},{},[122],{"type":28,"value":123},"The discovery topic pattern looks like this:",{"type":23,"tag":125,"props":126,"children":129},"pre",{"className":127,"code":128,"language":28,"meta":8,"style":8},"language-text shiki shiki-themes github-dark","homeassistant/sensor/\u003Cdevice-id>/\u003Cmetric>/config\n",[130],{"type":23,"tag":131,"props":132,"children":133},"code",{"__ignoreMap":8},[134],{"type":23,"tag":135,"props":136,"children":139},"span",{"class":137,"line":138},"line",1,[140],{"type":23,"tag":135,"props":141,"children":142},{},[143],{"type":28,"value":128},{"type":23,"tag":24,"props":145,"children":146},{},[147],{"type":28,"value":148},"The payload is a JSON object describing the sensor, including its name, state topic, unit of measurement, and device class. Once that message is retained on the broker, the entity exists in Home Assistant and updates any time a new value is published to the state topic.",{"type":23,"tag":125,"props":150,"children":154},{"className":151,"code":152,"language":153,"meta":8,"style":8},"language-json shiki shiki-themes github-dark","{\n  \"name\": \"battery_soc\",\n  \"state_topic\": \"solar/battery_soc\",\n  \"unit_of_measurement\": \"%\",\n  \"device_class\": \"battery\",\n  \"state_class\": \"measurement\",\n  \"unique_id\": \"sph5048_battery_soc\",\n  \"device\": {\n    \"identifiers\": [\"sph5048\"],\n    \"name\": \"Solar Inverter\"\n  }\n}\n","json",[155],{"type":23,"tag":131,"props":156,"children":157},{"__ignoreMap":8},[158,167,193,215,237,259,281,303,317,341,359,368],{"type":23,"tag":135,"props":159,"children":160},{"class":137,"line":138},[161],{"type":23,"tag":135,"props":162,"children":164},{"style":163},"--shiki-default:#E1E4E8",[165],{"type":28,"value":166},"{\n",{"type":23,"tag":135,"props":168,"children":170},{"class":137,"line":169},2,[171,177,182,188],{"type":23,"tag":135,"props":172,"children":174},{"style":173},"--shiki-default:#79B8FF",[175],{"type":28,"value":176},"  \"name\"",{"type":23,"tag":135,"props":178,"children":179},{"style":163},[180],{"type":28,"value":181},": ",{"type":23,"tag":135,"props":183,"children":185},{"style":184},"--shiki-default:#9ECBFF",[186],{"type":28,"value":187},"\"battery_soc\"",{"type":23,"tag":135,"props":189,"children":190},{"style":163},[191],{"type":28,"value":192},",\n",{"type":23,"tag":135,"props":194,"children":196},{"class":137,"line":195},3,[197,202,206,211],{"type":23,"tag":135,"props":198,"children":199},{"style":173},[200],{"type":28,"value":201},"  \"state_topic\"",{"type":23,"tag":135,"props":203,"children":204},{"style":163},[205],{"type":28,"value":181},{"type":23,"tag":135,"props":207,"children":208},{"style":184},[209],{"type":28,"value":210},"\"solar/battery_soc\"",{"type":23,"tag":135,"props":212,"children":213},{"style":163},[214],{"type":28,"value":192},{"type":23,"tag":135,"props":216,"children":218},{"class":137,"line":217},4,[219,224,228,233],{"type":23,"tag":135,"props":220,"children":221},{"style":173},[222],{"type":28,"value":223},"  \"unit_of_measurement\"",{"type":23,"tag":135,"props":225,"children":226},{"style":163},[227],{"type":28,"value":181},{"type":23,"tag":135,"props":229,"children":230},{"style":184},[231],{"type":28,"value":232},"\"%\"",{"type":23,"tag":135,"props":234,"children":235},{"style":163},[236],{"type":28,"value":192},{"type":23,"tag":135,"props":238,"children":240},{"class":137,"line":239},5,[241,246,250,255],{"type":23,"tag":135,"props":242,"children":243},{"style":173},[244],{"type":28,"value":245},"  \"device_class\"",{"type":23,"tag":135,"props":247,"children":248},{"style":163},[249],{"type":28,"value":181},{"type":23,"tag":135,"props":251,"children":252},{"style":184},[253],{"type":28,"value":254},"\"battery\"",{"type":23,"tag":135,"props":256,"children":257},{"style":163},[258],{"type":28,"value":192},{"type":23,"tag":135,"props":260,"children":262},{"class":137,"line":261},6,[263,268,272,277],{"type":23,"tag":135,"props":264,"children":265},{"style":173},[266],{"type":28,"value":267},"  \"state_class\"",{"type":23,"tag":135,"props":269,"children":270},{"style":163},[271],{"type":28,"value":181},{"type":23,"tag":135,"props":273,"children":274},{"style":184},[275],{"type":28,"value":276},"\"measurement\"",{"type":23,"tag":135,"props":278,"children":279},{"style":163},[280],{"type":28,"value":192},{"type":23,"tag":135,"props":282,"children":284},{"class":137,"line":283},7,[285,290,294,299],{"type":23,"tag":135,"props":286,"children":287},{"style":173},[288],{"type":28,"value":289},"  \"unique_id\"",{"type":23,"tag":135,"props":291,"children":292},{"style":163},[293],{"type":28,"value":181},{"type":23,"tag":135,"props":295,"children":296},{"style":184},[297],{"type":28,"value":298},"\"sph5048_battery_soc\"",{"type":23,"tag":135,"props":300,"children":301},{"style":163},[302],{"type":28,"value":192},{"type":23,"tag":135,"props":304,"children":306},{"class":137,"line":305},8,[307,312],{"type":23,"tag":135,"props":308,"children":309},{"style":173},[310],{"type":28,"value":311},"  \"device\"",{"type":23,"tag":135,"props":313,"children":314},{"style":163},[315],{"type":28,"value":316},": {\n",{"type":23,"tag":135,"props":318,"children":320},{"class":137,"line":319},9,[321,326,331,336],{"type":23,"tag":135,"props":322,"children":323},{"style":173},[324],{"type":28,"value":325},"    \"identifiers\"",{"type":23,"tag":135,"props":327,"children":328},{"style":163},[329],{"type":28,"value":330},": [",{"type":23,"tag":135,"props":332,"children":333},{"style":184},[334],{"type":28,"value":335},"\"sph5048\"",{"type":23,"tag":135,"props":337,"children":338},{"style":163},[339],{"type":28,"value":340},"],\n",{"type":23,"tag":135,"props":342,"children":344},{"class":137,"line":343},10,[345,350,354],{"type":23,"tag":135,"props":346,"children":347},{"style":173},[348],{"type":28,"value":349},"    \"name\"",{"type":23,"tag":135,"props":351,"children":352},{"style":163},[353],{"type":28,"value":181},{"type":23,"tag":135,"props":355,"children":356},{"style":184},[357],{"type":28,"value":358},"\"Solar Inverter\"\n",{"type":23,"tag":135,"props":360,"children":362},{"class":137,"line":361},11,[363],{"type":23,"tag":135,"props":364,"children":365},{"style":163},[366],{"type":28,"value":367},"  }\n",{"type":23,"tag":135,"props":369,"children":371},{"class":137,"line":370},12,[372],{"type":23,"tag":135,"props":373,"children":374},{"style":163},[375],{"type":28,"value":376},"}\n",{"type":23,"tag":24,"props":378,"children":379},{},[380],{"type":28,"value":381},"My solar poller publishes about 30 of these at startup. Thirty sensors just appear, grouped under a \"Solar Inverter\" device, without me touching a single config file. That's the part that clicked for me. The overhead I'd always imagined wasn't there.",{"type":23,"tag":24,"props":383,"children":384},{},[385,387,393],{"type":28,"value":386},"MQTT as an integration layer also removes a problem I had with the old stack: everything had to speak HTTP and know about my custom API. Now anything that wants solar data subscribes to ",{"type":23,"tag":131,"props":388,"children":390},{"className":389},[],[391],{"type":28,"value":392},"solar/#",{"type":28,"value":394}," on the broker. Multiple consumers, one publisher, no coupling between them.",{"type":23,"tag":36,"props":396,"children":398},{"id":397},"the-data-looked-wrong",[399],{"type":28,"value":400},"The Data Looked Wrong",{"type":23,"tag":24,"props":402,"children":403},{},[404],{"type":28,"value":405},"A day or two after getting things running, I had some time to actually build out a solar dashboard. I wanted a view with daily production totals, some trend charts, and a quick read on current battery state. I pulled the data into Lovelace cards and the numbers immediately looked off.",{"type":23,"tag":24,"props":407,"children":408},{},[409],{"type":28,"value":410},"Some sensors were showing values that didn't match what I knew the inverter had been doing. Aggregates were misaligned. Daily totals weren't adding up in ways that made sense. The raw sensor readings were fine, it was the grouped and summarized data that was confusing.",{"type":23,"tag":24,"props":412,"children":413},{},[414],{"type":28,"value":415},"Two separate issues turned out to be responsible, both timezone-related, and both entirely my fault.",{"type":23,"tag":36,"props":417,"children":419},{"id":418},"timezone-issue-one-home-assistant",[420],{"type":28,"value":421},"Timezone Issue One: Home Assistant",{"type":23,"tag":24,"props":423,"children":424},{},[425],{"type":28,"value":426},"Home Assistant stores timestamps internally. If the timezone setting in Home Assistant doesn't match your actual timezone, those timestamps are wrong relative to your local time, and anything that depends on them, including Energy Dashboard bucketing and history graphs, shifts accordingly.",{"type":23,"tag":24,"props":428,"children":429},{},[430],{"type":28,"value":431},"The fix is in Settings > System > General. There's a timezone field. Mine wasn't set correctly. I updated it to the right timezone, restarted, and the history graphs snapped into alignment.",{"type":23,"tag":24,"props":433,"children":434},{},[435],{"type":28,"value":436},"This one is easy to overlook because the live sensor values look fine. The inverter is pushing a number, Home Assistant is displaying it, all is well. The timezone setting only reveals itself when you start asking \"what happened at 2pm yesterday\" and Home Assistant is working from a different definition of 2pm than you are.",{"type":23,"tag":24,"props":438,"children":439},{},[440,442,448],{"type":28,"value":441},"If you run Home Assistant in Docker, the container also needs the right timezone set. Passing ",{"type":23,"tag":131,"props":443,"children":445},{"className":444},[],[446],{"type":28,"value":447},"TZ",{"type":28,"value":449}," as an environment variable in your Compose file handles it:",{"type":23,"tag":125,"props":451,"children":455},{"className":452,"code":453,"language":454,"meta":8,"style":8},"language-yaml shiki shiki-themes github-dark","services:\n  homeassistant:\n    image: ghcr.io/home-assistant/home-assistant:stable\n    environment:\n      TZ: America/New_York\n","yaml",[456],{"type":23,"tag":131,"props":457,"children":458},{"__ignoreMap":8},[459,473,485,502,514],{"type":23,"tag":135,"props":460,"children":461},{"class":137,"line":138},[462,468],{"type":23,"tag":135,"props":463,"children":465},{"style":464},"--shiki-default:#85E89D",[466],{"type":28,"value":467},"services",{"type":23,"tag":135,"props":469,"children":470},{"style":163},[471],{"type":28,"value":472},":\n",{"type":23,"tag":135,"props":474,"children":475},{"class":137,"line":169},[476,481],{"type":23,"tag":135,"props":477,"children":478},{"style":464},[479],{"type":28,"value":480},"  homeassistant",{"type":23,"tag":135,"props":482,"children":483},{"style":163},[484],{"type":28,"value":472},{"type":23,"tag":135,"props":486,"children":487},{"class":137,"line":195},[488,493,497],{"type":23,"tag":135,"props":489,"children":490},{"style":464},[491],{"type":28,"value":492},"    image",{"type":23,"tag":135,"props":494,"children":495},{"style":163},[496],{"type":28,"value":181},{"type":23,"tag":135,"props":498,"children":499},{"style":184},[500],{"type":28,"value":501},"ghcr.io/home-assistant/home-assistant:stable\n",{"type":23,"tag":135,"props":503,"children":504},{"class":137,"line":217},[505,510],{"type":23,"tag":135,"props":506,"children":507},{"style":464},[508],{"type":28,"value":509},"    environment",{"type":23,"tag":135,"props":511,"children":512},{"style":163},[513],{"type":28,"value":472},{"type":23,"tag":135,"props":515,"children":516},{"class":137,"line":239},[517,522,526],{"type":23,"tag":135,"props":518,"children":519},{"style":464},[520],{"type":28,"value":521},"      TZ",{"type":23,"tag":135,"props":523,"children":524},{"style":163},[525],{"type":28,"value":181},{"type":23,"tag":135,"props":527,"children":528},{"style":184},[529],{"type":28,"value":530},"America/New_York\n",{"type":23,"tag":24,"props":532,"children":533},{},[534],{"type":28,"value":535},"The UI setting and the container environment variable are separate things. Both need to be correct.",{"type":23,"tag":36,"props":537,"children":539},{"id":538},"timezone-issue-two-timescaledb",[540],{"type":28,"value":541},"Timezone Issue Two: TimescaleDB",{"type":23,"tag":24,"props":543,"children":544},{},[545],{"type":28,"value":546},"The second issue was in my TimescaleDB setup. I use TimescaleDB for long-term storage of solar metrics, which I may write a full post on at some point because it's been a genuinely good tool for this use case. The short version is that it's PostgreSQL with a time-series extension that adds automatic data partitioning, compression, and continuous aggregates.",{"type":23,"tag":24,"props":548,"children":549},{},[550,552,563,565,571],{"type":28,"value":551},"The problem: TimescaleDB's ",{"type":23,"tag":48,"props":553,"children":556},{"href":554,"rel":555},"https://docs.timescale.com/api/latest/hyperfunctions/time_bucket/",[113],[557],{"type":23,"tag":131,"props":558,"children":560},{"className":559},[],[561],{"type":28,"value":562},"time_bucket",{"type":28,"value":564}," function, when used on ",{"type":23,"tag":131,"props":566,"children":568},{"className":567},[],[569],{"type":28,"value":570},"TIMESTAMPTZ",{"type":28,"value":572}," columns, buckets by UTC midnight by default. If you're in a timezone that's offset from UTC, your \"daily\" aggregates don't align to your actual days. A bucket labeled \"March 8\" might contain data from 7pm local time on March 7 through 6:59pm local time on March 8, depending on your offset.",{"type":23,"tag":24,"props":574,"children":575},{},[576],{"type":28,"value":577},"For a solar system, this matters a lot. Daily production totals are one of the most useful metrics, and if the day boundaries are shifted by several hours, the numbers look wrong and, more importantly, they are wrong.",{"type":23,"tag":125,"props":579,"children":583},{"className":580,"code":581,"language":582,"meta":8,"style":8},"language-sql shiki shiki-themes github-dark","-- This buckets by UTC midnight, which may not be what you want\nSELECT time_bucket('1 day', ts) AS bucket, sum(value)\nFROM inverter_metrics\nWHERE key = 'pv1_energy_kwh'\nGROUP BY bucket;\n","sql",[584],{"type":23,"tag":131,"props":585,"children":586},{"__ignoreMap":8},[587,595,603,611,619],{"type":23,"tag":135,"props":588,"children":589},{"class":137,"line":138},[590],{"type":23,"tag":135,"props":591,"children":592},{},[593],{"type":28,"value":594},"-- This buckets by UTC midnight, which may not be what you want\n",{"type":23,"tag":135,"props":596,"children":597},{"class":137,"line":169},[598],{"type":23,"tag":135,"props":599,"children":600},{},[601],{"type":28,"value":602},"SELECT time_bucket('1 day', ts) AS bucket, sum(value)\n",{"type":23,"tag":135,"props":604,"children":605},{"class":137,"line":195},[606],{"type":23,"tag":135,"props":607,"children":608},{},[609],{"type":28,"value":610},"FROM inverter_metrics\n",{"type":23,"tag":135,"props":612,"children":613},{"class":137,"line":217},[614],{"type":23,"tag":135,"props":615,"children":616},{},[617],{"type":28,"value":618},"WHERE key = 'pv1_energy_kwh'\n",{"type":23,"tag":135,"props":620,"children":621},{"class":137,"line":239},[622],{"type":23,"tag":135,"props":623,"children":624},{},[625],{"type":28,"value":626},"GROUP BY bucket;\n",{"type":23,"tag":24,"props":628,"children":629},{},[630,632,637,639,645,647,653,655,660],{"type":28,"value":631},"The fix has two parts. First, I set the ",{"type":23,"tag":131,"props":633,"children":635},{"className":634},[],[636],{"type":28,"value":447},{"type":28,"value":638}," environment variable in my Docker Compose ",{"type":23,"tag":131,"props":640,"children":642},{"className":641},[],[643],{"type":28,"value":644},".env",{"type":28,"value":646}," file and passed it through to the TimescaleDB container. PostgreSQL uses this for ",{"type":23,"tag":131,"props":648,"children":650},{"className":649},[],[651],{"type":28,"value":652},"CURRENT_TIMESTAMP",{"type":28,"value":654},", display formatting, and any operations that reference the session timezone — good baseline hygiene, but it doesn't actually move where ",{"type":23,"tag":131,"props":656,"children":658},{"className":657},[],[659],{"type":28,"value":562},{"type":28,"value":661}," draws its day boundaries.",{"type":23,"tag":125,"props":663,"children":665},{"className":452,"code":664,"language":454,"meta":8,"style":8},"# docker-compose.yml\nservices:\n  timescaledb:\n    image: timescale/timescaledb:latest-pg16\n    environment:\n      TZ: ${TZ}\n      POSTGRES_DB: solar\n      POSTGRES_USER: solar\n      POSTGRES_PASSWORD: ${DB_PASSWORD}\n",[666],{"type":23,"tag":131,"props":667,"children":668},{"__ignoreMap":8},[669,678,689,701,717,728,744,761,777],{"type":23,"tag":135,"props":670,"children":671},{"class":137,"line":138},[672],{"type":23,"tag":135,"props":673,"children":675},{"style":674},"--shiki-default:#6A737D",[676],{"type":28,"value":677},"# docker-compose.yml\n",{"type":23,"tag":135,"props":679,"children":680},{"class":137,"line":169},[681,685],{"type":23,"tag":135,"props":682,"children":683},{"style":464},[684],{"type":28,"value":467},{"type":23,"tag":135,"props":686,"children":687},{"style":163},[688],{"type":28,"value":472},{"type":23,"tag":135,"props":690,"children":691},{"class":137,"line":195},[692,697],{"type":23,"tag":135,"props":693,"children":694},{"style":464},[695],{"type":28,"value":696},"  timescaledb",{"type":23,"tag":135,"props":698,"children":699},{"style":163},[700],{"type":28,"value":472},{"type":23,"tag":135,"props":702,"children":703},{"class":137,"line":217},[704,708,712],{"type":23,"tag":135,"props":705,"children":706},{"style":464},[707],{"type":28,"value":492},{"type":23,"tag":135,"props":709,"children":710},{"style":163},[711],{"type":28,"value":181},{"type":23,"tag":135,"props":713,"children":714},{"style":184},[715],{"type":28,"value":716},"timescale/timescaledb:latest-pg16\n",{"type":23,"tag":135,"props":718,"children":719},{"class":137,"line":239},[720,724],{"type":23,"tag":135,"props":721,"children":722},{"style":464},[723],{"type":28,"value":509},{"type":23,"tag":135,"props":725,"children":726},{"style":163},[727],{"type":28,"value":472},{"type":23,"tag":135,"props":729,"children":730},{"class":137,"line":261},[731,735,739],{"type":23,"tag":135,"props":732,"children":733},{"style":464},[734],{"type":28,"value":521},{"type":23,"tag":135,"props":736,"children":737},{"style":163},[738],{"type":28,"value":181},{"type":23,"tag":135,"props":740,"children":741},{"style":184},[742],{"type":28,"value":743},"${TZ}\n",{"type":23,"tag":135,"props":745,"children":746},{"class":137,"line":283},[747,752,756],{"type":23,"tag":135,"props":748,"children":749},{"style":464},[750],{"type":28,"value":751},"      POSTGRES_DB",{"type":23,"tag":135,"props":753,"children":754},{"style":163},[755],{"type":28,"value":181},{"type":23,"tag":135,"props":757,"children":758},{"style":184},[759],{"type":28,"value":760},"solar\n",{"type":23,"tag":135,"props":762,"children":763},{"class":137,"line":305},[764,769,773],{"type":23,"tag":135,"props":765,"children":766},{"style":464},[767],{"type":28,"value":768},"      POSTGRES_USER",{"type":23,"tag":135,"props":770,"children":771},{"style":163},[772],{"type":28,"value":181},{"type":23,"tag":135,"props":774,"children":775},{"style":184},[776],{"type":28,"value":760},{"type":23,"tag":135,"props":778,"children":779},{"class":137,"line":319},[780,785,789],{"type":23,"tag":135,"props":781,"children":782},{"style":464},[783],{"type":28,"value":784},"      POSTGRES_PASSWORD",{"type":23,"tag":135,"props":786,"children":787},{"style":163},[788],{"type":28,"value":181},{"type":23,"tag":135,"props":790,"children":791},{"style":184},[792],{"type":28,"value":793},"${DB_PASSWORD}\n",{"type":23,"tag":125,"props":795,"children":799},{"className":796,"code":797,"language":798,"meta":8,"style":8},"language-bash shiki shiki-themes github-dark","# .env\nTZ=America/New_York\nDB_PASSWORD=...\n","bash",[800],{"type":23,"tag":131,"props":801,"children":802},{"__ignoreMap":8},[803,811,828],{"type":23,"tag":135,"props":804,"children":805},{"class":137,"line":138},[806],{"type":23,"tag":135,"props":807,"children":808},{"style":674},[809],{"type":28,"value":810},"# .env\n",{"type":23,"tag":135,"props":812,"children":813},{"class":137,"line":169},[814,818,824],{"type":23,"tag":135,"props":815,"children":816},{"style":163},[817],{"type":28,"value":447},{"type":23,"tag":135,"props":819,"children":821},{"style":820},"--shiki-default:#F97583",[822],{"type":28,"value":823},"=",{"type":23,"tag":135,"props":825,"children":826},{"style":184},[827],{"type":28,"value":530},{"type":23,"tag":135,"props":829,"children":830},{"class":137,"line":195},[831,836,840],{"type":23,"tag":135,"props":832,"children":833},{"style":163},[834],{"type":28,"value":835},"DB_PASSWORD",{"type":23,"tag":135,"props":837,"children":838},{"style":820},[839],{"type":28,"value":823},{"type":23,"tag":135,"props":841,"children":842},{"style":184},[843],{"type":28,"value":844},"...\n",{"type":23,"tag":24,"props":846,"children":847},{},[848,850,855,857,862,864,869],{"type":28,"value":849},"On ",{"type":23,"tag":131,"props":851,"children":853},{"className":852},[],[854],{"type":28,"value":570},{"type":28,"value":856}," columns, ",{"type":23,"tag":131,"props":858,"children":860},{"className":859},[],[861],{"type":28,"value":562},{"type":28,"value":863}," always buckets by UTC midnight regardless of the container's ",{"type":23,"tag":131,"props":865,"children":867},{"className":866},[],[868],{"type":28,"value":447},{"type":28,"value":870}," setting. The env var helps with display; the query itself needs fixing.",{"type":23,"tag":24,"props":872,"children":873},{},[874,876,881,883,889],{"type":28,"value":875},"For local-midnight bucketing, the ",{"type":23,"tag":131,"props":877,"children":879},{"className":878},[],[880],{"type":28,"value":562},{"type":28,"value":882}," function has an ",{"type":23,"tag":131,"props":884,"children":886},{"className":885},[],[887],{"type":28,"value":888},"origin",{"type":28,"value":890}," parameter that shifts the bucket start point:",{"type":23,"tag":125,"props":892,"children":894},{"className":580,"code":893,"language":582,"meta":8,"style":8},"-- Shift buckets to align with local midnight (UTC-5 example)\nSELECT time_bucket('1 day', ts, '2026-01-01 00:00:00-05'::timestamptz) AS bucket,\n       sum(value)\nFROM inverter_metrics\nWHERE key = 'pv1_energy_kwh'\nGROUP BY bucket;\n",[895],{"type":23,"tag":131,"props":896,"children":897},{"__ignoreMap":8},[898,906,914,922,929,936],{"type":23,"tag":135,"props":899,"children":900},{"class":137,"line":138},[901],{"type":23,"tag":135,"props":902,"children":903},{},[904],{"type":28,"value":905},"-- Shift buckets to align with local midnight (UTC-5 example)\n",{"type":23,"tag":135,"props":907,"children":908},{"class":137,"line":169},[909],{"type":23,"tag":135,"props":910,"children":911},{},[912],{"type":28,"value":913},"SELECT time_bucket('1 day', ts, '2026-01-01 00:00:00-05'::timestamptz) AS bucket,\n",{"type":23,"tag":135,"props":915,"children":916},{"class":137,"line":195},[917],{"type":23,"tag":135,"props":918,"children":919},{},[920],{"type":28,"value":921},"       sum(value)\n",{"type":23,"tag":135,"props":923,"children":924},{"class":137,"line":217},[925],{"type":23,"tag":135,"props":926,"children":927},{},[928],{"type":28,"value":610},{"type":23,"tag":135,"props":930,"children":931},{"class":137,"line":239},[932],{"type":23,"tag":135,"props":933,"children":934},{},[935],{"type":28,"value":618},{"type":23,"tag":135,"props":937,"children":938},{"class":137,"line":261},[939],{"type":23,"tag":135,"props":940,"children":941},{},[942],{"type":28,"value":626},{"type":23,"tag":24,"props":944,"children":945},{},[946],{"type":28,"value":947},"Or you can cast the timestamp to a specific timezone before bucketing:",{"type":23,"tag":125,"props":949,"children":951},{"className":580,"code":950,"language":582,"meta":8,"style":8},"SELECT time_bucket('1 day', ts AT TIME ZONE 'America/New_York') AS local_bucket,\n       sum(value)\nFROM inverter_metrics\nWHERE key = 'pv1_energy_kwh'\nGROUP BY local_bucket;\n",[952],{"type":23,"tag":131,"props":953,"children":954},{"__ignoreMap":8},[955,963,970,977,984],{"type":23,"tag":135,"props":956,"children":957},{"class":137,"line":138},[958],{"type":23,"tag":135,"props":959,"children":960},{},[961],{"type":28,"value":962},"SELECT time_bucket('1 day', ts AT TIME ZONE 'America/New_York') AS local_bucket,\n",{"type":23,"tag":135,"props":964,"children":965},{"class":137,"line":169},[966],{"type":23,"tag":135,"props":967,"children":968},{},[969],{"type":28,"value":921},{"type":23,"tag":135,"props":971,"children":972},{"class":137,"line":195},[973],{"type":23,"tag":135,"props":974,"children":975},{},[976],{"type":28,"value":610},{"type":23,"tag":135,"props":978,"children":979},{"class":137,"line":217},[980],{"type":23,"tag":135,"props":981,"children":982},{},[983],{"type":28,"value":618},{"type":23,"tag":135,"props":985,"children":986},{"class":137,"line":239},[987],{"type":23,"tag":135,"props":988,"children":989},{},[990],{"type":28,"value":991},"GROUP BY local_bucket;\n",{"type":23,"tag":24,"props":993,"children":994},{},[995,997,1003],{"type":28,"value":996},"The ",{"type":23,"tag":131,"props":998,"children":1000},{"className":999},[],[1001],{"type":28,"value":1002},"AT TIME ZONE",{"type":28,"value":1004}," approach handles daylight saving automatically and is easier to read. The data already stored with UTC-offset timestamps won't retroactively fix itself, so the aggregates for the previous few days will still look a bit off. The new data should start bucketing correctly right away.",{"type":23,"tag":36,"props":1006,"children":1008},{"id":1007},"what-this-weekend-produced",[1009],{"type":28,"value":1010},"What This Weekend Produced",{"type":23,"tag":24,"props":1012,"children":1013},{},[1014],{"type":28,"value":1015},"A day to get Home Assistant running and data flowing. Another day to sort out the dashboards and fix both timezone issues. Net result: a solar monitoring setup that's actually better than what I had before, maintained largely by tools I didn't write, and running reliably since I got it working.",{"type":23,"tag":24,"props":1017,"children":1018},{},[1019],{"type":28,"value":1020},"MQTT clicked faster than expected, and the timezone issues were the kind of setup learning curve you only run into once. Both came down to setting an environment variable in the right place. Neither required code changes or schema migrations.",{"type":23,"tag":24,"props":1022,"children":1023},{},[1024],{"type":28,"value":1025},"TimescaleDB is still earning its spot in the stack. I'll probably write more about it separately, the continuous aggregates feature alone warrants its own writeup.",{"type":23,"tag":1027,"props":1028,"children":1029},"style",{},[1030],{"type":28,"value":1031},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":8,"searchDepth":169,"depth":169,"links":1033},[1034,1035,1036,1037,1038,1039,1040],{"id":38,"depth":169,"text":41},{"id":79,"depth":169,"text":82},{"id":95,"depth":169,"text":98},{"id":397,"depth":169,"text":400},{"id":418,"depth":169,"text":421},{"id":538,"depth":169,"text":541},{"id":1007,"depth":169,"text":1010},"markdown","content:blog:home-assistant-mqtt-and-the-timezone-confusion-i-made-myself.md","content","blog/home-assistant-mqtt-and-the-timezone-confusion-i-made-myself.md","blog/home-assistant-mqtt-and-the-timezone-confusion-i-made-myself","md",{"_path":71,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1048,"description":1049,"date":11,"updated":11,"tags":1050,"series":1052,"seriesPart":169,"readingTime":1053,"cover":8,"body":1054,"_type":1041,"_id":4594,"_source":1043,"_file":4595,"_stem":4596,"_extension":1046},"DIY Solar Monitoring Rebuilt: TypeScript, MQTT, and Home Assistant","After a PSU cable mistake took out my solar monitoring stack, I rebuilt it with TypeScript, MQTT, and Home Assistant — and it's better than the original.",[16,15,1051,14,13,17],"typescript","Solar Monitoring Stack","9 min read",{"type":20,"children":1055,"toc":4581},[1056,1068,1072,1077,1089,1102,1108,1113,1118,1124,1144,1408,1413,1998,2003,2010,2015,2608,2613,2619,2624,2629,2637,2642,2648,2653,2658,3107,3112,3125,3131,3144,3149,3779,3784,3796,3802,3815,3820,3952,3965,3970,3976,3981,4452,4464,4476,4482,4493,4510,4528,4538,4544,4549,4554,4559,4564,4567,4572,4577],{"type":23,"tag":24,"props":1057,"children":1058},{},[1059,1061,1066],{"type":28,"value":1060},"This is part two of a two-part series. ",{"type":23,"tag":48,"props":1062,"children":1063},{"href":63},[1064],{"type":28,"value":1065},"Part one covers the original build",{"type":28,"value":1067}," and how it ended. This is the story of what came next.",{"type":23,"tag":1069,"props":1070,"children":1071},"hr",{},[],{"type":23,"tag":24,"props":1073,"children":1074},{},[1075],{"type":28,"value":1076},"Losing your own work stings. But there's a particular flavor of losing work that only hits when you realize the thing you rebuilt is actually better than the thing you lost.",{"type":23,"tag":24,"props":1078,"children":1079},{},[1080,1082,1087],{"type":28,"value":1081},"After a ",{"type":23,"tag":48,"props":1083,"children":1084},{"href":50},[1085],{"type":28,"value":1086},"PSU cable mix-up",{"type":28,"value":1088}," took out the drives in my server, I lost all the custom code for my solar monitoring stack. The Python poller, the TypeScript API, the hand-built dashboard — gone. I had two choices: rebuild the same stack, or rethink it.",{"type":23,"tag":24,"props":1090,"children":1091},{},[1092,1094,1100],{"type":28,"value":1093},"The new stack is TypeScript, Node.js, MQTT, TimescaleDB, and Home Assistant. It runs in Docker Compose, every piece of it fits in a ",{"type":23,"tag":131,"props":1095,"children":1097},{"className":1096},[],[1098],{"type":28,"value":1099},"git push",{"type":28,"value":1101},", and adding a new sensor takes about three lines of code.",{"type":23,"tag":36,"props":1103,"children":1105},{"id":1104},"what-i-changed-and-why",[1106],{"type":28,"value":1107},"What I Changed and Why",{"type":23,"tag":24,"props":1109,"children":1110},{},[1111],{"type":28,"value":1112},"The original stack wasn't around long enough for the refactoring costs to become truly painful, but there was one thing I already knew I didn't want to carry forward: the custom dashboard. A hand-built web interface is satisfying to build and tedious to keep current. Every new metric meant touching the schema, the API, and the dashboard component. The stack worked, but the dashboard was the part I least wanted to rebuild.",{"type":23,"tag":24,"props":1114,"children":1115},{},[1116],{"type":28,"value":1117},"So I didn't. The new approach delegates the dashboard to Home Assistant. Not because Home Assistant is perfect, but because someone else maintains it.",{"type":23,"tag":36,"props":1119,"children":1121},{"id":1120},"the-new-poller-typescript-and-modbus-serial",[1122],{"type":28,"value":1123},"The New Poller: TypeScript and modbus-serial",{"type":23,"tag":24,"props":1125,"children":1126},{},[1127,1129,1135,1137,1142],{"type":28,"value":1128},"The poller was rewritten in TypeScript on Node.js 20. I used ",{"type":23,"tag":131,"props":1130,"children":1132},{"className":1131},[],[1133],{"type":28,"value":1134},"modbus-serial",{"type":28,"value":1136}," for the Modbus RTU communication and the ",{"type":23,"tag":131,"props":1138,"children":1140},{"className":1139},[],[1141],{"type":28,"value":14},{"type":28,"value":1143}," library for publishing. The polling interval stayed at 5 seconds.",{"type":23,"tag":125,"props":1145,"children":1148},{"code":1146,"language":1051,"meta":8,"className":1147,"style":8},"import ModbusRTU from \"modbus-serial\";\nimport mqtt from \"mqtt\";\n\nconst client = new ModbusRTU();\nawait client.connectRTUBuffered(\"/dev/ttyUSB0\", {\n  baudRate: 9600,\n  parity: \"none\",\n  stopBits: 1,\n  dataBits: 8,\n});\nclient.setID(1);\nclient.setTimeout(3000);\n","language-typescript shiki shiki-themes github-dark",[1149],{"type":23,"tag":131,"props":1150,"children":1151},{"__ignoreMap":8},[1152,1180,1205,1214,1248,1281,1298,1315,1332,1349,1357,1383],{"type":23,"tag":135,"props":1153,"children":1154},{"class":137,"line":138},[1155,1160,1165,1170,1175],{"type":23,"tag":135,"props":1156,"children":1157},{"style":820},[1158],{"type":28,"value":1159},"import",{"type":23,"tag":135,"props":1161,"children":1162},{"style":163},[1163],{"type":28,"value":1164}," ModbusRTU ",{"type":23,"tag":135,"props":1166,"children":1167},{"style":820},[1168],{"type":28,"value":1169},"from",{"type":23,"tag":135,"props":1171,"children":1172},{"style":184},[1173],{"type":28,"value":1174}," \"modbus-serial\"",{"type":23,"tag":135,"props":1176,"children":1177},{"style":163},[1178],{"type":28,"value":1179},";\n",{"type":23,"tag":135,"props":1181,"children":1182},{"class":137,"line":169},[1183,1187,1192,1196,1201],{"type":23,"tag":135,"props":1184,"children":1185},{"style":820},[1186],{"type":28,"value":1159},{"type":23,"tag":135,"props":1188,"children":1189},{"style":163},[1190],{"type":28,"value":1191}," mqtt ",{"type":23,"tag":135,"props":1193,"children":1194},{"style":820},[1195],{"type":28,"value":1169},{"type":23,"tag":135,"props":1197,"children":1198},{"style":184},[1199],{"type":28,"value":1200}," \"mqtt\"",{"type":23,"tag":135,"props":1202,"children":1203},{"style":163},[1204],{"type":28,"value":1179},{"type":23,"tag":135,"props":1206,"children":1207},{"class":137,"line":195},[1208],{"type":23,"tag":135,"props":1209,"children":1211},{"emptyLinePlaceholder":1210},true,[1212],{"type":28,"value":1213},"\n",{"type":23,"tag":135,"props":1215,"children":1216},{"class":137,"line":217},[1217,1222,1227,1232,1237,1243],{"type":23,"tag":135,"props":1218,"children":1219},{"style":820},[1220],{"type":28,"value":1221},"const",{"type":23,"tag":135,"props":1223,"children":1224},{"style":173},[1225],{"type":28,"value":1226}," client",{"type":23,"tag":135,"props":1228,"children":1229},{"style":820},[1230],{"type":28,"value":1231}," =",{"type":23,"tag":135,"props":1233,"children":1234},{"style":820},[1235],{"type":28,"value":1236}," new",{"type":23,"tag":135,"props":1238,"children":1240},{"style":1239},"--shiki-default:#B392F0",[1241],{"type":28,"value":1242}," ModbusRTU",{"type":23,"tag":135,"props":1244,"children":1245},{"style":163},[1246],{"type":28,"value":1247},"();\n",{"type":23,"tag":135,"props":1249,"children":1250},{"class":137,"line":239},[1251,1256,1261,1266,1271,1276],{"type":23,"tag":135,"props":1252,"children":1253},{"style":820},[1254],{"type":28,"value":1255},"await",{"type":23,"tag":135,"props":1257,"children":1258},{"style":163},[1259],{"type":28,"value":1260}," client.",{"type":23,"tag":135,"props":1262,"children":1263},{"style":1239},[1264],{"type":28,"value":1265},"connectRTUBuffered",{"type":23,"tag":135,"props":1267,"children":1268},{"style":163},[1269],{"type":28,"value":1270},"(",{"type":23,"tag":135,"props":1272,"children":1273},{"style":184},[1274],{"type":28,"value":1275},"\"/dev/ttyUSB0\"",{"type":23,"tag":135,"props":1277,"children":1278},{"style":163},[1279],{"type":28,"value":1280},", {\n",{"type":23,"tag":135,"props":1282,"children":1283},{"class":137,"line":261},[1284,1289,1294],{"type":23,"tag":135,"props":1285,"children":1286},{"style":163},[1287],{"type":28,"value":1288},"  baudRate: ",{"type":23,"tag":135,"props":1290,"children":1291},{"style":173},[1292],{"type":28,"value":1293},"9600",{"type":23,"tag":135,"props":1295,"children":1296},{"style":163},[1297],{"type":28,"value":192},{"type":23,"tag":135,"props":1299,"children":1300},{"class":137,"line":283},[1301,1306,1311],{"type":23,"tag":135,"props":1302,"children":1303},{"style":163},[1304],{"type":28,"value":1305},"  parity: ",{"type":23,"tag":135,"props":1307,"children":1308},{"style":184},[1309],{"type":28,"value":1310},"\"none\"",{"type":23,"tag":135,"props":1312,"children":1313},{"style":163},[1314],{"type":28,"value":192},{"type":23,"tag":135,"props":1316,"children":1317},{"class":137,"line":305},[1318,1323,1328],{"type":23,"tag":135,"props":1319,"children":1320},{"style":163},[1321],{"type":28,"value":1322},"  stopBits: ",{"type":23,"tag":135,"props":1324,"children":1325},{"style":173},[1326],{"type":28,"value":1327},"1",{"type":23,"tag":135,"props":1329,"children":1330},{"style":163},[1331],{"type":28,"value":192},{"type":23,"tag":135,"props":1333,"children":1334},{"class":137,"line":319},[1335,1340,1345],{"type":23,"tag":135,"props":1336,"children":1337},{"style":163},[1338],{"type":28,"value":1339},"  dataBits: ",{"type":23,"tag":135,"props":1341,"children":1342},{"style":173},[1343],{"type":28,"value":1344},"8",{"type":23,"tag":135,"props":1346,"children":1347},{"style":163},[1348],{"type":28,"value":192},{"type":23,"tag":135,"props":1350,"children":1351},{"class":137,"line":343},[1352],{"type":23,"tag":135,"props":1353,"children":1354},{"style":163},[1355],{"type":28,"value":1356},"});\n",{"type":23,"tag":135,"props":1358,"children":1359},{"class":137,"line":361},[1360,1365,1370,1374,1378],{"type":23,"tag":135,"props":1361,"children":1362},{"style":163},[1363],{"type":28,"value":1364},"client.",{"type":23,"tag":135,"props":1366,"children":1367},{"style":1239},[1368],{"type":28,"value":1369},"setID",{"type":23,"tag":135,"props":1371,"children":1372},{"style":163},[1373],{"type":28,"value":1270},{"type":23,"tag":135,"props":1375,"children":1376},{"style":173},[1377],{"type":28,"value":1327},{"type":23,"tag":135,"props":1379,"children":1380},{"style":163},[1381],{"type":28,"value":1382},");\n",{"type":23,"tag":135,"props":1384,"children":1385},{"class":137,"line":370},[1386,1390,1395,1399,1404],{"type":23,"tag":135,"props":1387,"children":1388},{"style":163},[1389],{"type":28,"value":1364},{"type":23,"tag":135,"props":1391,"children":1392},{"style":1239},[1393],{"type":28,"value":1394},"setTimeout",{"type":23,"tag":135,"props":1396,"children":1397},{"style":163},[1398],{"type":28,"value":1270},{"type":23,"tag":135,"props":1400,"children":1401},{"style":173},[1402],{"type":28,"value":1403},"3000",{"type":23,"tag":135,"props":1405,"children":1406},{"style":163},[1407],{"type":28,"value":1382},{"type":23,"tag":24,"props":1409,"children":1410},{},[1411],{"type":28,"value":1412},"The register layout maps about 30 metrics across two protocol areas. P01 covers battery and PV data (input registers), P02 covers inverter state, grid, and load (a mix of input and holding registers). Same fallback logic as the original, but now with TypeScript types so the register definitions are explicit:",{"type":23,"tag":125,"props":1414,"children":1416},{"code":1415,"language":1051,"meta":8,"className":1147,"style":8},"type RegisterDef = {\n  address: number;\n  name: string;\n  scale: number;\n  unit: string;\n  deviceClass?: string;\n  stateClass?: string;\n};\n\nconst REGISTERS: RegisterDef[] = [\n  { address: 0x0100, name: \"battery_soc\",     scale: 1,    unit: \"%\",  deviceClass: \"battery\",     stateClass: \"measurement\" },\n  { address: 0x0101, name: \"battery_voltage\",  scale: 0.1,  unit: \"V\",  deviceClass: \"voltage\",     stateClass: \"measurement\" },\n  { address: 0x0102, name: \"battery_current\",  scale: 0.1,  unit: \"A\",  deviceClass: \"current\",     stateClass: \"measurement\" },\n  { address: 0x0107, name: \"pv1_voltage\",      scale: 0.1,  unit: \"V\",  deviceClass: \"voltage\",     stateClass: \"measurement\" },\n  { address: 0x0108, name: \"pv1_current\",      scale: 0.1,  unit: \"A\",  deviceClass: \"current\",     stateClass: \"measurement\" },\n  { address: 0x0109, name: \"pv1_power\",        scale: 1,    unit: \"W\",  deviceClass: \"power\",       stateClass: \"measurement\" },\n  // ...~24 more\n];\n",[1417],{"type":23,"tag":131,"props":1418,"children":1419},{"__ignoreMap":8},[1420,1442,1465,1486,1506,1526,1547,1567,1575,1582,1616,1679,1741,1801,1860,1918,1980,1989],{"type":23,"tag":135,"props":1421,"children":1422},{"class":137,"line":138},[1423,1428,1433,1437],{"type":23,"tag":135,"props":1424,"children":1425},{"style":820},[1426],{"type":28,"value":1427},"type",{"type":23,"tag":135,"props":1429,"children":1430},{"style":1239},[1431],{"type":28,"value":1432}," RegisterDef",{"type":23,"tag":135,"props":1434,"children":1435},{"style":820},[1436],{"type":28,"value":1231},{"type":23,"tag":135,"props":1438,"children":1439},{"style":163},[1440],{"type":28,"value":1441}," {\n",{"type":23,"tag":135,"props":1443,"children":1444},{"class":137,"line":169},[1445,1451,1456,1461],{"type":23,"tag":135,"props":1446,"children":1448},{"style":1447},"--shiki-default:#FFAB70",[1449],{"type":28,"value":1450},"  address",{"type":23,"tag":135,"props":1452,"children":1453},{"style":820},[1454],{"type":28,"value":1455},":",{"type":23,"tag":135,"props":1457,"children":1458},{"style":173},[1459],{"type":28,"value":1460}," number",{"type":23,"tag":135,"props":1462,"children":1463},{"style":163},[1464],{"type":28,"value":1179},{"type":23,"tag":135,"props":1466,"children":1467},{"class":137,"line":195},[1468,1473,1477,1482],{"type":23,"tag":135,"props":1469,"children":1470},{"style":1447},[1471],{"type":28,"value":1472},"  name",{"type":23,"tag":135,"props":1474,"children":1475},{"style":820},[1476],{"type":28,"value":1455},{"type":23,"tag":135,"props":1478,"children":1479},{"style":173},[1480],{"type":28,"value":1481}," string",{"type":23,"tag":135,"props":1483,"children":1484},{"style":163},[1485],{"type":28,"value":1179},{"type":23,"tag":135,"props":1487,"children":1488},{"class":137,"line":217},[1489,1494,1498,1502],{"type":23,"tag":135,"props":1490,"children":1491},{"style":1447},[1492],{"type":28,"value":1493},"  scale",{"type":23,"tag":135,"props":1495,"children":1496},{"style":820},[1497],{"type":28,"value":1455},{"type":23,"tag":135,"props":1499,"children":1500},{"style":173},[1501],{"type":28,"value":1460},{"type":23,"tag":135,"props":1503,"children":1504},{"style":163},[1505],{"type":28,"value":1179},{"type":23,"tag":135,"props":1507,"children":1508},{"class":137,"line":239},[1509,1514,1518,1522],{"type":23,"tag":135,"props":1510,"children":1511},{"style":1447},[1512],{"type":28,"value":1513},"  unit",{"type":23,"tag":135,"props":1515,"children":1516},{"style":820},[1517],{"type":28,"value":1455},{"type":23,"tag":135,"props":1519,"children":1520},{"style":173},[1521],{"type":28,"value":1481},{"type":23,"tag":135,"props":1523,"children":1524},{"style":163},[1525],{"type":28,"value":1179},{"type":23,"tag":135,"props":1527,"children":1528},{"class":137,"line":261},[1529,1534,1539,1543],{"type":23,"tag":135,"props":1530,"children":1531},{"style":1447},[1532],{"type":28,"value":1533},"  deviceClass",{"type":23,"tag":135,"props":1535,"children":1536},{"style":820},[1537],{"type":28,"value":1538},"?:",{"type":23,"tag":135,"props":1540,"children":1541},{"style":173},[1542],{"type":28,"value":1481},{"type":23,"tag":135,"props":1544,"children":1545},{"style":163},[1546],{"type":28,"value":1179},{"type":23,"tag":135,"props":1548,"children":1549},{"class":137,"line":283},[1550,1555,1559,1563],{"type":23,"tag":135,"props":1551,"children":1552},{"style":1447},[1553],{"type":28,"value":1554},"  stateClass",{"type":23,"tag":135,"props":1556,"children":1557},{"style":820},[1558],{"type":28,"value":1538},{"type":23,"tag":135,"props":1560,"children":1561},{"style":173},[1562],{"type":28,"value":1481},{"type":23,"tag":135,"props":1564,"children":1565},{"style":163},[1566],{"type":28,"value":1179},{"type":23,"tag":135,"props":1568,"children":1569},{"class":137,"line":305},[1570],{"type":23,"tag":135,"props":1571,"children":1572},{"style":163},[1573],{"type":28,"value":1574},"};\n",{"type":23,"tag":135,"props":1576,"children":1577},{"class":137,"line":319},[1578],{"type":23,"tag":135,"props":1579,"children":1580},{"emptyLinePlaceholder":1210},[1581],{"type":28,"value":1213},{"type":23,"tag":135,"props":1583,"children":1584},{"class":137,"line":343},[1585,1589,1594,1598,1602,1607,1611],{"type":23,"tag":135,"props":1586,"children":1587},{"style":820},[1588],{"type":28,"value":1221},{"type":23,"tag":135,"props":1590,"children":1591},{"style":173},[1592],{"type":28,"value":1593}," REGISTERS",{"type":23,"tag":135,"props":1595,"children":1596},{"style":820},[1597],{"type":28,"value":1455},{"type":23,"tag":135,"props":1599,"children":1600},{"style":1239},[1601],{"type":28,"value":1432},{"type":23,"tag":135,"props":1603,"children":1604},{"style":163},[1605],{"type":28,"value":1606},"[] ",{"type":23,"tag":135,"props":1608,"children":1609},{"style":820},[1610],{"type":28,"value":823},{"type":23,"tag":135,"props":1612,"children":1613},{"style":163},[1614],{"type":28,"value":1615}," [\n",{"type":23,"tag":135,"props":1617,"children":1618},{"class":137,"line":361},[1619,1624,1629,1634,1638,1643,1647,1652,1656,1661,1665,1670,1674],{"type":23,"tag":135,"props":1620,"children":1621},{"style":163},[1622],{"type":28,"value":1623},"  { address: ",{"type":23,"tag":135,"props":1625,"children":1626},{"style":173},[1627],{"type":28,"value":1628},"0x0100",{"type":23,"tag":135,"props":1630,"children":1631},{"style":163},[1632],{"type":28,"value":1633},", name: ",{"type":23,"tag":135,"props":1635,"children":1636},{"style":184},[1637],{"type":28,"value":187},{"type":23,"tag":135,"props":1639,"children":1640},{"style":163},[1641],{"type":28,"value":1642},",     scale: ",{"type":23,"tag":135,"props":1644,"children":1645},{"style":173},[1646],{"type":28,"value":1327},{"type":23,"tag":135,"props":1648,"children":1649},{"style":163},[1650],{"type":28,"value":1651},",    unit: ",{"type":23,"tag":135,"props":1653,"children":1654},{"style":184},[1655],{"type":28,"value":232},{"type":23,"tag":135,"props":1657,"children":1658},{"style":163},[1659],{"type":28,"value":1660},",  deviceClass: ",{"type":23,"tag":135,"props":1662,"children":1663},{"style":184},[1664],{"type":28,"value":254},{"type":23,"tag":135,"props":1666,"children":1667},{"style":163},[1668],{"type":28,"value":1669},",     stateClass: ",{"type":23,"tag":135,"props":1671,"children":1672},{"style":184},[1673],{"type":28,"value":276},{"type":23,"tag":135,"props":1675,"children":1676},{"style":163},[1677],{"type":28,"value":1678}," },\n",{"type":23,"tag":135,"props":1680,"children":1681},{"class":137,"line":370},[1682,1686,1691,1695,1700,1705,1710,1715,1720,1724,1729,1733,1737],{"type":23,"tag":135,"props":1683,"children":1684},{"style":163},[1685],{"type":28,"value":1623},{"type":23,"tag":135,"props":1687,"children":1688},{"style":173},[1689],{"type":28,"value":1690},"0x0101",{"type":23,"tag":135,"props":1692,"children":1693},{"style":163},[1694],{"type":28,"value":1633},{"type":23,"tag":135,"props":1696,"children":1697},{"style":184},[1698],{"type":28,"value":1699},"\"battery_voltage\"",{"type":23,"tag":135,"props":1701,"children":1702},{"style":163},[1703],{"type":28,"value":1704},",  scale: ",{"type":23,"tag":135,"props":1706,"children":1707},{"style":173},[1708],{"type":28,"value":1709},"0.1",{"type":23,"tag":135,"props":1711,"children":1712},{"style":163},[1713],{"type":28,"value":1714},",  unit: ",{"type":23,"tag":135,"props":1716,"children":1717},{"style":184},[1718],{"type":28,"value":1719},"\"V\"",{"type":23,"tag":135,"props":1721,"children":1722},{"style":163},[1723],{"type":28,"value":1660},{"type":23,"tag":135,"props":1725,"children":1726},{"style":184},[1727],{"type":28,"value":1728},"\"voltage\"",{"type":23,"tag":135,"props":1730,"children":1731},{"style":163},[1732],{"type":28,"value":1669},{"type":23,"tag":135,"props":1734,"children":1735},{"style":184},[1736],{"type":28,"value":276},{"type":23,"tag":135,"props":1738,"children":1739},{"style":163},[1740],{"type":28,"value":1678},{"type":23,"tag":135,"props":1742,"children":1744},{"class":137,"line":1743},13,[1745,1749,1754,1758,1763,1767,1771,1775,1780,1784,1789,1793,1797],{"type":23,"tag":135,"props":1746,"children":1747},{"style":163},[1748],{"type":28,"value":1623},{"type":23,"tag":135,"props":1750,"children":1751},{"style":173},[1752],{"type":28,"value":1753},"0x0102",{"type":23,"tag":135,"props":1755,"children":1756},{"style":163},[1757],{"type":28,"value":1633},{"type":23,"tag":135,"props":1759,"children":1760},{"style":184},[1761],{"type":28,"value":1762},"\"battery_current\"",{"type":23,"tag":135,"props":1764,"children":1765},{"style":163},[1766],{"type":28,"value":1704},{"type":23,"tag":135,"props":1768,"children":1769},{"style":173},[1770],{"type":28,"value":1709},{"type":23,"tag":135,"props":1772,"children":1773},{"style":163},[1774],{"type":28,"value":1714},{"type":23,"tag":135,"props":1776,"children":1777},{"style":184},[1778],{"type":28,"value":1779},"\"A\"",{"type":23,"tag":135,"props":1781,"children":1782},{"style":163},[1783],{"type":28,"value":1660},{"type":23,"tag":135,"props":1785,"children":1786},{"style":184},[1787],{"type":28,"value":1788},"\"current\"",{"type":23,"tag":135,"props":1790,"children":1791},{"style":163},[1792],{"type":28,"value":1669},{"type":23,"tag":135,"props":1794,"children":1795},{"style":184},[1796],{"type":28,"value":276},{"type":23,"tag":135,"props":1798,"children":1799},{"style":163},[1800],{"type":28,"value":1678},{"type":23,"tag":135,"props":1802,"children":1804},{"class":137,"line":1803},14,[1805,1809,1814,1818,1823,1828,1832,1836,1840,1844,1848,1852,1856],{"type":23,"tag":135,"props":1806,"children":1807},{"style":163},[1808],{"type":28,"value":1623},{"type":23,"tag":135,"props":1810,"children":1811},{"style":173},[1812],{"type":28,"value":1813},"0x0107",{"type":23,"tag":135,"props":1815,"children":1816},{"style":163},[1817],{"type":28,"value":1633},{"type":23,"tag":135,"props":1819,"children":1820},{"style":184},[1821],{"type":28,"value":1822},"\"pv1_voltage\"",{"type":23,"tag":135,"props":1824,"children":1825},{"style":163},[1826],{"type":28,"value":1827},",      scale: ",{"type":23,"tag":135,"props":1829,"children":1830},{"style":173},[1831],{"type":28,"value":1709},{"type":23,"tag":135,"props":1833,"children":1834},{"style":163},[1835],{"type":28,"value":1714},{"type":23,"tag":135,"props":1837,"children":1838},{"style":184},[1839],{"type":28,"value":1719},{"type":23,"tag":135,"props":1841,"children":1842},{"style":163},[1843],{"type":28,"value":1660},{"type":23,"tag":135,"props":1845,"children":1846},{"style":184},[1847],{"type":28,"value":1728},{"type":23,"tag":135,"props":1849,"children":1850},{"style":163},[1851],{"type":28,"value":1669},{"type":23,"tag":135,"props":1853,"children":1854},{"style":184},[1855],{"type":28,"value":276},{"type":23,"tag":135,"props":1857,"children":1858},{"style":163},[1859],{"type":28,"value":1678},{"type":23,"tag":135,"props":1861,"children":1863},{"class":137,"line":1862},15,[1864,1868,1873,1877,1882,1886,1890,1894,1898,1902,1906,1910,1914],{"type":23,"tag":135,"props":1865,"children":1866},{"style":163},[1867],{"type":28,"value":1623},{"type":23,"tag":135,"props":1869,"children":1870},{"style":173},[1871],{"type":28,"value":1872},"0x0108",{"type":23,"tag":135,"props":1874,"children":1875},{"style":163},[1876],{"type":28,"value":1633},{"type":23,"tag":135,"props":1878,"children":1879},{"style":184},[1880],{"type":28,"value":1881},"\"pv1_current\"",{"type":23,"tag":135,"props":1883,"children":1884},{"style":163},[1885],{"type":28,"value":1827},{"type":23,"tag":135,"props":1887,"children":1888},{"style":173},[1889],{"type":28,"value":1709},{"type":23,"tag":135,"props":1891,"children":1892},{"style":163},[1893],{"type":28,"value":1714},{"type":23,"tag":135,"props":1895,"children":1896},{"style":184},[1897],{"type":28,"value":1779},{"type":23,"tag":135,"props":1899,"children":1900},{"style":163},[1901],{"type":28,"value":1660},{"type":23,"tag":135,"props":1903,"children":1904},{"style":184},[1905],{"type":28,"value":1788},{"type":23,"tag":135,"props":1907,"children":1908},{"style":163},[1909],{"type":28,"value":1669},{"type":23,"tag":135,"props":1911,"children":1912},{"style":184},[1913],{"type":28,"value":276},{"type":23,"tag":135,"props":1915,"children":1916},{"style":163},[1917],{"type":28,"value":1678},{"type":23,"tag":135,"props":1919,"children":1921},{"class":137,"line":1920},16,[1922,1926,1931,1935,1940,1945,1949,1953,1958,1962,1967,1972,1976],{"type":23,"tag":135,"props":1923,"children":1924},{"style":163},[1925],{"type":28,"value":1623},{"type":23,"tag":135,"props":1927,"children":1928},{"style":173},[1929],{"type":28,"value":1930},"0x0109",{"type":23,"tag":135,"props":1932,"children":1933},{"style":163},[1934],{"type":28,"value":1633},{"type":23,"tag":135,"props":1936,"children":1937},{"style":184},[1938],{"type":28,"value":1939},"\"pv1_power\"",{"type":23,"tag":135,"props":1941,"children":1942},{"style":163},[1943],{"type":28,"value":1944},",        scale: ",{"type":23,"tag":135,"props":1946,"children":1947},{"style":173},[1948],{"type":28,"value":1327},{"type":23,"tag":135,"props":1950,"children":1951},{"style":163},[1952],{"type":28,"value":1651},{"type":23,"tag":135,"props":1954,"children":1955},{"style":184},[1956],{"type":28,"value":1957},"\"W\"",{"type":23,"tag":135,"props":1959,"children":1960},{"style":163},[1961],{"type":28,"value":1660},{"type":23,"tag":135,"props":1963,"children":1964},{"style":184},[1965],{"type":28,"value":1966},"\"power\"",{"type":23,"tag":135,"props":1968,"children":1969},{"style":163},[1970],{"type":28,"value":1971},",       stateClass: ",{"type":23,"tag":135,"props":1973,"children":1974},{"style":184},[1975],{"type":28,"value":276},{"type":23,"tag":135,"props":1977,"children":1978},{"style":163},[1979],{"type":28,"value":1678},{"type":23,"tag":135,"props":1981,"children":1983},{"class":137,"line":1982},17,[1984],{"type":23,"tag":135,"props":1985,"children":1986},{"style":674},[1987],{"type":28,"value":1988},"  // ...~24 more\n",{"type":23,"tag":135,"props":1990,"children":1992},{"class":137,"line":1991},18,[1993],{"type":23,"tag":135,"props":1994,"children":1995},{"style":163},[1996],{"type":28,"value":1997},"];\n",{"type":23,"tag":24,"props":1999,"children":2000},{},[2001],{"type":28,"value":2002},"Having types here pays off immediately. In Python, a missing key in a dictionary fails at runtime. In TypeScript with strict mode, the wrong shape fails at compile time. I caught two register scaling bugs during the rewrite that would have silently produced wrong numbers in the original.",{"type":23,"tag":2004,"props":2005,"children":2007},"h3",{"id":2006},"auto-grouping-contiguous-registers",[2008],{"type":28,"value":2009},"Auto-Grouping Contiguous Registers",{"type":23,"tag":24,"props":2011,"children":2012},{},[2013],{"type":28,"value":2014},"The same contiguous grouping logic from the Python version is here, but typed:",{"type":23,"tag":125,"props":2016,"children":2018},{"code":2017,"language":1051,"meta":8,"className":1147,"style":8},"function groupContiguous(regs: RegisterDef[]): Array\u003C{ start: number; count: number; defs: RegisterDef[] }> {\n  const sorted = [...regs].sort((a, b) => a.address - b.address);\n  const blocks: Array\u003C{ start: number; count: number; defs: RegisterDef[] }> = [];\n  let group: RegisterDef[] = [sorted[0]];\n\n  for (let i = 1; i \u003C sorted.length; i++) {\n    if (sorted[i].address === sorted[i - 1].address + 1) {\n      group.push(sorted[i]);\n    } else {\n      blocks.push({ start: group[0].address, count: group.length, defs: group });\n      group = [sorted[i]];\n    }\n  }\n  blocks.push({ start: group[0].address, count: group.length, defs: group });\n  return blocks;\n}\n",[2019],{"type":23,"tag":131,"props":2020,"children":2021},{"__ignoreMap":8},[2022,2124,2205,2287,2331,2338,2405,2454,2472,2489,2524,2541,2549,2556,2588,2601],{"type":23,"tag":135,"props":2023,"children":2024},{"class":137,"line":138},[2025,2030,2035,2039,2044,2048,2052,2057,2061,2066,2071,2076,2080,2084,2089,2094,2098,2102,2106,2111,2115,2119],{"type":23,"tag":135,"props":2026,"children":2027},{"style":820},[2028],{"type":28,"value":2029},"function",{"type":23,"tag":135,"props":2031,"children":2032},{"style":1239},[2033],{"type":28,"value":2034}," groupContiguous",{"type":23,"tag":135,"props":2036,"children":2037},{"style":163},[2038],{"type":28,"value":1270},{"type":23,"tag":135,"props":2040,"children":2041},{"style":1447},[2042],{"type":28,"value":2043},"regs",{"type":23,"tag":135,"props":2045,"children":2046},{"style":820},[2047],{"type":28,"value":1455},{"type":23,"tag":135,"props":2049,"children":2050},{"style":1239},[2051],{"type":28,"value":1432},{"type":23,"tag":135,"props":2053,"children":2054},{"style":163},[2055],{"type":28,"value":2056},"[])",{"type":23,"tag":135,"props":2058,"children":2059},{"style":820},[2060],{"type":28,"value":1455},{"type":23,"tag":135,"props":2062,"children":2063},{"style":1239},[2064],{"type":28,"value":2065}," Array",{"type":23,"tag":135,"props":2067,"children":2068},{"style":163},[2069],{"type":28,"value":2070},"\u003C{ ",{"type":23,"tag":135,"props":2072,"children":2073},{"style":1447},[2074],{"type":28,"value":2075},"start",{"type":23,"tag":135,"props":2077,"children":2078},{"style":820},[2079],{"type":28,"value":1455},{"type":23,"tag":135,"props":2081,"children":2082},{"style":173},[2083],{"type":28,"value":1460},{"type":23,"tag":135,"props":2085,"children":2086},{"style":163},[2087],{"type":28,"value":2088},"; ",{"type":23,"tag":135,"props":2090,"children":2091},{"style":1447},[2092],{"type":28,"value":2093},"count",{"type":23,"tag":135,"props":2095,"children":2096},{"style":820},[2097],{"type":28,"value":1455},{"type":23,"tag":135,"props":2099,"children":2100},{"style":173},[2101],{"type":28,"value":1460},{"type":23,"tag":135,"props":2103,"children":2104},{"style":163},[2105],{"type":28,"value":2088},{"type":23,"tag":135,"props":2107,"children":2108},{"style":1447},[2109],{"type":28,"value":2110},"defs",{"type":23,"tag":135,"props":2112,"children":2113},{"style":820},[2114],{"type":28,"value":1455},{"type":23,"tag":135,"props":2116,"children":2117},{"style":1239},[2118],{"type":28,"value":1432},{"type":23,"tag":135,"props":2120,"children":2121},{"style":163},[2122],{"type":28,"value":2123},"[] }> {\n",{"type":23,"tag":135,"props":2125,"children":2126},{"class":137,"line":169},[2127,2132,2137,2141,2146,2151,2156,2161,2166,2170,2175,2180,2185,2190,2195,2200],{"type":23,"tag":135,"props":2128,"children":2129},{"style":820},[2130],{"type":28,"value":2131},"  const",{"type":23,"tag":135,"props":2133,"children":2134},{"style":173},[2135],{"type":28,"value":2136}," sorted",{"type":23,"tag":135,"props":2138,"children":2139},{"style":820},[2140],{"type":28,"value":1231},{"type":23,"tag":135,"props":2142,"children":2143},{"style":163},[2144],{"type":28,"value":2145}," [",{"type":23,"tag":135,"props":2147,"children":2148},{"style":820},[2149],{"type":28,"value":2150},"...",{"type":23,"tag":135,"props":2152,"children":2153},{"style":163},[2154],{"type":28,"value":2155},"regs].",{"type":23,"tag":135,"props":2157,"children":2158},{"style":1239},[2159],{"type":28,"value":2160},"sort",{"type":23,"tag":135,"props":2162,"children":2163},{"style":163},[2164],{"type":28,"value":2165},"((",{"type":23,"tag":135,"props":2167,"children":2168},{"style":1447},[2169],{"type":28,"value":48},{"type":23,"tag":135,"props":2171,"children":2172},{"style":163},[2173],{"type":28,"value":2174},", ",{"type":23,"tag":135,"props":2176,"children":2177},{"style":1447},[2178],{"type":28,"value":2179},"b",{"type":23,"tag":135,"props":2181,"children":2182},{"style":163},[2183],{"type":28,"value":2184},") ",{"type":23,"tag":135,"props":2186,"children":2187},{"style":820},[2188],{"type":28,"value":2189},"=>",{"type":23,"tag":135,"props":2191,"children":2192},{"style":163},[2193],{"type":28,"value":2194}," a.address ",{"type":23,"tag":135,"props":2196,"children":2197},{"style":820},[2198],{"type":28,"value":2199},"-",{"type":23,"tag":135,"props":2201,"children":2202},{"style":163},[2203],{"type":28,"value":2204}," b.address);\n",{"type":23,"tag":135,"props":2206,"children":2207},{"class":137,"line":195},[2208,2212,2217,2221,2225,2229,2233,2237,2241,2245,2249,2253,2257,2261,2265,2269,2273,2278,2282],{"type":23,"tag":135,"props":2209,"children":2210},{"style":820},[2211],{"type":28,"value":2131},{"type":23,"tag":135,"props":2213,"children":2214},{"style":173},[2215],{"type":28,"value":2216}," blocks",{"type":23,"tag":135,"props":2218,"children":2219},{"style":820},[2220],{"type":28,"value":1455},{"type":23,"tag":135,"props":2222,"children":2223},{"style":1239},[2224],{"type":28,"value":2065},{"type":23,"tag":135,"props":2226,"children":2227},{"style":163},[2228],{"type":28,"value":2070},{"type":23,"tag":135,"props":2230,"children":2231},{"style":1447},[2232],{"type":28,"value":2075},{"type":23,"tag":135,"props":2234,"children":2235},{"style":820},[2236],{"type":28,"value":1455},{"type":23,"tag":135,"props":2238,"children":2239},{"style":173},[2240],{"type":28,"value":1460},{"type":23,"tag":135,"props":2242,"children":2243},{"style":163},[2244],{"type":28,"value":2088},{"type":23,"tag":135,"props":2246,"children":2247},{"style":1447},[2248],{"type":28,"value":2093},{"type":23,"tag":135,"props":2250,"children":2251},{"style":820},[2252],{"type":28,"value":1455},{"type":23,"tag":135,"props":2254,"children":2255},{"style":173},[2256],{"type":28,"value":1460},{"type":23,"tag":135,"props":2258,"children":2259},{"style":163},[2260],{"type":28,"value":2088},{"type":23,"tag":135,"props":2262,"children":2263},{"style":1447},[2264],{"type":28,"value":2110},{"type":23,"tag":135,"props":2266,"children":2267},{"style":820},[2268],{"type":28,"value":1455},{"type":23,"tag":135,"props":2270,"children":2271},{"style":1239},[2272],{"type":28,"value":1432},{"type":23,"tag":135,"props":2274,"children":2275},{"style":163},[2276],{"type":28,"value":2277},"[] }> ",{"type":23,"tag":135,"props":2279,"children":2280},{"style":820},[2281],{"type":28,"value":823},{"type":23,"tag":135,"props":2283,"children":2284},{"style":163},[2285],{"type":28,"value":2286}," [];\n",{"type":23,"tag":135,"props":2288,"children":2289},{"class":137,"line":217},[2290,2295,2300,2304,2308,2312,2316,2321,2326],{"type":23,"tag":135,"props":2291,"children":2292},{"style":820},[2293],{"type":28,"value":2294},"  let",{"type":23,"tag":135,"props":2296,"children":2297},{"style":163},[2298],{"type":28,"value":2299}," group",{"type":23,"tag":135,"props":2301,"children":2302},{"style":820},[2303],{"type":28,"value":1455},{"type":23,"tag":135,"props":2305,"children":2306},{"style":1239},[2307],{"type":28,"value":1432},{"type":23,"tag":135,"props":2309,"children":2310},{"style":163},[2311],{"type":28,"value":1606},{"type":23,"tag":135,"props":2313,"children":2314},{"style":820},[2315],{"type":28,"value":823},{"type":23,"tag":135,"props":2317,"children":2318},{"style":163},[2319],{"type":28,"value":2320}," [sorted[",{"type":23,"tag":135,"props":2322,"children":2323},{"style":173},[2324],{"type":28,"value":2325},"0",{"type":23,"tag":135,"props":2327,"children":2328},{"style":163},[2329],{"type":28,"value":2330},"]];\n",{"type":23,"tag":135,"props":2332,"children":2333},{"class":137,"line":239},[2334],{"type":23,"tag":135,"props":2335,"children":2336},{"emptyLinePlaceholder":1210},[2337],{"type":28,"value":1213},{"type":23,"tag":135,"props":2339,"children":2340},{"class":137,"line":261},[2341,2346,2351,2356,2361,2365,2370,2375,2380,2385,2390,2395,2400],{"type":23,"tag":135,"props":2342,"children":2343},{"style":820},[2344],{"type":28,"value":2345},"  for",{"type":23,"tag":135,"props":2347,"children":2348},{"style":163},[2349],{"type":28,"value":2350}," (",{"type":23,"tag":135,"props":2352,"children":2353},{"style":820},[2354],{"type":28,"value":2355},"let",{"type":23,"tag":135,"props":2357,"children":2358},{"style":163},[2359],{"type":28,"value":2360}," i ",{"type":23,"tag":135,"props":2362,"children":2363},{"style":820},[2364],{"type":28,"value":823},{"type":23,"tag":135,"props":2366,"children":2367},{"style":173},[2368],{"type":28,"value":2369}," 1",{"type":23,"tag":135,"props":2371,"children":2372},{"style":163},[2373],{"type":28,"value":2374},"; i ",{"type":23,"tag":135,"props":2376,"children":2377},{"style":820},[2378],{"type":28,"value":2379},"\u003C",{"type":23,"tag":135,"props":2381,"children":2382},{"style":163},[2383],{"type":28,"value":2384}," sorted.",{"type":23,"tag":135,"props":2386,"children":2387},{"style":173},[2388],{"type":28,"value":2389},"length",{"type":23,"tag":135,"props":2391,"children":2392},{"style":163},[2393],{"type":28,"value":2394},"; i",{"type":23,"tag":135,"props":2396,"children":2397},{"style":820},[2398],{"type":28,"value":2399},"++",{"type":23,"tag":135,"props":2401,"children":2402},{"style":163},[2403],{"type":28,"value":2404},") {\n",{"type":23,"tag":135,"props":2406,"children":2407},{"class":137,"line":283},[2408,2413,2418,2423,2428,2432,2436,2441,2446,2450],{"type":23,"tag":135,"props":2409,"children":2410},{"style":820},[2411],{"type":28,"value":2412},"    if",{"type":23,"tag":135,"props":2414,"children":2415},{"style":163},[2416],{"type":28,"value":2417}," (sorted[i].address ",{"type":23,"tag":135,"props":2419,"children":2420},{"style":820},[2421],{"type":28,"value":2422},"===",{"type":23,"tag":135,"props":2424,"children":2425},{"style":163},[2426],{"type":28,"value":2427}," sorted[i ",{"type":23,"tag":135,"props":2429,"children":2430},{"style":820},[2431],{"type":28,"value":2199},{"type":23,"tag":135,"props":2433,"children":2434},{"style":173},[2435],{"type":28,"value":2369},{"type":23,"tag":135,"props":2437,"children":2438},{"style":163},[2439],{"type":28,"value":2440},"].address ",{"type":23,"tag":135,"props":2442,"children":2443},{"style":820},[2444],{"type":28,"value":2445},"+",{"type":23,"tag":135,"props":2447,"children":2448},{"style":173},[2449],{"type":28,"value":2369},{"type":23,"tag":135,"props":2451,"children":2452},{"style":163},[2453],{"type":28,"value":2404},{"type":23,"tag":135,"props":2455,"children":2456},{"class":137,"line":305},[2457,2462,2467],{"type":23,"tag":135,"props":2458,"children":2459},{"style":163},[2460],{"type":28,"value":2461},"      group.",{"type":23,"tag":135,"props":2463,"children":2464},{"style":1239},[2465],{"type":28,"value":2466},"push",{"type":23,"tag":135,"props":2468,"children":2469},{"style":163},[2470],{"type":28,"value":2471},"(sorted[i]);\n",{"type":23,"tag":135,"props":2473,"children":2474},{"class":137,"line":319},[2475,2480,2485],{"type":23,"tag":135,"props":2476,"children":2477},{"style":163},[2478],{"type":28,"value":2479},"    } ",{"type":23,"tag":135,"props":2481,"children":2482},{"style":820},[2483],{"type":28,"value":2484},"else",{"type":23,"tag":135,"props":2486,"children":2487},{"style":163},[2488],{"type":28,"value":1441},{"type":23,"tag":135,"props":2490,"children":2491},{"class":137,"line":343},[2492,2497,2501,2506,2510,2515,2519],{"type":23,"tag":135,"props":2493,"children":2494},{"style":163},[2495],{"type":28,"value":2496},"      blocks.",{"type":23,"tag":135,"props":2498,"children":2499},{"style":1239},[2500],{"type":28,"value":2466},{"type":23,"tag":135,"props":2502,"children":2503},{"style":163},[2504],{"type":28,"value":2505},"({ start: group[",{"type":23,"tag":135,"props":2507,"children":2508},{"style":173},[2509],{"type":28,"value":2325},{"type":23,"tag":135,"props":2511,"children":2512},{"style":163},[2513],{"type":28,"value":2514},"].address, count: group.",{"type":23,"tag":135,"props":2516,"children":2517},{"style":173},[2518],{"type":28,"value":2389},{"type":23,"tag":135,"props":2520,"children":2521},{"style":163},[2522],{"type":28,"value":2523},", defs: group });\n",{"type":23,"tag":135,"props":2525,"children":2526},{"class":137,"line":361},[2527,2532,2536],{"type":23,"tag":135,"props":2528,"children":2529},{"style":163},[2530],{"type":28,"value":2531},"      group ",{"type":23,"tag":135,"props":2533,"children":2534},{"style":820},[2535],{"type":28,"value":823},{"type":23,"tag":135,"props":2537,"children":2538},{"style":163},[2539],{"type":28,"value":2540}," [sorted[i]];\n",{"type":23,"tag":135,"props":2542,"children":2543},{"class":137,"line":370},[2544],{"type":23,"tag":135,"props":2545,"children":2546},{"style":163},[2547],{"type":28,"value":2548},"    }\n",{"type":23,"tag":135,"props":2550,"children":2551},{"class":137,"line":1743},[2552],{"type":23,"tag":135,"props":2553,"children":2554},{"style":163},[2555],{"type":28,"value":367},{"type":23,"tag":135,"props":2557,"children":2558},{"class":137,"line":1803},[2559,2564,2568,2572,2576,2580,2584],{"type":23,"tag":135,"props":2560,"children":2561},{"style":163},[2562],{"type":28,"value":2563},"  blocks.",{"type":23,"tag":135,"props":2565,"children":2566},{"style":1239},[2567],{"type":28,"value":2466},{"type":23,"tag":135,"props":2569,"children":2570},{"style":163},[2571],{"type":28,"value":2505},{"type":23,"tag":135,"props":2573,"children":2574},{"style":173},[2575],{"type":28,"value":2325},{"type":23,"tag":135,"props":2577,"children":2578},{"style":163},[2579],{"type":28,"value":2514},{"type":23,"tag":135,"props":2581,"children":2582},{"style":173},[2583],{"type":28,"value":2389},{"type":23,"tag":135,"props":2585,"children":2586},{"style":163},[2587],{"type":28,"value":2523},{"type":23,"tag":135,"props":2589,"children":2590},{"class":137,"line":1862},[2591,2596],{"type":23,"tag":135,"props":2592,"children":2593},{"style":820},[2594],{"type":28,"value":2595},"  return",{"type":23,"tag":135,"props":2597,"children":2598},{"style":163},[2599],{"type":28,"value":2600}," blocks;\n",{"type":23,"tag":135,"props":2602,"children":2603},{"class":137,"line":1920},[2604],{"type":23,"tag":135,"props":2605,"children":2606},{"style":163},[2607],{"type":28,"value":376},{"type":23,"tag":24,"props":2609,"children":2610},{},[2611],{"type":28,"value":2612},"This runs once at startup, so there's no overhead per poll cycle.",{"type":23,"tag":36,"props":2614,"children":2616},{"id":2615},"mqtt-replaces-the-custom-api",[2617],{"type":28,"value":2618},"MQTT Replaces the Custom API",{"type":23,"tag":24,"props":2620,"children":2621},{},[2622],{"type":28,"value":2623},"In the original stack, the TypeScript API was the integration layer. Anything that wanted solar data had to know the API's endpoints and speak HTTP.",{"type":23,"tag":24,"props":2625,"children":2626},{},[2627],{"type":28,"value":2628},"The new integration layer is MQTT, specifically Eclipse Mosquitto running in the same Docker Compose stack. The poller publishes each metric as a retained message on a per-sensor topic:",{"type":23,"tag":125,"props":2630,"children":2632},{"code":2631},"solar/battery_soc        → \"87\"\nsolar/battery_voltage    → \"52.3\"\nsolar/pv1_power          → \"1840\"\nsolar/inverter_state     → \"charging\"\n",[2633],{"type":23,"tag":131,"props":2634,"children":2635},{"__ignoreMap":8},[2636],{"type":28,"value":2631},{"type":23,"tag":24,"props":2638,"children":2639},{},[2640],{"type":28,"value":2641},"Retained messages mean any new subscriber immediately gets the last known value without waiting for the next poll cycle. Everything that wants solar data subscribes to the relevant topics. Nothing needs to know about the poller, TimescaleDB, or Modbus. MQTT is the contract.",{"type":23,"tag":36,"props":2643,"children":2645},{"id":2644},"home-assistant-auto-discovery",[2646],{"type":28,"value":2647},"Home Assistant Auto-Discovery",{"type":23,"tag":24,"props":2649,"children":2650},{},[2651],{"type":28,"value":2652},"This is the part that changed the maintenance picture most dramatically.",{"type":23,"tag":24,"props":2654,"children":2655},{},[2656],{"type":28,"value":2657},"The poller publishes Home Assistant MQTT discovery configs at startup. Each sensor definition maps directly to a discovery message:",{"type":23,"tag":125,"props":2659,"children":2661},{"code":2660,"language":1051,"meta":8,"className":1147,"style":8},"function publishDiscovery(mqttClient: mqtt.MqttClient, reg: RegisterDef): void {\n  const config = {\n    name: reg.name.replace(/_/g, \" \"),\n    state_topic: `solar/${reg.name}`,\n    unit_of_measurement: reg.unit,\n    device_class: reg.deviceClass,\n    state_class: reg.stateClass,\n    unique_id: `sph5048_${reg.name}`,\n    device: {\n      identifiers: [\"sph5048\"],\n      name: \"Solar Inverter\",\n      model: \"SPH5048\",\n      manufacturer: \"Sungoldpower\",\n    },\n  };\n\n  mqttClient.publish(\n    `homeassistant/sensor/sph5048/${reg.name}/config`,\n    JSON.stringify(config),\n    { retain: true }\n  );\n}\n",[2662],{"type":23,"tag":131,"props":2663,"children":2664},{"__ignoreMap":8},[2665,2740,2760,2811,2846,2854,2862,2870,2903,2911,2927,2944,2961,2978,2986,2994,3001,3019,3048,3071,3090,3099],{"type":23,"tag":135,"props":2666,"children":2667},{"class":137,"line":138},[2668,2672,2677,2681,2686,2690,2695,2700,2705,2709,2714,2718,2722,2727,2731,2736],{"type":23,"tag":135,"props":2669,"children":2670},{"style":820},[2671],{"type":28,"value":2029},{"type":23,"tag":135,"props":2673,"children":2674},{"style":1239},[2675],{"type":28,"value":2676}," publishDiscovery",{"type":23,"tag":135,"props":2678,"children":2679},{"style":163},[2680],{"type":28,"value":1270},{"type":23,"tag":135,"props":2682,"children":2683},{"style":1447},[2684],{"type":28,"value":2685},"mqttClient",{"type":23,"tag":135,"props":2687,"children":2688},{"style":820},[2689],{"type":28,"value":1455},{"type":23,"tag":135,"props":2691,"children":2692},{"style":1239},[2693],{"type":28,"value":2694}," mqtt",{"type":23,"tag":135,"props":2696,"children":2697},{"style":163},[2698],{"type":28,"value":2699},".",{"type":23,"tag":135,"props":2701,"children":2702},{"style":1239},[2703],{"type":28,"value":2704},"MqttClient",{"type":23,"tag":135,"props":2706,"children":2707},{"style":163},[2708],{"type":28,"value":2174},{"type":23,"tag":135,"props":2710,"children":2711},{"style":1447},[2712],{"type":28,"value":2713},"reg",{"type":23,"tag":135,"props":2715,"children":2716},{"style":820},[2717],{"type":28,"value":1455},{"type":23,"tag":135,"props":2719,"children":2720},{"style":1239},[2721],{"type":28,"value":1432},{"type":23,"tag":135,"props":2723,"children":2724},{"style":163},[2725],{"type":28,"value":2726},")",{"type":23,"tag":135,"props":2728,"children":2729},{"style":820},[2730],{"type":28,"value":1455},{"type":23,"tag":135,"props":2732,"children":2733},{"style":173},[2734],{"type":28,"value":2735}," void",{"type":23,"tag":135,"props":2737,"children":2738},{"style":163},[2739],{"type":28,"value":1441},{"type":23,"tag":135,"props":2741,"children":2742},{"class":137,"line":169},[2743,2747,2752,2756],{"type":23,"tag":135,"props":2744,"children":2745},{"style":820},[2746],{"type":28,"value":2131},{"type":23,"tag":135,"props":2748,"children":2749},{"style":173},[2750],{"type":28,"value":2751}," config",{"type":23,"tag":135,"props":2753,"children":2754},{"style":820},[2755],{"type":28,"value":1231},{"type":23,"tag":135,"props":2757,"children":2758},{"style":163},[2759],{"type":28,"value":1441},{"type":23,"tag":135,"props":2761,"children":2762},{"class":137,"line":195},[2763,2768,2773,2777,2782,2788,2792,2797,2801,2806],{"type":23,"tag":135,"props":2764,"children":2765},{"style":163},[2766],{"type":28,"value":2767},"    name: reg.name.",{"type":23,"tag":135,"props":2769,"children":2770},{"style":1239},[2771],{"type":28,"value":2772},"replace",{"type":23,"tag":135,"props":2774,"children":2775},{"style":163},[2776],{"type":28,"value":1270},{"type":23,"tag":135,"props":2778,"children":2779},{"style":184},[2780],{"type":28,"value":2781},"/",{"type":23,"tag":135,"props":2783,"children":2785},{"style":2784},"--shiki-default:#DBEDFF",[2786],{"type":28,"value":2787},"_",{"type":23,"tag":135,"props":2789,"children":2790},{"style":184},[2791],{"type":28,"value":2781},{"type":23,"tag":135,"props":2793,"children":2794},{"style":820},[2795],{"type":28,"value":2796},"g",{"type":23,"tag":135,"props":2798,"children":2799},{"style":163},[2800],{"type":28,"value":2174},{"type":23,"tag":135,"props":2802,"children":2803},{"style":184},[2804],{"type":28,"value":2805},"\" \"",{"type":23,"tag":135,"props":2807,"children":2808},{"style":163},[2809],{"type":28,"value":2810},"),\n",{"type":23,"tag":135,"props":2812,"children":2813},{"class":137,"line":217},[2814,2819,2824,2828,2832,2837,2842],{"type":23,"tag":135,"props":2815,"children":2816},{"style":163},[2817],{"type":28,"value":2818},"    state_topic: ",{"type":23,"tag":135,"props":2820,"children":2821},{"style":184},[2822],{"type":28,"value":2823},"`solar/${",{"type":23,"tag":135,"props":2825,"children":2826},{"style":163},[2827],{"type":28,"value":2713},{"type":23,"tag":135,"props":2829,"children":2830},{"style":184},[2831],{"type":28,"value":2699},{"type":23,"tag":135,"props":2833,"children":2834},{"style":163},[2835],{"type":28,"value":2836},"name",{"type":23,"tag":135,"props":2838,"children":2839},{"style":184},[2840],{"type":28,"value":2841},"}`",{"type":23,"tag":135,"props":2843,"children":2844},{"style":163},[2845],{"type":28,"value":192},{"type":23,"tag":135,"props":2847,"children":2848},{"class":137,"line":239},[2849],{"type":23,"tag":135,"props":2850,"children":2851},{"style":163},[2852],{"type":28,"value":2853},"    unit_of_measurement: reg.unit,\n",{"type":23,"tag":135,"props":2855,"children":2856},{"class":137,"line":261},[2857],{"type":23,"tag":135,"props":2858,"children":2859},{"style":163},[2860],{"type":28,"value":2861},"    device_class: reg.deviceClass,\n",{"type":23,"tag":135,"props":2863,"children":2864},{"class":137,"line":283},[2865],{"type":23,"tag":135,"props":2866,"children":2867},{"style":163},[2868],{"type":28,"value":2869},"    state_class: reg.stateClass,\n",{"type":23,"tag":135,"props":2871,"children":2872},{"class":137,"line":305},[2873,2878,2883,2887,2891,2895,2899],{"type":23,"tag":135,"props":2874,"children":2875},{"style":163},[2876],{"type":28,"value":2877},"    unique_id: ",{"type":23,"tag":135,"props":2879,"children":2880},{"style":184},[2881],{"type":28,"value":2882},"`sph5048_${",{"type":23,"tag":135,"props":2884,"children":2885},{"style":163},[2886],{"type":28,"value":2713},{"type":23,"tag":135,"props":2888,"children":2889},{"style":184},[2890],{"type":28,"value":2699},{"type":23,"tag":135,"props":2892,"children":2893},{"style":163},[2894],{"type":28,"value":2836},{"type":23,"tag":135,"props":2896,"children":2897},{"style":184},[2898],{"type":28,"value":2841},{"type":23,"tag":135,"props":2900,"children":2901},{"style":163},[2902],{"type":28,"value":192},{"type":23,"tag":135,"props":2904,"children":2905},{"class":137,"line":319},[2906],{"type":23,"tag":135,"props":2907,"children":2908},{"style":163},[2909],{"type":28,"value":2910},"    device: {\n",{"type":23,"tag":135,"props":2912,"children":2913},{"class":137,"line":343},[2914,2919,2923],{"type":23,"tag":135,"props":2915,"children":2916},{"style":163},[2917],{"type":28,"value":2918},"      identifiers: [",{"type":23,"tag":135,"props":2920,"children":2921},{"style":184},[2922],{"type":28,"value":335},{"type":23,"tag":135,"props":2924,"children":2925},{"style":163},[2926],{"type":28,"value":340},{"type":23,"tag":135,"props":2928,"children":2929},{"class":137,"line":361},[2930,2935,2940],{"type":23,"tag":135,"props":2931,"children":2932},{"style":163},[2933],{"type":28,"value":2934},"      name: ",{"type":23,"tag":135,"props":2936,"children":2937},{"style":184},[2938],{"type":28,"value":2939},"\"Solar Inverter\"",{"type":23,"tag":135,"props":2941,"children":2942},{"style":163},[2943],{"type":28,"value":192},{"type":23,"tag":135,"props":2945,"children":2946},{"class":137,"line":370},[2947,2952,2957],{"type":23,"tag":135,"props":2948,"children":2949},{"style":163},[2950],{"type":28,"value":2951},"      model: ",{"type":23,"tag":135,"props":2953,"children":2954},{"style":184},[2955],{"type":28,"value":2956},"\"SPH5048\"",{"type":23,"tag":135,"props":2958,"children":2959},{"style":163},[2960],{"type":28,"value":192},{"type":23,"tag":135,"props":2962,"children":2963},{"class":137,"line":1743},[2964,2969,2974],{"type":23,"tag":135,"props":2965,"children":2966},{"style":163},[2967],{"type":28,"value":2968},"      manufacturer: ",{"type":23,"tag":135,"props":2970,"children":2971},{"style":184},[2972],{"type":28,"value":2973},"\"Sungoldpower\"",{"type":23,"tag":135,"props":2975,"children":2976},{"style":163},[2977],{"type":28,"value":192},{"type":23,"tag":135,"props":2979,"children":2980},{"class":137,"line":1803},[2981],{"type":23,"tag":135,"props":2982,"children":2983},{"style":163},[2984],{"type":28,"value":2985},"    },\n",{"type":23,"tag":135,"props":2987,"children":2988},{"class":137,"line":1862},[2989],{"type":23,"tag":135,"props":2990,"children":2991},{"style":163},[2992],{"type":28,"value":2993},"  };\n",{"type":23,"tag":135,"props":2995,"children":2996},{"class":137,"line":1920},[2997],{"type":23,"tag":135,"props":2998,"children":2999},{"emptyLinePlaceholder":1210},[3000],{"type":28,"value":1213},{"type":23,"tag":135,"props":3002,"children":3003},{"class":137,"line":1982},[3004,3009,3014],{"type":23,"tag":135,"props":3005,"children":3006},{"style":163},[3007],{"type":28,"value":3008},"  mqttClient.",{"type":23,"tag":135,"props":3010,"children":3011},{"style":1239},[3012],{"type":28,"value":3013},"publish",{"type":23,"tag":135,"props":3015,"children":3016},{"style":163},[3017],{"type":28,"value":3018},"(\n",{"type":23,"tag":135,"props":3020,"children":3021},{"class":137,"line":1991},[3022,3027,3031,3035,3039,3044],{"type":23,"tag":135,"props":3023,"children":3024},{"style":184},[3025],{"type":28,"value":3026},"    `homeassistant/sensor/sph5048/${",{"type":23,"tag":135,"props":3028,"children":3029},{"style":163},[3030],{"type":28,"value":2713},{"type":23,"tag":135,"props":3032,"children":3033},{"style":184},[3034],{"type":28,"value":2699},{"type":23,"tag":135,"props":3036,"children":3037},{"style":163},[3038],{"type":28,"value":2836},{"type":23,"tag":135,"props":3040,"children":3041},{"style":184},[3042],{"type":28,"value":3043},"}/config`",{"type":23,"tag":135,"props":3045,"children":3046},{"style":163},[3047],{"type":28,"value":192},{"type":23,"tag":135,"props":3049,"children":3051},{"class":137,"line":3050},19,[3052,3057,3061,3066],{"type":23,"tag":135,"props":3053,"children":3054},{"style":173},[3055],{"type":28,"value":3056},"    JSON",{"type":23,"tag":135,"props":3058,"children":3059},{"style":163},[3060],{"type":28,"value":2699},{"type":23,"tag":135,"props":3062,"children":3063},{"style":1239},[3064],{"type":28,"value":3065},"stringify",{"type":23,"tag":135,"props":3067,"children":3068},{"style":163},[3069],{"type":28,"value":3070},"(config),\n",{"type":23,"tag":135,"props":3072,"children":3074},{"class":137,"line":3073},20,[3075,3080,3085],{"type":23,"tag":135,"props":3076,"children":3077},{"style":163},[3078],{"type":28,"value":3079},"    { retain: ",{"type":23,"tag":135,"props":3081,"children":3082},{"style":173},[3083],{"type":28,"value":3084},"true",{"type":23,"tag":135,"props":3086,"children":3087},{"style":163},[3088],{"type":28,"value":3089}," }\n",{"type":23,"tag":135,"props":3091,"children":3093},{"class":137,"line":3092},21,[3094],{"type":23,"tag":135,"props":3095,"children":3096},{"style":163},[3097],{"type":28,"value":3098},"  );\n",{"type":23,"tag":135,"props":3100,"children":3102},{"class":137,"line":3101},22,[3103],{"type":23,"tag":135,"props":3104,"children":3105},{"style":163},[3106],{"type":28,"value":376},{"type":23,"tag":24,"props":3108,"children":3109},{},[3110],{"type":28,"value":3111},"When Home Assistant sees these discovery messages, it creates all 30+ sensors automatically under a \"Solar Inverter\" device. No YAML config files. No manual entity setup. They just appear.",{"type":23,"tag":24,"props":3113,"children":3114},{},[3115,3117,3123],{"type":28,"value":3116},"Adding a new register to the ",{"type":23,"tag":131,"props":3118,"children":3120},{"className":3119},[],[3121],{"type":28,"value":3122},"REGISTERS",{"type":28,"value":3124}," array automatically adds a new sensor in Home Assistant on the next container restart. Removing a register removes it. The definition is the source of truth.",{"type":23,"tag":36,"props":3126,"children":3128},{"id":3127},"energy-tracking-with-trapezoidal-integration",[3129],{"type":28,"value":3130},"Energy Tracking With Trapezoidal Integration",{"type":23,"tag":24,"props":3132,"children":3133},{},[3134,3136,3142],{"type":28,"value":3135},"The original stack had no energy tracking. It stored power values (watts) but never accumulated them into energy values (kWh). That meant I couldn't use Home Assistant's Energy Dashboard, which needs ",{"type":23,"tag":131,"props":3137,"children":3139},{"className":3138},[],[3140],{"type":28,"value":3141},"total_increasing",{"type":28,"value":3143}," sensors with kWh units.",{"type":23,"tag":24,"props":3145,"children":3146},{},[3147],{"type":28,"value":3148},"The rebuild adds software energy accumulators. Every poll cycle, the poller calculates the energy added since the last poll using the trapezoidal rule: average the current and previous power readings, multiply by the elapsed time interval.",{"type":23,"tag":125,"props":3150,"children":3152},{"code":3151,"language":1051,"meta":8,"className":1147,"style":8},"class EnergyAccumulator {\n  private totalKwh: number;\n  private lastPowerW: number | null;\n  private lastTs: number | null;\n\n  constructor(initialKwh = 0) {\n    this.totalKwh = initialKwh;\n    this.lastPowerW = null;\n    this.lastTs = null;\n  }\n\n  update(powerW: number, nowMs: number): number {\n    if (this.lastPowerW !== null && this.lastTs !== null) {\n      const dtHours = (nowMs - this.lastTs) / 3_600_000;\n      const avgW = (powerW + this.lastPowerW) / 2;\n      this.totalKwh += (avgW * dtHours) / 1000;\n    }\n    this.lastPowerW = powerW;\n    this.lastTs = nowMs;\n    return this.totalKwh;\n  }\n\n  get value(): number {\n    return this.totalKwh;\n  }\n}\n",[3153],{"type":23,"tag":131,"props":3154,"children":3155},{"__ignoreMap":8},[3156,3173,3198,3232,3264,3271,3301,3323,3347,3371,3378,3385,3443,3498,3546,3593,3638,3645,3665,3685,3702,3709,3716,3747,3763,3771],{"type":23,"tag":135,"props":3157,"children":3158},{"class":137,"line":138},[3159,3164,3169],{"type":23,"tag":135,"props":3160,"children":3161},{"style":820},[3162],{"type":28,"value":3163},"class",{"type":23,"tag":135,"props":3165,"children":3166},{"style":1239},[3167],{"type":28,"value":3168}," EnergyAccumulator",{"type":23,"tag":135,"props":3170,"children":3171},{"style":163},[3172],{"type":28,"value":1441},{"type":23,"tag":135,"props":3174,"children":3175},{"class":137,"line":169},[3176,3181,3186,3190,3194],{"type":23,"tag":135,"props":3177,"children":3178},{"style":820},[3179],{"type":28,"value":3180},"  private",{"type":23,"tag":135,"props":3182,"children":3183},{"style":1447},[3184],{"type":28,"value":3185}," totalKwh",{"type":23,"tag":135,"props":3187,"children":3188},{"style":820},[3189],{"type":28,"value":1455},{"type":23,"tag":135,"props":3191,"children":3192},{"style":173},[3193],{"type":28,"value":1460},{"type":23,"tag":135,"props":3195,"children":3196},{"style":163},[3197],{"type":28,"value":1179},{"type":23,"tag":135,"props":3199,"children":3200},{"class":137,"line":195},[3201,3205,3210,3214,3218,3223,3228],{"type":23,"tag":135,"props":3202,"children":3203},{"style":820},[3204],{"type":28,"value":3180},{"type":23,"tag":135,"props":3206,"children":3207},{"style":1447},[3208],{"type":28,"value":3209}," lastPowerW",{"type":23,"tag":135,"props":3211,"children":3212},{"style":820},[3213],{"type":28,"value":1455},{"type":23,"tag":135,"props":3215,"children":3216},{"style":173},[3217],{"type":28,"value":1460},{"type":23,"tag":135,"props":3219,"children":3220},{"style":820},[3221],{"type":28,"value":3222}," |",{"type":23,"tag":135,"props":3224,"children":3225},{"style":173},[3226],{"type":28,"value":3227}," null",{"type":23,"tag":135,"props":3229,"children":3230},{"style":163},[3231],{"type":28,"value":1179},{"type":23,"tag":135,"props":3233,"children":3234},{"class":137,"line":217},[3235,3239,3244,3248,3252,3256,3260],{"type":23,"tag":135,"props":3236,"children":3237},{"style":820},[3238],{"type":28,"value":3180},{"type":23,"tag":135,"props":3240,"children":3241},{"style":1447},[3242],{"type":28,"value":3243}," lastTs",{"type":23,"tag":135,"props":3245,"children":3246},{"style":820},[3247],{"type":28,"value":1455},{"type":23,"tag":135,"props":3249,"children":3250},{"style":173},[3251],{"type":28,"value":1460},{"type":23,"tag":135,"props":3253,"children":3254},{"style":820},[3255],{"type":28,"value":3222},{"type":23,"tag":135,"props":3257,"children":3258},{"style":173},[3259],{"type":28,"value":3227},{"type":23,"tag":135,"props":3261,"children":3262},{"style":163},[3263],{"type":28,"value":1179},{"type":23,"tag":135,"props":3265,"children":3266},{"class":137,"line":239},[3267],{"type":23,"tag":135,"props":3268,"children":3269},{"emptyLinePlaceholder":1210},[3270],{"type":28,"value":1213},{"type":23,"tag":135,"props":3272,"children":3273},{"class":137,"line":261},[3274,3279,3283,3288,3292,3297],{"type":23,"tag":135,"props":3275,"children":3276},{"style":820},[3277],{"type":28,"value":3278},"  constructor",{"type":23,"tag":135,"props":3280,"children":3281},{"style":163},[3282],{"type":28,"value":1270},{"type":23,"tag":135,"props":3284,"children":3285},{"style":1447},[3286],{"type":28,"value":3287},"initialKwh",{"type":23,"tag":135,"props":3289,"children":3290},{"style":820},[3291],{"type":28,"value":1231},{"type":23,"tag":135,"props":3293,"children":3294},{"style":173},[3295],{"type":28,"value":3296}," 0",{"type":23,"tag":135,"props":3298,"children":3299},{"style":163},[3300],{"type":28,"value":2404},{"type":23,"tag":135,"props":3302,"children":3303},{"class":137,"line":283},[3304,3309,3314,3318],{"type":23,"tag":135,"props":3305,"children":3306},{"style":173},[3307],{"type":28,"value":3308},"    this",{"type":23,"tag":135,"props":3310,"children":3311},{"style":163},[3312],{"type":28,"value":3313},".totalKwh ",{"type":23,"tag":135,"props":3315,"children":3316},{"style":820},[3317],{"type":28,"value":823},{"type":23,"tag":135,"props":3319,"children":3320},{"style":163},[3321],{"type":28,"value":3322}," initialKwh;\n",{"type":23,"tag":135,"props":3324,"children":3325},{"class":137,"line":305},[3326,3330,3335,3339,3343],{"type":23,"tag":135,"props":3327,"children":3328},{"style":173},[3329],{"type":28,"value":3308},{"type":23,"tag":135,"props":3331,"children":3332},{"style":163},[3333],{"type":28,"value":3334},".lastPowerW ",{"type":23,"tag":135,"props":3336,"children":3337},{"style":820},[3338],{"type":28,"value":823},{"type":23,"tag":135,"props":3340,"children":3341},{"style":173},[3342],{"type":28,"value":3227},{"type":23,"tag":135,"props":3344,"children":3345},{"style":163},[3346],{"type":28,"value":1179},{"type":23,"tag":135,"props":3348,"children":3349},{"class":137,"line":319},[3350,3354,3359,3363,3367],{"type":23,"tag":135,"props":3351,"children":3352},{"style":173},[3353],{"type":28,"value":3308},{"type":23,"tag":135,"props":3355,"children":3356},{"style":163},[3357],{"type":28,"value":3358},".lastTs ",{"type":23,"tag":135,"props":3360,"children":3361},{"style":820},[3362],{"type":28,"value":823},{"type":23,"tag":135,"props":3364,"children":3365},{"style":173},[3366],{"type":28,"value":3227},{"type":23,"tag":135,"props":3368,"children":3369},{"style":163},[3370],{"type":28,"value":1179},{"type":23,"tag":135,"props":3372,"children":3373},{"class":137,"line":343},[3374],{"type":23,"tag":135,"props":3375,"children":3376},{"style":163},[3377],{"type":28,"value":367},{"type":23,"tag":135,"props":3379,"children":3380},{"class":137,"line":361},[3381],{"type":23,"tag":135,"props":3382,"children":3383},{"emptyLinePlaceholder":1210},[3384],{"type":28,"value":1213},{"type":23,"tag":135,"props":3386,"children":3387},{"class":137,"line":370},[3388,3393,3397,3402,3406,3410,3414,3419,3423,3427,3431,3435,3439],{"type":23,"tag":135,"props":3389,"children":3390},{"style":1239},[3391],{"type":28,"value":3392},"  update",{"type":23,"tag":135,"props":3394,"children":3395},{"style":163},[3396],{"type":28,"value":1270},{"type":23,"tag":135,"props":3398,"children":3399},{"style":1447},[3400],{"type":28,"value":3401},"powerW",{"type":23,"tag":135,"props":3403,"children":3404},{"style":820},[3405],{"type":28,"value":1455},{"type":23,"tag":135,"props":3407,"children":3408},{"style":173},[3409],{"type":28,"value":1460},{"type":23,"tag":135,"props":3411,"children":3412},{"style":163},[3413],{"type":28,"value":2174},{"type":23,"tag":135,"props":3415,"children":3416},{"style":1447},[3417],{"type":28,"value":3418},"nowMs",{"type":23,"tag":135,"props":3420,"children":3421},{"style":820},[3422],{"type":28,"value":1455},{"type":23,"tag":135,"props":3424,"children":3425},{"style":173},[3426],{"type":28,"value":1460},{"type":23,"tag":135,"props":3428,"children":3429},{"style":163},[3430],{"type":28,"value":2726},{"type":23,"tag":135,"props":3432,"children":3433},{"style":820},[3434],{"type":28,"value":1455},{"type":23,"tag":135,"props":3436,"children":3437},{"style":173},[3438],{"type":28,"value":1460},{"type":23,"tag":135,"props":3440,"children":3441},{"style":163},[3442],{"type":28,"value":1441},{"type":23,"tag":135,"props":3444,"children":3445},{"class":137,"line":1743},[3446,3450,3454,3459,3463,3468,3472,3477,3482,3486,3490,3494],{"type":23,"tag":135,"props":3447,"children":3448},{"style":820},[3449],{"type":28,"value":2412},{"type":23,"tag":135,"props":3451,"children":3452},{"style":163},[3453],{"type":28,"value":2350},{"type":23,"tag":135,"props":3455,"children":3456},{"style":173},[3457],{"type":28,"value":3458},"this",{"type":23,"tag":135,"props":3460,"children":3461},{"style":163},[3462],{"type":28,"value":3334},{"type":23,"tag":135,"props":3464,"children":3465},{"style":820},[3466],{"type":28,"value":3467},"!==",{"type":23,"tag":135,"props":3469,"children":3470},{"style":173},[3471],{"type":28,"value":3227},{"type":23,"tag":135,"props":3473,"children":3474},{"style":820},[3475],{"type":28,"value":3476}," &&",{"type":23,"tag":135,"props":3478,"children":3479},{"style":173},[3480],{"type":28,"value":3481}," this",{"type":23,"tag":135,"props":3483,"children":3484},{"style":163},[3485],{"type":28,"value":3358},{"type":23,"tag":135,"props":3487,"children":3488},{"style":820},[3489],{"type":28,"value":3467},{"type":23,"tag":135,"props":3491,"children":3492},{"style":173},[3493],{"type":28,"value":3227},{"type":23,"tag":135,"props":3495,"children":3496},{"style":163},[3497],{"type":28,"value":2404},{"type":23,"tag":135,"props":3499,"children":3500},{"class":137,"line":1803},[3501,3506,3511,3515,3520,3524,3528,3533,3537,3542],{"type":23,"tag":135,"props":3502,"children":3503},{"style":820},[3504],{"type":28,"value":3505},"      const",{"type":23,"tag":135,"props":3507,"children":3508},{"style":173},[3509],{"type":28,"value":3510}," dtHours",{"type":23,"tag":135,"props":3512,"children":3513},{"style":820},[3514],{"type":28,"value":1231},{"type":23,"tag":135,"props":3516,"children":3517},{"style":163},[3518],{"type":28,"value":3519}," (nowMs ",{"type":23,"tag":135,"props":3521,"children":3522},{"style":820},[3523],{"type":28,"value":2199},{"type":23,"tag":135,"props":3525,"children":3526},{"style":173},[3527],{"type":28,"value":3481},{"type":23,"tag":135,"props":3529,"children":3530},{"style":163},[3531],{"type":28,"value":3532},".lastTs) ",{"type":23,"tag":135,"props":3534,"children":3535},{"style":820},[3536],{"type":28,"value":2781},{"type":23,"tag":135,"props":3538,"children":3539},{"style":173},[3540],{"type":28,"value":3541}," 3_600_000",{"type":23,"tag":135,"props":3543,"children":3544},{"style":163},[3545],{"type":28,"value":1179},{"type":23,"tag":135,"props":3547,"children":3548},{"class":137,"line":1862},[3549,3553,3558,3562,3567,3571,3575,3580,3584,3589],{"type":23,"tag":135,"props":3550,"children":3551},{"style":820},[3552],{"type":28,"value":3505},{"type":23,"tag":135,"props":3554,"children":3555},{"style":173},[3556],{"type":28,"value":3557}," avgW",{"type":23,"tag":135,"props":3559,"children":3560},{"style":820},[3561],{"type":28,"value":1231},{"type":23,"tag":135,"props":3563,"children":3564},{"style":163},[3565],{"type":28,"value":3566}," (powerW ",{"type":23,"tag":135,"props":3568,"children":3569},{"style":820},[3570],{"type":28,"value":2445},{"type":23,"tag":135,"props":3572,"children":3573},{"style":173},[3574],{"type":28,"value":3481},{"type":23,"tag":135,"props":3576,"children":3577},{"style":163},[3578],{"type":28,"value":3579},".lastPowerW) ",{"type":23,"tag":135,"props":3581,"children":3582},{"style":820},[3583],{"type":28,"value":2781},{"type":23,"tag":135,"props":3585,"children":3586},{"style":173},[3587],{"type":28,"value":3588}," 2",{"type":23,"tag":135,"props":3590,"children":3591},{"style":163},[3592],{"type":28,"value":1179},{"type":23,"tag":135,"props":3594,"children":3595},{"class":137,"line":1920},[3596,3601,3605,3610,3615,3620,3625,3629,3634],{"type":23,"tag":135,"props":3597,"children":3598},{"style":173},[3599],{"type":28,"value":3600},"      this",{"type":23,"tag":135,"props":3602,"children":3603},{"style":163},[3604],{"type":28,"value":3313},{"type":23,"tag":135,"props":3606,"children":3607},{"style":820},[3608],{"type":28,"value":3609},"+=",{"type":23,"tag":135,"props":3611,"children":3612},{"style":163},[3613],{"type":28,"value":3614}," (avgW ",{"type":23,"tag":135,"props":3616,"children":3617},{"style":820},[3618],{"type":28,"value":3619},"*",{"type":23,"tag":135,"props":3621,"children":3622},{"style":163},[3623],{"type":28,"value":3624}," dtHours) ",{"type":23,"tag":135,"props":3626,"children":3627},{"style":820},[3628],{"type":28,"value":2781},{"type":23,"tag":135,"props":3630,"children":3631},{"style":173},[3632],{"type":28,"value":3633}," 1000",{"type":23,"tag":135,"props":3635,"children":3636},{"style":163},[3637],{"type":28,"value":1179},{"type":23,"tag":135,"props":3639,"children":3640},{"class":137,"line":1982},[3641],{"type":23,"tag":135,"props":3642,"children":3643},{"style":163},[3644],{"type":28,"value":2548},{"type":23,"tag":135,"props":3646,"children":3647},{"class":137,"line":1991},[3648,3652,3656,3660],{"type":23,"tag":135,"props":3649,"children":3650},{"style":173},[3651],{"type":28,"value":3308},{"type":23,"tag":135,"props":3653,"children":3654},{"style":163},[3655],{"type":28,"value":3334},{"type":23,"tag":135,"props":3657,"children":3658},{"style":820},[3659],{"type":28,"value":823},{"type":23,"tag":135,"props":3661,"children":3662},{"style":163},[3663],{"type":28,"value":3664}," powerW;\n",{"type":23,"tag":135,"props":3666,"children":3667},{"class":137,"line":3050},[3668,3672,3676,3680],{"type":23,"tag":135,"props":3669,"children":3670},{"style":173},[3671],{"type":28,"value":3308},{"type":23,"tag":135,"props":3673,"children":3674},{"style":163},[3675],{"type":28,"value":3358},{"type":23,"tag":135,"props":3677,"children":3678},{"style":820},[3679],{"type":28,"value":823},{"type":23,"tag":135,"props":3681,"children":3682},{"style":163},[3683],{"type":28,"value":3684}," nowMs;\n",{"type":23,"tag":135,"props":3686,"children":3687},{"class":137,"line":3073},[3688,3693,3697],{"type":23,"tag":135,"props":3689,"children":3690},{"style":820},[3691],{"type":28,"value":3692},"    return",{"type":23,"tag":135,"props":3694,"children":3695},{"style":173},[3696],{"type":28,"value":3481},{"type":23,"tag":135,"props":3698,"children":3699},{"style":163},[3700],{"type":28,"value":3701},".totalKwh;\n",{"type":23,"tag":135,"props":3703,"children":3704},{"class":137,"line":3092},[3705],{"type":23,"tag":135,"props":3706,"children":3707},{"style":163},[3708],{"type":28,"value":367},{"type":23,"tag":135,"props":3710,"children":3711},{"class":137,"line":3101},[3712],{"type":23,"tag":135,"props":3713,"children":3714},{"emptyLinePlaceholder":1210},[3715],{"type":28,"value":1213},{"type":23,"tag":135,"props":3717,"children":3719},{"class":137,"line":3718},23,[3720,3725,3730,3735,3739,3743],{"type":23,"tag":135,"props":3721,"children":3722},{"style":820},[3723],{"type":28,"value":3724},"  get",{"type":23,"tag":135,"props":3726,"children":3727},{"style":1239},[3728],{"type":28,"value":3729}," value",{"type":23,"tag":135,"props":3731,"children":3732},{"style":163},[3733],{"type":28,"value":3734},"()",{"type":23,"tag":135,"props":3736,"children":3737},{"style":820},[3738],{"type":28,"value":1455},{"type":23,"tag":135,"props":3740,"children":3741},{"style":173},[3742],{"type":28,"value":1460},{"type":23,"tag":135,"props":3744,"children":3745},{"style":163},[3746],{"type":28,"value":1441},{"type":23,"tag":135,"props":3748,"children":3750},{"class":137,"line":3749},24,[3751,3755,3759],{"type":23,"tag":135,"props":3752,"children":3753},{"style":820},[3754],{"type":28,"value":3692},{"type":23,"tag":135,"props":3756,"children":3757},{"style":173},[3758],{"type":28,"value":3481},{"type":23,"tag":135,"props":3760,"children":3761},{"style":163},[3762],{"type":28,"value":3701},{"type":23,"tag":135,"props":3764,"children":3766},{"class":137,"line":3765},25,[3767],{"type":23,"tag":135,"props":3768,"children":3769},{"style":163},[3770],{"type":28,"value":367},{"type":23,"tag":135,"props":3772,"children":3774},{"class":137,"line":3773},26,[3775],{"type":23,"tag":135,"props":3776,"children":3777},{"style":163},[3778],{"type":28,"value":376},{"type":23,"tag":24,"props":3780,"children":3781},{},[3782],{"type":28,"value":3783},"Accumulators run for: solar generation (PV1 power), load consumption, grid import, and grid export. On container restart, the poller queries TimescaleDB for the current day's accumulated values and restores the accumulators from there. Daily totals survive reboots.",{"type":23,"tag":24,"props":3785,"children":3786},{},[3787,3789,3794],{"type":28,"value":3788},"These publish as ",{"type":23,"tag":131,"props":3790,"children":3792},{"className":3791},[],[3793],{"type":28,"value":3141},{"type":28,"value":3795}," energy sensors, which Home Assistant's Energy Dashboard understands natively. I get daily, weekly, and monthly energy breakdowns with no custom charting code at all.",{"type":23,"tag":36,"props":3797,"children":3799},{"id":3798},"timescaledb-continuous-aggregates-and-retention",[3800],{"type":28,"value":3801},"TimescaleDB: Continuous Aggregates and Retention",{"type":23,"tag":24,"props":3803,"children":3804},{},[3805,3807,3813],{"type":28,"value":3806},"The schema is the same basic approach as before, ",{"type":23,"tag":131,"props":3808,"children":3810},{"className":3809},[],[3811],{"type":28,"value":3812},"(timestamp, key, value)",{"type":28,"value":3814}," rows in a hypertable. The difference is continuous aggregates.",{"type":23,"tag":24,"props":3816,"children":3817},{},[3818],{"type":28,"value":3819},"TimescaleDB can maintain pre-computed rollups that stay current automatically:",{"type":23,"tag":125,"props":3821,"children":3823},{"code":3822,"language":582,"meta":8,"className":580,"style":8},"CREATE MATERIALIZED VIEW inverter_hourly\nWITH (timescaledb.continuous) AS\nSELECT\n  time_bucket('1 hour', ts) AS bucket,\n  key,\n  avg(value)  AS avg_val,\n  min(value)  AS min_val,\n  max(value)  AS max_val\nFROM inverter_metrics\nGROUP BY bucket, key;\n\nSELECT add_continuous_aggregate_policy('inverter_hourly',\n  start_offset => INTERVAL '3 hours',\n  end_offset   => INTERVAL '1 hour',\n  schedule_interval => INTERVAL '1 hour'\n);\n",[3824],{"type":23,"tag":131,"props":3825,"children":3826},{"__ignoreMap":8},[3827,3835,3843,3851,3859,3867,3875,3883,3891,3898,3906,3913,3921,3929,3937,3945],{"type":23,"tag":135,"props":3828,"children":3829},{"class":137,"line":138},[3830],{"type":23,"tag":135,"props":3831,"children":3832},{},[3833],{"type":28,"value":3834},"CREATE MATERIALIZED VIEW inverter_hourly\n",{"type":23,"tag":135,"props":3836,"children":3837},{"class":137,"line":169},[3838],{"type":23,"tag":135,"props":3839,"children":3840},{},[3841],{"type":28,"value":3842},"WITH (timescaledb.continuous) AS\n",{"type":23,"tag":135,"props":3844,"children":3845},{"class":137,"line":195},[3846],{"type":23,"tag":135,"props":3847,"children":3848},{},[3849],{"type":28,"value":3850},"SELECT\n",{"type":23,"tag":135,"props":3852,"children":3853},{"class":137,"line":217},[3854],{"type":23,"tag":135,"props":3855,"children":3856},{},[3857],{"type":28,"value":3858},"  time_bucket('1 hour', ts) AS bucket,\n",{"type":23,"tag":135,"props":3860,"children":3861},{"class":137,"line":239},[3862],{"type":23,"tag":135,"props":3863,"children":3864},{},[3865],{"type":28,"value":3866},"  key,\n",{"type":23,"tag":135,"props":3868,"children":3869},{"class":137,"line":261},[3870],{"type":23,"tag":135,"props":3871,"children":3872},{},[3873],{"type":28,"value":3874},"  avg(value)  AS avg_val,\n",{"type":23,"tag":135,"props":3876,"children":3877},{"class":137,"line":283},[3878],{"type":23,"tag":135,"props":3879,"children":3880},{},[3881],{"type":28,"value":3882},"  min(value)  AS min_val,\n",{"type":23,"tag":135,"props":3884,"children":3885},{"class":137,"line":305},[3886],{"type":23,"tag":135,"props":3887,"children":3888},{},[3889],{"type":28,"value":3890},"  max(value)  AS max_val\n",{"type":23,"tag":135,"props":3892,"children":3893},{"class":137,"line":319},[3894],{"type":23,"tag":135,"props":3895,"children":3896},{},[3897],{"type":28,"value":610},{"type":23,"tag":135,"props":3899,"children":3900},{"class":137,"line":343},[3901],{"type":23,"tag":135,"props":3902,"children":3903},{},[3904],{"type":28,"value":3905},"GROUP BY bucket, key;\n",{"type":23,"tag":135,"props":3907,"children":3908},{"class":137,"line":361},[3909],{"type":23,"tag":135,"props":3910,"children":3911},{"emptyLinePlaceholder":1210},[3912],{"type":28,"value":1213},{"type":23,"tag":135,"props":3914,"children":3915},{"class":137,"line":370},[3916],{"type":23,"tag":135,"props":3917,"children":3918},{},[3919],{"type":28,"value":3920},"SELECT add_continuous_aggregate_policy('inverter_hourly',\n",{"type":23,"tag":135,"props":3922,"children":3923},{"class":137,"line":1743},[3924],{"type":23,"tag":135,"props":3925,"children":3926},{},[3927],{"type":28,"value":3928},"  start_offset => INTERVAL '3 hours',\n",{"type":23,"tag":135,"props":3930,"children":3931},{"class":137,"line":1803},[3932],{"type":23,"tag":135,"props":3933,"children":3934},{},[3935],{"type":28,"value":3936},"  end_offset   => INTERVAL '1 hour',\n",{"type":23,"tag":135,"props":3938,"children":3939},{"class":137,"line":1862},[3940],{"type":23,"tag":135,"props":3941,"children":3942},{},[3943],{"type":28,"value":3944},"  schedule_interval => INTERVAL '1 hour'\n",{"type":23,"tag":135,"props":3946,"children":3947},{"class":137,"line":1920},[3948],{"type":23,"tag":135,"props":3949,"children":3950},{},[3951],{"type":28,"value":1382},{"type":23,"tag":24,"props":3953,"children":3954},{},[3955,3957,3963],{"type":28,"value":3956},"Daily aggregates use ",{"type":23,"tag":131,"props":3958,"children":3960},{"className":3959},[],[3961],{"type":28,"value":3962},"time_bucket_gapfill",{"type":28,"value":3964}," with timezone offset so buckets align to local midnight rather than UTC midnight. This matters when you want to show \"today's solar yield\" and you're not on UTC.",{"type":23,"tag":24,"props":3966,"children":3967},{},[3968],{"type":28,"value":3969},"Raw data has a 30-day retention policy. The continuous aggregates keep hourly and daily summaries indefinitely. This keeps the database small while preserving the data that actually gets queried.",{"type":23,"tag":36,"props":3971,"children":3973},{"id":3972},"the-full-stack-in-docker-compose",[3974],{"type":28,"value":3975},"The Full Stack in Docker Compose",{"type":23,"tag":24,"props":3977,"children":3978},{},[3979],{"type":28,"value":3980},"Everything runs in a single Compose file:",{"type":23,"tag":125,"props":3982,"children":3984},{"code":3983,"language":454,"meta":8,"className":452,"style":8},"services:\n  mosquitto:\n    image: eclipse-mosquitto:2\n    volumes:\n      - ./mosquitto/config:/mosquitto/config\n      - mosquitto-data:/mosquitto/data\n    ports:\n      - \"1883:1883\"\n\n  timescaledb:\n    image: timescale/timescaledb:latest-pg16\n    environment:\n      POSTGRES_DB: solar\n      POSTGRES_USER: solar\n      POSTGRES_PASSWORD: ${DB_PASSWORD}\n    volumes:\n      - tsdb-data:/var/lib/postgresql/data\n      - ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql\n\n  poller:\n    build: ./poller\n    depends_on:\n      - mosquitto\n      - timescaledb\n    environment:\n      MQTT_HOST: mosquitto\n      DB_HOST: timescaledb\n      DB_PASSWORD: ${DB_PASSWORD}\n      TZ: ${TZ}\n    devices:\n      - /dev/ttyUSB0:/dev/ttyUSB0\n    restart: unless-stopped\n\nvolumes:\n  mosquitto-data:\n  tsdb-data:\n",[3985],{"type":23,"tag":131,"props":3986,"children":3987},{"__ignoreMap":8},[3988,3999,4011,4027,4039,4052,4064,4076,4088,4095,4106,4121,4132,4147,4162,4177,4188,4200,4212,4219,4231,4248,4260,4272,4284,4295,4311,4328,4345,4361,4374,4387,4405,4413,4426,4439],{"type":23,"tag":135,"props":3989,"children":3990},{"class":137,"line":138},[3991,3995],{"type":23,"tag":135,"props":3992,"children":3993},{"style":464},[3994],{"type":28,"value":467},{"type":23,"tag":135,"props":3996,"children":3997},{"style":163},[3998],{"type":28,"value":472},{"type":23,"tag":135,"props":4000,"children":4001},{"class":137,"line":169},[4002,4007],{"type":23,"tag":135,"props":4003,"children":4004},{"style":464},[4005],{"type":28,"value":4006},"  mosquitto",{"type":23,"tag":135,"props":4008,"children":4009},{"style":163},[4010],{"type":28,"value":472},{"type":23,"tag":135,"props":4012,"children":4013},{"class":137,"line":195},[4014,4018,4022],{"type":23,"tag":135,"props":4015,"children":4016},{"style":464},[4017],{"type":28,"value":492},{"type":23,"tag":135,"props":4019,"children":4020},{"style":163},[4021],{"type":28,"value":181},{"type":23,"tag":135,"props":4023,"children":4024},{"style":184},[4025],{"type":28,"value":4026},"eclipse-mosquitto:2\n",{"type":23,"tag":135,"props":4028,"children":4029},{"class":137,"line":217},[4030,4035],{"type":23,"tag":135,"props":4031,"children":4032},{"style":464},[4033],{"type":28,"value":4034},"    volumes",{"type":23,"tag":135,"props":4036,"children":4037},{"style":163},[4038],{"type":28,"value":472},{"type":23,"tag":135,"props":4040,"children":4041},{"class":137,"line":239},[4042,4047],{"type":23,"tag":135,"props":4043,"children":4044},{"style":163},[4045],{"type":28,"value":4046},"      - ",{"type":23,"tag":135,"props":4048,"children":4049},{"style":184},[4050],{"type":28,"value":4051},"./mosquitto/config:/mosquitto/config\n",{"type":23,"tag":135,"props":4053,"children":4054},{"class":137,"line":261},[4055,4059],{"type":23,"tag":135,"props":4056,"children":4057},{"style":163},[4058],{"type":28,"value":4046},{"type":23,"tag":135,"props":4060,"children":4061},{"style":184},[4062],{"type":28,"value":4063},"mosquitto-data:/mosquitto/data\n",{"type":23,"tag":135,"props":4065,"children":4066},{"class":137,"line":283},[4067,4072],{"type":23,"tag":135,"props":4068,"children":4069},{"style":464},[4070],{"type":28,"value":4071},"    ports",{"type":23,"tag":135,"props":4073,"children":4074},{"style":163},[4075],{"type":28,"value":472},{"type":23,"tag":135,"props":4077,"children":4078},{"class":137,"line":305},[4079,4083],{"type":23,"tag":135,"props":4080,"children":4081},{"style":163},[4082],{"type":28,"value":4046},{"type":23,"tag":135,"props":4084,"children":4085},{"style":184},[4086],{"type":28,"value":4087},"\"1883:1883\"\n",{"type":23,"tag":135,"props":4089,"children":4090},{"class":137,"line":319},[4091],{"type":23,"tag":135,"props":4092,"children":4093},{"emptyLinePlaceholder":1210},[4094],{"type":28,"value":1213},{"type":23,"tag":135,"props":4096,"children":4097},{"class":137,"line":343},[4098,4102],{"type":23,"tag":135,"props":4099,"children":4100},{"style":464},[4101],{"type":28,"value":696},{"type":23,"tag":135,"props":4103,"children":4104},{"style":163},[4105],{"type":28,"value":472},{"type":23,"tag":135,"props":4107,"children":4108},{"class":137,"line":361},[4109,4113,4117],{"type":23,"tag":135,"props":4110,"children":4111},{"style":464},[4112],{"type":28,"value":492},{"type":23,"tag":135,"props":4114,"children":4115},{"style":163},[4116],{"type":28,"value":181},{"type":23,"tag":135,"props":4118,"children":4119},{"style":184},[4120],{"type":28,"value":716},{"type":23,"tag":135,"props":4122,"children":4123},{"class":137,"line":370},[4124,4128],{"type":23,"tag":135,"props":4125,"children":4126},{"style":464},[4127],{"type":28,"value":509},{"type":23,"tag":135,"props":4129,"children":4130},{"style":163},[4131],{"type":28,"value":472},{"type":23,"tag":135,"props":4133,"children":4134},{"class":137,"line":1743},[4135,4139,4143],{"type":23,"tag":135,"props":4136,"children":4137},{"style":464},[4138],{"type":28,"value":751},{"type":23,"tag":135,"props":4140,"children":4141},{"style":163},[4142],{"type":28,"value":181},{"type":23,"tag":135,"props":4144,"children":4145},{"style":184},[4146],{"type":28,"value":760},{"type":23,"tag":135,"props":4148,"children":4149},{"class":137,"line":1803},[4150,4154,4158],{"type":23,"tag":135,"props":4151,"children":4152},{"style":464},[4153],{"type":28,"value":768},{"type":23,"tag":135,"props":4155,"children":4156},{"style":163},[4157],{"type":28,"value":181},{"type":23,"tag":135,"props":4159,"children":4160},{"style":184},[4161],{"type":28,"value":760},{"type":23,"tag":135,"props":4163,"children":4164},{"class":137,"line":1862},[4165,4169,4173],{"type":23,"tag":135,"props":4166,"children":4167},{"style":464},[4168],{"type":28,"value":784},{"type":23,"tag":135,"props":4170,"children":4171},{"style":163},[4172],{"type":28,"value":181},{"type":23,"tag":135,"props":4174,"children":4175},{"style":184},[4176],{"type":28,"value":793},{"type":23,"tag":135,"props":4178,"children":4179},{"class":137,"line":1920},[4180,4184],{"type":23,"tag":135,"props":4181,"children":4182},{"style":464},[4183],{"type":28,"value":4034},{"type":23,"tag":135,"props":4185,"children":4186},{"style":163},[4187],{"type":28,"value":472},{"type":23,"tag":135,"props":4189,"children":4190},{"class":137,"line":1982},[4191,4195],{"type":23,"tag":135,"props":4192,"children":4193},{"style":163},[4194],{"type":28,"value":4046},{"type":23,"tag":135,"props":4196,"children":4197},{"style":184},[4198],{"type":28,"value":4199},"tsdb-data:/var/lib/postgresql/data\n",{"type":23,"tag":135,"props":4201,"children":4202},{"class":137,"line":1991},[4203,4207],{"type":23,"tag":135,"props":4204,"children":4205},{"style":163},[4206],{"type":28,"value":4046},{"type":23,"tag":135,"props":4208,"children":4209},{"style":184},[4210],{"type":28,"value":4211},"./sql/init.sql:/docker-entrypoint-initdb.d/init.sql\n",{"type":23,"tag":135,"props":4213,"children":4214},{"class":137,"line":3050},[4215],{"type":23,"tag":135,"props":4216,"children":4217},{"emptyLinePlaceholder":1210},[4218],{"type":28,"value":1213},{"type":23,"tag":135,"props":4220,"children":4221},{"class":137,"line":3073},[4222,4227],{"type":23,"tag":135,"props":4223,"children":4224},{"style":464},[4225],{"type":28,"value":4226},"  poller",{"type":23,"tag":135,"props":4228,"children":4229},{"style":163},[4230],{"type":28,"value":472},{"type":23,"tag":135,"props":4232,"children":4233},{"class":137,"line":3092},[4234,4239,4243],{"type":23,"tag":135,"props":4235,"children":4236},{"style":464},[4237],{"type":28,"value":4238},"    build",{"type":23,"tag":135,"props":4240,"children":4241},{"style":163},[4242],{"type":28,"value":181},{"type":23,"tag":135,"props":4244,"children":4245},{"style":184},[4246],{"type":28,"value":4247},"./poller\n",{"type":23,"tag":135,"props":4249,"children":4250},{"class":137,"line":3101},[4251,4256],{"type":23,"tag":135,"props":4252,"children":4253},{"style":464},[4254],{"type":28,"value":4255},"    depends_on",{"type":23,"tag":135,"props":4257,"children":4258},{"style":163},[4259],{"type":28,"value":472},{"type":23,"tag":135,"props":4261,"children":4262},{"class":137,"line":3718},[4263,4267],{"type":23,"tag":135,"props":4264,"children":4265},{"style":163},[4266],{"type":28,"value":4046},{"type":23,"tag":135,"props":4268,"children":4269},{"style":184},[4270],{"type":28,"value":4271},"mosquitto\n",{"type":23,"tag":135,"props":4273,"children":4274},{"class":137,"line":3749},[4275,4279],{"type":23,"tag":135,"props":4276,"children":4277},{"style":163},[4278],{"type":28,"value":4046},{"type":23,"tag":135,"props":4280,"children":4281},{"style":184},[4282],{"type":28,"value":4283},"timescaledb\n",{"type":23,"tag":135,"props":4285,"children":4286},{"class":137,"line":3765},[4287,4291],{"type":23,"tag":135,"props":4288,"children":4289},{"style":464},[4290],{"type":28,"value":509},{"type":23,"tag":135,"props":4292,"children":4293},{"style":163},[4294],{"type":28,"value":472},{"type":23,"tag":135,"props":4296,"children":4297},{"class":137,"line":3773},[4298,4303,4307],{"type":23,"tag":135,"props":4299,"children":4300},{"style":464},[4301],{"type":28,"value":4302},"      MQTT_HOST",{"type":23,"tag":135,"props":4304,"children":4305},{"style":163},[4306],{"type":28,"value":181},{"type":23,"tag":135,"props":4308,"children":4309},{"style":184},[4310],{"type":28,"value":4271},{"type":23,"tag":135,"props":4312,"children":4314},{"class":137,"line":4313},27,[4315,4320,4324],{"type":23,"tag":135,"props":4316,"children":4317},{"style":464},[4318],{"type":28,"value":4319},"      DB_HOST",{"type":23,"tag":135,"props":4321,"children":4322},{"style":163},[4323],{"type":28,"value":181},{"type":23,"tag":135,"props":4325,"children":4326},{"style":184},[4327],{"type":28,"value":4283},{"type":23,"tag":135,"props":4329,"children":4331},{"class":137,"line":4330},28,[4332,4337,4341],{"type":23,"tag":135,"props":4333,"children":4334},{"style":464},[4335],{"type":28,"value":4336},"      DB_PASSWORD",{"type":23,"tag":135,"props":4338,"children":4339},{"style":163},[4340],{"type":28,"value":181},{"type":23,"tag":135,"props":4342,"children":4343},{"style":184},[4344],{"type":28,"value":793},{"type":23,"tag":135,"props":4346,"children":4348},{"class":137,"line":4347},29,[4349,4353,4357],{"type":23,"tag":135,"props":4350,"children":4351},{"style":464},[4352],{"type":28,"value":521},{"type":23,"tag":135,"props":4354,"children":4355},{"style":163},[4356],{"type":28,"value":181},{"type":23,"tag":135,"props":4358,"children":4359},{"style":184},[4360],{"type":28,"value":743},{"type":23,"tag":135,"props":4362,"children":4364},{"class":137,"line":4363},30,[4365,4370],{"type":23,"tag":135,"props":4366,"children":4367},{"style":464},[4368],{"type":28,"value":4369},"    devices",{"type":23,"tag":135,"props":4371,"children":4372},{"style":163},[4373],{"type":28,"value":472},{"type":23,"tag":135,"props":4375,"children":4377},{"class":137,"line":4376},31,[4378,4382],{"type":23,"tag":135,"props":4379,"children":4380},{"style":163},[4381],{"type":28,"value":4046},{"type":23,"tag":135,"props":4383,"children":4384},{"style":184},[4385],{"type":28,"value":4386},"/dev/ttyUSB0:/dev/ttyUSB0\n",{"type":23,"tag":135,"props":4388,"children":4390},{"class":137,"line":4389},32,[4391,4396,4400],{"type":23,"tag":135,"props":4392,"children":4393},{"style":464},[4394],{"type":28,"value":4395},"    restart",{"type":23,"tag":135,"props":4397,"children":4398},{"style":163},[4399],{"type":28,"value":181},{"type":23,"tag":135,"props":4401,"children":4402},{"style":184},[4403],{"type":28,"value":4404},"unless-stopped\n",{"type":23,"tag":135,"props":4406,"children":4408},{"class":137,"line":4407},33,[4409],{"type":23,"tag":135,"props":4410,"children":4411},{"emptyLinePlaceholder":1210},[4412],{"type":28,"value":1213},{"type":23,"tag":135,"props":4414,"children":4416},{"class":137,"line":4415},34,[4417,4422],{"type":23,"tag":135,"props":4418,"children":4419},{"style":464},[4420],{"type":28,"value":4421},"volumes",{"type":23,"tag":135,"props":4423,"children":4424},{"style":163},[4425],{"type":28,"value":472},{"type":23,"tag":135,"props":4427,"children":4429},{"class":137,"line":4428},35,[4430,4435],{"type":23,"tag":135,"props":4431,"children":4432},{"style":464},[4433],{"type":28,"value":4434},"  mosquitto-data",{"type":23,"tag":135,"props":4436,"children":4437},{"style":163},[4438],{"type":28,"value":472},{"type":23,"tag":135,"props":4440,"children":4442},{"class":137,"line":4441},36,[4443,4448],{"type":23,"tag":135,"props":4444,"children":4445},{"style":464},[4446],{"type":28,"value":4447},"  tsdb-data",{"type":23,"tag":135,"props":4449,"children":4450},{"style":163},[4451],{"type":28,"value":472},{"type":23,"tag":24,"props":4453,"children":4454},{},[4455,4457,4462],{"type":28,"value":4456},"A ",{"type":23,"tag":131,"props":4458,"children":4460},{"className":4459},[],[4461],{"type":28,"value":644},{"type":28,"value":4463}," file carries the timezone and any secrets. The whole stack rebuilds from scratch in under a minute on a fresh machine.",{"type":23,"tag":24,"props":4465,"children":4466},{},[4467,4469,4474],{"type":28,"value":4468},"The Mosquitto broker is also shared with other Docker Compose stacks on the same host via an external Docker network. Solar metrics, mining stats, and general homelab monitoring all flow through one broker. Any service that wants solar data subscribes to ",{"type":23,"tag":131,"props":4470,"children":4472},{"className":4471},[],[4473],{"type":28,"value":392},{"type":28,"value":4475},". The poller has no idea who's listening.",{"type":23,"tag":36,"props":4477,"children":4479},{"id":4478},"what-got-better",[4480],{"type":28,"value":4481},"What Got Better",{"type":23,"tag":24,"props":4483,"children":4484},{},[4485,4491],{"type":23,"tag":4486,"props":4487,"children":4488},"strong",{},[4489],{"type":28,"value":4490},"No more custom dashboard.",{"type":28,"value":4492}," The Home Assistant Energy Dashboard gives daily and monthly breakdowns out of the box. Lovelace cards give me live gauges and power flow visualization. All of it is maintained by the HA community, not by me.",{"type":23,"tag":24,"props":4494,"children":4495},{},[4496,4501,4503,4508],{"type":23,"tag":4486,"props":4497,"children":4498},{},[4499],{"type":28,"value":4500},"Adding a metric takes three lines.",{"type":28,"value":4502}," Drop a new entry in the ",{"type":23,"tag":131,"props":4504,"children":4506},{"className":4505},[],[4507],{"type":28,"value":3122},{"type":28,"value":4509}," array with the address, name, scale, and unit. TypeScript compilation catches mistakes. The sensor appears in Home Assistant on the next deploy.",{"type":23,"tag":24,"props":4511,"children":4512},{},[4513,4518,4520,4526],{"type":23,"tag":4486,"props":4514,"children":4515},{},[4516],{"type":28,"value":4517},"The whole stack fits in a repository.",{"type":28,"value":4519}," ",{"type":23,"tag":131,"props":4521,"children":4523},{"className":4522},[],[4524],{"type":28,"value":4525},"docker compose up -d",{"type":28,"value":4527}," on a new machine and everything is back. That lesson cost me twice before I learned it.",{"type":23,"tag":24,"props":4529,"children":4530},{},[4531,4536],{"type":23,"tag":4486,"props":4532,"children":4533},{},[4534],{"type":28,"value":4535},"Energy tracking works.",{"type":28,"value":4537}," The trapezoidal accumulators and TimescaleDB continuous aggregates give me accurate daily kWh numbers without writing any aggregation code in the application layer.",{"type":23,"tag":36,"props":4539,"children":4541},{"id":4540},"what-i-learned",[4542],{"type":28,"value":4543},"What I Learned",{"type":23,"tag":24,"props":4545,"children":4546},{},[4547],{"type":28,"value":4548},"The biggest lesson isn't about MQTT or TypeScript. It's that a custom dashboard is a liability, not just an asset. Building it was satisfying. Maintaining it was a cost I was paying every time I wanted to change anything. Handing that responsibility to Home Assistant removed the biggest maintenance surface from the whole stack.",{"type":23,"tag":24,"props":4550,"children":4551},{},[4552],{"type":28,"value":4553},"MQTT as an integration layer is genuinely more flexible than a custom REST API. Anything can subscribe. Multiple consumers can get the same data without the poller knowing about them. New integrations (future me wants InfluxDB, apparently) just subscribe to the existing topics.",{"type":23,"tag":24,"props":4555,"children":4556},{},[4557],{"type":28,"value":4558},"TimescaleDB continuous aggregates are one of the more underrated features in any database I've used. I write 5-second raw data and hourly and daily rollups maintain themselves. No cron jobs, no application-level aggregation, no stale numbers if the poller restarts.",{"type":23,"tag":24,"props":4560,"children":4561},{},[4562],{"type":28,"value":4563},"And the thing that should have been obvious: push your code to a repository. Not someday. Before you deploy it.",{"type":23,"tag":1069,"props":4565,"children":4566},{},[],{"type":23,"tag":24,"props":4568,"children":4569},{},[4570],{"type":28,"value":4571},"The solar setup is running the new stack right now. If you want to build something similar, the architecture is straightforward. Modbus RTU over USB, 5-second polling, MQTT for distribution, Home Assistant for visualization, TimescaleDB for history. None of it requires specialized hardware or expensive software.",{"type":23,"tag":24,"props":4573,"children":4574},{},[4575],{"type":28,"value":4576},"If you have the same inverter or a similar Modbus-speaking one, drop a comment. The register mapping is the hardest part, and the more documentation exists in public, the less time anyone spends reverse-engineering the same spec.",{"type":23,"tag":1027,"props":4578,"children":4579},{},[4580],{"type":28,"value":1031},{"title":8,"searchDepth":169,"depth":169,"links":4582},[4583,4584,4587,4588,4589,4590,4591,4592,4593],{"id":1104,"depth":169,"text":1107},{"id":1120,"depth":169,"text":1123,"children":4585},[4586],{"id":2006,"depth":195,"text":2009},{"id":2615,"depth":169,"text":2618},{"id":2644,"depth":169,"text":2647},{"id":3127,"depth":169,"text":3130},{"id":3798,"depth":169,"text":3801},{"id":3972,"depth":169,"text":3975},{"id":4478,"depth":169,"text":4481},{"id":4540,"depth":169,"text":4543},"content:blog:solar-monitoring-part-2-the-typescript-rebuild.md","blog/solar-monitoring-part-2-the-typescript-rebuild.md","blog/solar-monitoring-part-2-the-typescript-rebuild",1774200455342]