-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
通过通知来执行app操作或修改app配置
需要开启消息推送(APP设置->消息推送beta)
- 立即上报开启的传感器状态
action: notify.mobile_app_XXX
data:
message: command_update_sensors
- 立即上报当前位置(无论是否开启开关)
action: notify.mobile_app_XXX
data:
message: request_location_update
- 修改app配置
目前支持enableLocation(开关定位),locationAccuracyHigh(高精度定位),enableKeepLocation(持续定位),walk(步数),wifiSensor(wifi状态),ble(蓝牙状态),batterySensor(电池状态)
例子:
action: notify.mobile_app_XXX
metadata: {}
data:
message: smart_house_config
title: 修改SmartHouse配置 #可选,不设置不显示推送,但仍可以修改配置
data:
config:
enableLocation: true
enableKeepLocation: false
walk: false
ble: false
- 消息推送-文本
action: notify.mobile_app_XXX
data:
message: "已关闭所有设备"
title: "无人在家"
- 消息推送-图片(目前仅支持Android)
action: notify.mobile_app_XXX
data:
message: "展示图片"
title: "测试推送"
data:
push_img: >-
https://img1.mydrivers.com/img/20250424/04bd8013b5274377a77f0b8bbefe9f48.png
- 消息推送-URI操作
支持 entityId:实体id 打开设备
支持 callService:domain/service/service_data(json)/target(json) 执行服务(3.8.1版本)
支持 media-source://ha的media中的文件 打开HA内的视频和图片(比如:media-source://media_source/local/xxx,xxx是ha媒体中的目,如果HA接入了远程视频local改成对应的就可以)
支持 通用URI 比如网页,打开特定应用的界面/功能,拨号等等
ios每条push仅支持一个action,并且未经测试,不保证可以用
action: notify.mobile_app_XXX
data:
message: "URI打开设备页面"
title: "测试推送"
data:
actions:
- action: URI
uri: entityId:light.yeelight_ceil26_0x158027b8
title: 打开设备
- 消息推送-Action操作处理自动化-官方方式(仅支持Android)
actions:
- alias: 设置actionId
variables:
action_open: "{{ 'OPEN' ~ context.id }}"
action_close: "{{ 'CLOSE' ~ context.id }}"
- alias: 发送推送消息
data:
message: 检测到你已到小区并且气温过低,需要开启电暖器吗吗?
data:
actions:
- action: "{{ action_open }}"
title: 开启
- action: "{{ action_close }}"
title: 关闭
title: test
action: notify.mobile_app_22011211c_8ab4
- alias: 等待消息按钮点击
wait_for_trigger:
- event_type: mobile_app_notification_action
event_data:
action: "{{ action_open }}"
trigger: event
- event_type: mobile_app_notification_action
event_data:
action: "{{ action_close }}"
trigger: event
continue_on_timeout: true
- alias: 处理点击后的操作
choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_open }}"
sequence:
- data:
message: 电暖器已开启
action: notify.mobile_app_subsystem_for_androidtm_e0ad
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_close }}"
sequence:
- data:
message: 你选择了关闭
action: notify.mobile_app_subsystem_for_androidtm_e0ad
- 消息推送-Action操作处理自动化-SmartHouse特有方式(3.8.1版本后完整支持,3.8.0不支持target数据)
uri格式:callService:domain/service/service_data(json)/target(json),没有的不填(但/要有)
actions:
- alias: 发送推送消息
data:
message: 检测到你已到小区并且气温过低,需要开启电暖器吗吗?
data:
actions:
- action: URI
uri: 'callService:switch/turn_on//{"entity_id": "switch.living_room_diannuanqi"}'
title: 开启
title: test
action: notify.mobile_app_22011211c_8ab4
- 消息推送-复杂例子:推送米家摄像头/门铃事件图片和视频(需要依赖hass-xiaomi-miot)
通知中显示图片目前仅Android支持,点击打开视频ios,Androd都支持,但只测试了Android。ios下不保证可用
- 10.1 首先要实现龙佬的保存视频脚本(添加后记得重启):
# configuration.yaml
shell_command:
# other commands ...
save_xiaomi_video: |
bash -c '
mp4="{{ name|default('latest') }}.mp4"
dir="{{ dir|default('/media/camera',true) }}"
mkdir -p "$dir" && cd "$dir"
script=/config/custom_components/xiaomi_miot/scripts/save_xiaomi_video.sh
if [ -f "$script" ]; then
bash "$script" "{{ url }}" "$mp4"
else
ffmpeg -y -i "{{ url }}" -c copy "$mp4"
fi
ls *.mp4 | sort | head -n -{{ keep|default(100) }} | xargs rm -vf
if [ -n "{{ img }}" ]; then
curl -o "{{ name|default('latest') }}.jpg" "{{ img }}"
ls *.jpg | sort | head -n -{{ keep|default(100) }} | xargs rm -vf
fi
'
- 10.2 实现对应自动化(较新设备,并且不需要对触发场景自定义的话可以直接使用龙佬的蓝图)
alias: 推送按门铃图片
description: ""
triggers:
- trigger: state
entity_id:
# [hass-xiaomi-miot](https://github.com/al-one/hass-xiaomi-miot)中的米家通知实体
- sensor.mi_XXX_message
id: mihome_notify
- trigger: state
entity_id:
# 摄像头/门铃id
- camera.XXX
attribute: motion_video_time
id: new_photo
# 下面的是门打开时触发,根据需要自己加不加
- trigger: state
entity_id:
- event.lumi_cn_1011415348_mcn01_lock_opened_e_2_1
to: null
conditions: []
actions:
- variables:
# 你的haurl(需要外网可访问)
external_url: https://xxx
# 摄像头/门铃 info id
info_eid: button.isa_hldb6_7a66_info
# 摄像头/门铃id
camera_eid: camera.isa_hldb6_7a66_video_doorbell
# 摄像头/门铃视频存储目录
save_dir: /media/doorbell
- variables:
motion_video_type: >-
{{ state_attr(camera_eid,'motion_video_type')|regex_replace('[\s:-]','')
}}
motion_type: |-
{% set mapper = {
'PeopleMotion': '有人移动',
'ObjectMotion': '画面变动',
'Pass': '有人在门前经过',
'Bell': '有人按门铃',
'PassStay': '有人在门前停留',
'AI': '自动化触发'
} %} {{ mapper.get(motion_video_type, motion_video_type) }}
mp4_name: >-
{{ state_attr(camera_eid,'motion_video_time')|regex_replace('[\s:-]','')
}}-{{
state_attr(camera_eid,'motion_video_type')|regex_replace('[\s:-]','') }}
img_path: >-
{{ (external_url~state_attr(camera_eid,'entity_picture')) if
external_url else '' }}
- choose:
- conditions:
- condition: template
value_template: >-
{{ trigger.id == 'mihome_notify' and '智能门铃' in
trigger.to_state.state }}
sequence:
- action: homeassistant.update_entity
target:
entity_id: "{{ camera_eid }}"
# 根据自己需要该,我这边限制了只有门打开的情况下才会推送pass事件
- conditions:
- condition: trigger
id:
- new_photo
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.door_status
state: "on"
- condition: template
value_template: "{{ state_attr(camera_eid, 'motion_video_type') != 'Pass' }}"
sequence:
- action: shell_command.save_xiaomi_video
data:
dir: "{{ save_dir }}"
name: "{{ mp4_name }}"
img: "{{ img_path }}"
url: "{{ state_attr(camera_eid,'stream_address')}}"
response_variable: action_result
# 推送视频到SmartHouse
- action: notify.mobile_app_XXX
data:
message: "{{ state_attr(camera_eid,'motion_video_time') }}"
title: 门铃-{{ motion_type }}
data:
push_img: "{{ img_path }}"
actions:
- action: "{{ state_attr(camera_eid,'motion_video_time') }}"
# 此处根据前面的视频保存目录做对应的修改
uri: >-
media-source://media_source/local/doorbell/{{ mp4_name
}}.mp4
title: 查看视频
# 这是我的另一个企业微信推送插件的推送方式
- action: notify.wework
data:
message: "{{ state_attr(camera_eid,'motion_video_time') }}"
title: 门铃-{{ motion_type }}
data:
type: video
videopath: /media/doorbell/{{ mp4_name }}.mp4
mode: queued
max: 10
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation