← 返回首页

Home Assistant 通用PushPlus推送脚本搭建

发布时间:2026-10-12

需求

不想每个自动化写死标题、消息内容。编写一个通用脚本,自动化调用时传入标题与消息内容,统一走PushPlus推送。

核心思路

使用 script 脚本,接收变量 title、message,调用REST notify服务推送到微信。 自动化只需要调用脚本并传入参数,解耦推送渠道和告警逻辑。

配置步骤

1. configuration.yaml 增加 notify 配置

notify:
  - platform: rest
    name: pushplus_notify
    resource: https://www.pushplus.plus/send
    method: POST
    headers:
      Content-Type: application/json
    payload: >-
      {
        "token": "你的pushplus token",
        "title": "{{ title }}",
        "content": "{{ message }}",
        "template": "html"
      }

2. 通用脚本 script.yaml

pushplus_send:
  fields:
    title:
      description: 消息标题
      example: 主机离线告警
    message:
      description: 消息正文
      example: 服务器主机网络离线
  sequence:
    - service: notify.pushplus_notify
      data:
        title: "{{ title }}"
        message: "{{ message }}"

3. 自动化调用示例

action:
  - service: script.pushplus_send
    data:
      title: "主机离线告警"
      message: "监控主机 {{ trigger.to_state.name }} 网络离线"

优势