I wrote an API client for my water-cooled bed
I wrote an API client for my water-cooled bed
我为我的水冷床垫编写了一个 API 客户端
Posted on July 18, 2026 发布于 2026 年 7 月 18 日
Table of Contents: Sleep, Chilipad, Why this device, Construction, API, A note about the Postman examples, Endpoints, Device control, API Client, Sleeping on it. 目录: 睡眠、Chilipad、为什么选择这款设备、构建过程、API、关于 Postman 示例的说明、端点、设备控制、API 客户端、睡眠体验。
Now that I have your attention, let’s break that down a little bit. I recently purchased a Sleep.me Chilipad 2.0, which is a system that allows you to control the temperature of your bed using a thin, water-filled mattress topper that’s connected to a device that contains a pump, reservoir, and thermostat. It was $1700. Yes it’s ridiculous. I know. I make software engineer money, I’m single, I live alone, and I don’t have kids. Sue me. I’ll provide a serious, grown-up justification in just a second, but for now “la la la can’t hear you.” 既然我已经吸引了你的注意,让我们来拆解一下。我最近购买了 Sleep.me Chilipad 2.0,这是一个可以通过薄薄的注水床垫来控制床铺温度的系统,该床垫连接着一个包含水泵、储水箱和恒温器的设备。它花了 1700 美元。是的,这很荒谬。我知道。我拿着软件工程师的薪水,单身,独居,没有孩子。想告我就告吧。我稍后会给出一个严肃、成熟的理由,但现在请允许我“啦啦啦,我听不见”。
The idea is that it helps regulate your body temperature while you sleep if you have trouble doing it yourself, don’t have AC in your bedroom, etc. The device allows you to set desired temperatures throughout the night, put this on schedules that apply on certain days of the week, etc. The manufacturer also provides a developer API, so immediately there was no world in which I didn’t do some bullshittery with this. The result is a tool called bedctl2. I named it that way for two reasons: There’s a long history of “control” programs having names that end with -ctl. In my head bedctl is pronounced “bed cuttle”, which sounds like “bed cuddle”, which is cute.
这个系统的理念是,如果你在睡眠时难以调节体温,或者卧室没有空调等,它可以帮助你调节体温。该设备允许你设置整晚的期望温度,并为一周中的特定日子设定时间表等。制造商还提供了一个开发者 API,所以我立刻就决定要折腾一番。结果就是我开发了一个名为 bedctl2 的工具。我这样命名有两个原因:历史上有很多以 -ctl 结尾的“控制”程序;在我的脑海里,bedctl 读作“bed cuttle”,听起来像“bed cuddle”(床上的拥抱),这很可爱。
Sleep
睡眠
Our understanding of how the human body works is constantly evolving. This is good. However, between grifters on social media, biased research funded by industry, and the evolving understanding provided by science I mentioned earlier, you could sometimes reasonably convince yourself that there’s evidence to support the claim that juggling live salmon cures male pattern baldness. I have a PhD in physics. I built lasers that spit out 80 femtosecond pulses, and I did quantum mechanics simulations. I am so scarred by that experience that my default stance on science-related (which includes health) headlines and social media posts is “bullshit until proven otherwise”, where “proven” includes but is not limited to “corroborated by my doctor or a consensus of medical professionals.” 我们对人体运作方式的理解在不断演变。这是好事。然而,在社交媒体上的骗子、行业资助的偏见研究,以及我前面提到的科学界不断演变的认知之间,你有时甚至会合理地相信,有证据支持“抛接活鲑鱼可以治愈男性脱发”这种说法。我拥有物理学博士学位。我曾制造过能发射 80 飞秒脉冲的激光器,也做过量子力学模拟。那段经历让我深受“创伤”,以至于我对科学相关(包括健康)的头条新闻和社交媒体帖子的默认态度是“在证明之前都是胡扯”,其中“证明”包括但不限于“得到我的医生或医学专家共识的证实”。
And to be clear, that distrust is not distrust of science, it’s distrust that nuance has been stripped away to fit into a headline, essentially. I am not a doctor, and I’m very aware of that. One piece of knowledge I feel safe clinging to and saying out loud to the internet is that sleep is probably good for you. Everything seems to get better with sleep: your immune system, your cognitive function, recovery from physical activity, etc. Unfortunately, I’ve always had a complicated relationship with sleep. Namely because my neuro is divergent. 需要明确的是,这种不信任并非针对科学本身,而是针对那些为了迎合标题而剥离了细微差别的做法。我不是医生,我非常清楚这一点。有一条知识我可以放心地坚持并大声告诉互联网:睡眠对你有好处。一切似乎都会随着睡眠而改善:你的免疫系统、认知功能、体力恢复等。不幸的是,我与睡眠的关系一直很复杂。主要是因为我的神经是发散的(神经多样性)。
Neurodivergent people tend to be night owls as a survival/recovery mechanism. Having some time to ourselves where no one is placing demands on our attention, behavior, etc, gives us some space to exist as our actual selves, not our “capitalism demands that I perform on this schedule, in this manner, to these people, otherwise I can’t feed myself” selves. This means that our sleep routines can be either misaligned with our work schedules, or just irregular in general. If it’s not clear yet, I have ADHD. This means that my brain never shuts up. Like, ever. This is not conducive to “winding down for bed.” 神经多样性人群往往倾向于做“夜猫子”,这是一种生存/恢复机制。拥有一段属于自己的时间,没有人对我们的注意力、行为等提出要求,这给了我们空间去成为真实的自己,而不是那个“资本主义要求我按这个时间表、以这种方式、对这些人表现,否则我就无法养活自己”的自己。这意味着我们的睡眠习惯可能与工作时间表不一致,或者干脆就是不规律的。如果还没说清楚的话,我有 ADHD(多动症)。这意味着我的大脑从不停歇。真的,从来没有。这不利于“睡前放松”。
I developed a reading in bed routine from a pretty early age, which cuts down on distractions and acts as a signpost my nervous system can recognize as “ah, we typically fall asleep after doing this for a while, let’s start that process.” Luckily I was diagnosed with ADHD pretty young, and I’ve been medicated since childhood. For people that are diagnosed as adults, I see one of two reactions to starting ADHD medication: Holy shit, is this how normal people feel all the time? It’s so much quieter! Ah fuck, I’m autistic too. 我很早就养成了在床上阅读的习惯,这减少了干扰,并作为一个信号,让我的神经系统识别出:“啊,我们通常做完这个就会入睡,让我们开始这个过程吧。”幸运的是,我很早就被诊断出患有 ADHD,并且从小就开始服药。对于成年后才被诊断出的人,我看到他们开始服用 ADHD 药物时通常有两种反应:天哪,正常人一直都是这种感觉吗?安静多了!啊该死,我还是个自闭症患者。
If it’s not clear yet, I’m autistic. The overlap between autism and ADHD is pretty significant, and in many cases the ADHD is just masking the autism. That’s why some people go undiagnosed until they start medication. Not me though, I happen to be exceptionally good at burning mental energy in exchange for social skills. I was only diagnosed about two years ago, but there were signs. Many people with autism have sensory issues, as in certain textures or sensations are abnormally bothersome. Imagine the reaction that some people have to nails on a chalkboard, or the sound of someone chewing, etc, but getting that reaction to a texture, certain kinds of touch, etc. 如果还没说清楚的话,我是自闭症患者。自闭症和 ADHD 之间的重叠非常显著,在许多情况下,ADHD 只是掩盖了自闭症。这就是为什么有些人直到开始服药才被诊断出来。不过我不是,我恰好非常擅长消耗心理能量来换取社交技能。我大约两年前才被诊断出来,但早有迹象。许多自闭症患者有感官问题,即某些质地或感觉会异常令人烦恼。想象一下有些人对指甲刮黑板或咀嚼声的反应,但这种反应是针对某种质地或某种触觉的。
Similarly, many people with autism have trouble regulating their body temperature to the same degree as neurotypical people. When it comes to sleep, this means that I have trouble feeling comfortable unless the temperature is just right, the weight of the comforter/duvet is high enough, etc. I also just moved to Portland (the cool one, not the lobster one). This is one of the rare cities in the US where air conditioning isn’t a given. For most of the US this is like living in the stone age. I guess for a long time the climate was temperate enough that it wasn’t needed, but the climate is changing has changed. It now gets certifiably hot as fuck in Portland. 同样,许多自闭症患者在调节体温方面也难以达到神经典型人群的水平。在睡眠方面,这意味着除非温度恰到好处、被子的重量足够等,否则我很难感到舒适。我刚搬到波特兰(那个酷的波特兰,不是产龙虾的那个)。这是美国极少数空调不是标配的城市之一。对美国大部分地区来说,这简直就像生活在石器时代。我想长期以来气候足够温和,不需要空调,但气候正在改变,已经改变了。现在的波特兰热得要命。
My new apartment at least has a window unit, but it’s in the living room, not the bedroom. There’s also no ceiling fans. I also live in a high-rise, and heat rises. This means that my bedroom gets pretty stuffy at night. I bought temperature sensors to prove that my bedroom is the hottest room in the apartment and everything. So, to recap: Brain never shuts up, I have medical grade stimulants coursing through my veins, Me no likey stuffy bedroom, Not sleeping well is pretty bad for you, Please, PLEASE help me sleep better. That’s why I said fuck it and dropped RAM money on a temperature control system for my bed. Spoiler: it’s good. 我的新公寓至少有一个窗式空调,但它在客厅,不在卧室。也没有吊扇。我住在高层建筑里,热气上升。这意味着我的卧室晚上会变得非常闷热。我买了温度传感器来证明我的卧室是公寓里最热的房间。所以,总结一下:大脑不停歇,我有医用级兴奋剂在血管里流淌,我不喜欢闷热的卧室,睡眠不好对身体很糟糕,请,拜托帮我睡得更好。这就是为什么我决定豁出去了,花了一大笔钱买了一套床铺温度控制系统。剧透一下:效果很好。
Chilipad
Chilipad
Now we’ll talk about the device itself. Why this device: Naturally I did a bunch of research into the… 现在我们来谈谈设备本身。为什么选择这款设备:自然地,我做了一堆关于……的研究。