第一步:编辑homeassistant的configuration.yaml,直接在末尾添加

rest_command:
  wechat_bot_send:
    url: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx"

# 上面的XXXX请打开企业微信群右上角三个点,找到“消息推送”获取连接

# 注意:只有企业微信内部群才有“消息推送”功能
    method: POST
    headers:
      Content-Type: application/json
    payload: >
      {
        "msgtype": "text",
        "text": {
          "content": "{{ message }}"
        }
      }

第二步:编辑homeassistant的scripts.yaml

wechat_bot_send:
  alias: "企业微信推送"
  description: "发送消息到企业微信群机器人"
  fields:
    title:
      name: "标题"
      description: "消息标题"
      required: true
      example: "设备状态提醒"
      selector:
        text:
    message:
      name: "内容"
      description: "消息正文"
      required: true
      example: "客厅灯已打开"
      selector:
        text:
          multiline: true
  sequence:
    - service: rest_command.wechat_bot_send
      data:
        message: >-
          【{{ title }}】
          {{ message }}

第三步:重启HA。

这样就能在HA里的自动化处理里直接使用了,如下图:

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐