0、添加按钮
配置-设备与服务-辅助元素-创建辅助元素-按钮
1、查看正在运行的容器
docker ps
2、进入bash
docker exec -it <容器名/容器ID> bash
3、编辑configuration.yaml,推荐按功能创建多个.yaml,在configuration.yaml中include
3.1、编辑 vi shell_commands.yaml 增加一个远程的服务,本次是调用一个远程的开关灯服务。
#将声明一个btnpress_cesuo的服务
btnpress_cesuo: curl http://ip:port/cesuo
3.2、编辑 vi automations.yaml 给按钮添加自动化动作,当按钮按下,调用btnpress_cesuo服务
- alias: "cesuo"
trigger:
- platform: state
entity_id: 按钮名称
action:
- service: shell_command.btnpress_cesuo
data:
message: "厕所按钮按下"
3.3确保configuration.yaml都include了shell_commands.yaml和automations.yaml
automation: !include automations.yaml
shell_command: !include shell_commands.yaml
4、在HomeAssistant 开发者工具-YAML配置-检查配置-重新启动
5、在HomeAssistant 概览-编辑仪表盘-添加卡片-按实体-找到按钮并添加。测试按下效果。
ps:单纯调用服务或许使用CommandLine更简单,但不符合本次需求。 Command Line - Home Assistant