You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现提前15分钟向Google Home Mini广播祷告时间并预调度一年任务?

解决方案

Google Home 广播实现

放弃IFTTT/Zapier,直接通过代码调用Google Cast协议发送广播,最简便的方式是用Python第三方库googlehomepush:

  • 安装:pip install googlehomepush
  • 核心代码:
from googlehomepush import GoogleHome

# 替换为你的Google Home Mini的设备名或局域网IP
device = GoogleHome("Google Home Mini")
device.say("祷告时间即将到来,请做好准备")
  • 注意:脚本运行环境需与设备在同一局域网;若需远程触发,需通过VPN或端口转发打通网络。

如果需要更复杂的交互,也可以使用Google Assistant SDK,但配置流程繁琐,googlehomepush完全满足广播需求。

无服务器全年调度实现

要一次性拉取全年祷告时间并完成所有通知调度,无需持续运行服务器,推荐用云调度+云函数的组合:

1. 拉取并处理全年祷告时间

调用目标API获取全年数据,生成每个祷告时间提前15分钟的触发时间:

import requests
from datetime import datetime, timedelta

def fetch_prayer_times(target_year):
    # 替换为实际祷告时间API的地址和参数
    resp = requests.get(f"https://api.example.com/prayer-times?year={target_year}")
    prayer_data = resp.json()
    trigger_times = []
    for entry in prayer_data:
        prayer_dt = datetime.strptime(entry["datetime"], "%Y-%m-%d %H:%M:%S")
        trigger_dt = prayer_dt - timedelta(minutes=15)
        # 转换为云调度支持的UTC时间格式(以Google Cloud为例)
        trigger_times.append(trigger_dt.strftime("%Y-%m-%dT%H:%M:%SZ"))
    return trigger_times

2. 批量创建云调度任务

以Google Cloud为例,步骤如下:

  • 编写Cloud Function:将广播代码封装成HTTP触发的云函数,接收请求后执行广播逻辑。
  • 批量创建调度任务:用gcloud命令行工具批量生成定时任务,每个任务对应一个触发时间,触发目标为你的Cloud Function:
# 假设trigger_times.txt每行是一个UTC格式的触发时间
while read trigger_time; do
  gcloud scheduler jobs create http prayer-reminder-${trigger_time//[:T]/} \
    --schedule="$trigger_time" \
    --uri="https://us-central1-your-project-id.cloudfunctions.net/send-prayer-alert" \
    --http-method=POST
done < trigger_times.txt

其他云服务商(如AWS Lambda+CloudWatch Events、阿里云函数计算+事件总线)逻辑一致,均可批量创建定时无服务器任务。

替代方案:GitHub Actions 调度

若不想使用云服务商,可借助GitHub Actions的定时触发器。但需注意:GitHub Actions的调度精度为分钟级,且单个仓库最多支持约100个定时任务,若全年祷告时间过多,可改为创建每日任务,触发时处理当天所有的祷告提醒。

注意事项

  • 提前确认祷告时间API的调用频率限制,避免触发限流。
  • 云调度任务的费用极低,主流云服务商的免费额度完全覆盖一年的需求。
  • 若Google Home设备IP动态变化,优先使用设备名称自动发现(依赖局域网mDNS服务)。

内容的提问来源于stack exchange,提问作者Amri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 17:48:15