在Stream Deck上运行Home Assistant:通过YAML(带有模板)配置并在Linux、MacOS和Windows上运行
项目描述
在Stream Deck上运行Home Assistant
通过YAML(带有模板)配置并在Linux、MacOS和Windows上运行
介绍:在Stream Deck上运行Home Assistant!
如果您使用Home Assistant并希望有一个无缝的控制方式,您就来到了正确的位置。使用这个Python脚本,您可以通过Stream Deck控制您的Home Assistant实例,使管理您的智能家居设备和场景变得前所未有的简单。
主要功能
- ✅ 易于使用
- 🛠️ 高度可定制
- 🧩 Home Assistant插件支持
- 🐧 支持 Linux, MacOS, 和 Windows
- 📁 YAML配置
- 🏠 在与Home Assistant相同的机器上运行
- 🚀 支持模板的高级定制
- 💤 自动同步
entity_id
状态以开启/关闭显示 - 🎛️(新!)Stream Deck Plus支持旋钮
[目录]
为什么选择我们的解决方案而不是其他方案?
您可能之前在Github上看到了一个类似的项目(cgiesche/streamdeck-homeassistant
)。然而,我们的解决方案更加灵活,允许您将Stream Deck连接到运行Home Assistant的同一Linux机器。原生的Stream Deck软件不支持Linux,但我们借助python-elgato-streamdeck
库来解决这个问题。如果您想寻找一些灵感,请查看下面的>20个按钮配置想法部分。
下面是视频演示!
https://user-images.githubusercontent.com/6897215/226788119-6c198ea6-2950-4f95-95dc-346c9e5b5cee.mp4
:books: 目录
🌟 分享您的成功
我喜欢收到用户的消息!如果您在项目中使用 Home Assistant StreamDeck YAML,请考虑在 GitHub 仓库 上提交一个问题,让我知道。您的反馈和成功故事不仅有助于改进库,还能激励社区中的其他人。通过分享您的经验,您可以为 Home Assistant StreamDeck YAML 的成长和发展做出贡献。我非常感谢您的支持!
:rocket: 入门指南
按照以下步骤在 Stream Deck 上启动 Home Assistant。
:house_with_garden: 作为 Home Assistant 插件安装
点击展开。
- 在您的 Home Assistant 实例中,导航到 Supervisor > 插件商店。
- 点击右上角的菜单图标(三个垂直点),然后选择 仓库。
- 添加以下仓库 URL:
https://github.com/basnijholt/home-assistant-streamdeck-yaml-addon
。 - 插件现在应出现在 插件商店 中。点击“Home Assistant Stream Deck YAML”,然后点击“安装”。
- 安装完成后,使用
.env
文件或单个配置选项配置插件(有关更多信息,请参阅 插件配置文档)。 - 启动插件并检查日志中是否有错误。
:whale: 使用 Docker 安装
点击展开。
- 编辑
.env.example
文件并将其重命名为.env
。 - 设置一个
configuration.yaml
文件(见下文)。 - 安装 Docker,请参阅 此页面 的说明
- 使用以下 Docker 镜像:
basnijholt/home-assistant-streamdeck-yaml:latest
docker run --rm -it --privileged --env-file=$(pwd)/.env -v $(pwd)/:/app/ basnijholt/home-assistant-streamdeck-yaml:latest
或者使用一个 docker-compose
文件,示例文件如下: docker-compose.yaml
可选地,您可以使用以下命令自行构建 Docker 镜像:
docker build -t basnijholt/home-assistant-streamdeck-yaml:latest .
:computer: 不使用 Docker 安装
点击展开 Linux :penguin]、:apple] MacOS 和 :desktop_computer] Windows 的常见步骤。
- 在仓库文件夹中运行
pip install -e .
以安装所需的依赖项。 - 编辑
.env.example
文件并将其重命名为.env
。 - 设置一个
configuration.yaml
文件(见下文)。 - 按照特定于平台的步骤进行操作 Linux、MacOS 或 Windows。
:penguin: Linux
点击展开。
在 Linux 上,您需要安装一些额外的依赖项
sudo apt-get update
sudo apt-get install -y libudev-dev libusb-1.0-0-dev libhidapi-libusb0 libffi-dev
并添加一个 udev 规则以允许访问 Stream Deck,运行 sudo nano /etc/udev/rules.d/99-streamdeck.rules
并添加以下行
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0fd9", GROUP="users", TAG+="uaccess"
:apple: MacOS
点击展开。
在 MacOS 上,您需要安装一些额外的依赖项
brew install hidapi cairo libffi
:desktop_computer: Windows
点击展开。
对于 Windows,请参阅 此页面。
:gear: 配置
- 在同一目录下创建一个
configuration.yaml
文件。 - 选择两种使用选项之一
- 选项 1:使用环境变量。(有关详细信息,请参阅
.env.example
) - 选项 2:使用命令行参数。(运行
home-assistant-streamdeck-yaml -h
以查看可用选项)
您已设置完毕!🎉
现在您可以轻松地控制您的智能家居设备了。查看 configuration.yaml
文件以获取示例配置或随时与社区分享您自己的配置。
享受控制吧!🏠💡🎮
:page_facing_up: configuration.yaml
以下是一个示例 configuration.yaml
文件以供参考
brightness: 100 # Default brightness of the Stream Deck (0-100)
state_entity_id: binary_sensor.anyone_home # Entity to sync display state with
auto_reload: true # Automatically reload the configuration file when it changes
pages:
- name: Home
buttons:
- entity_id: light.bedroom_lights
service: light.toggle
text: |
Bedroom
lights
- icon: netflix.png
service: script.start_spotify
- icon: xbox.png
service: script.start_xbox
- icon_mdi: restart
service: homeassistant.restart
text: |
Restart
HA
# Special light control page
- entity_id: light.living_room_lights
special_type: light-control
special_type_data:
colormap: hsv
text: |
Living room
lights
# Move pages
- special_type: previous-page
- special_type: next-page
- name: Example
buttons:
# Empty button
- special_type: empty
# Change pages
- special_type: go-to-page
special_type_data: Home
- special_type: go-to-page
special_type_data: 0
- special_type: previous-page
- special_type: next-page
- name: Other
buttons:
# Spotify playlist
- service_data:
id: playlist:37i9dQZF1DXaRycgyh6kXP
source: KEF LS50
icon: "spotify:playlist/37i9dQZF1DXaRycgyh6kXP" # Downloads the cover art
service: script.start_spotify
# (Advanced) Use templates!
- entity_id: media_player.kef_ls50
service: media_player.volume_set
service_data:
volume_level: '{{ (state_attr("media_player.kef_ls50", "volume_level") - 0.05) | max(0) }}'
entity_id: media_player.kef_ls50
text: '{{ (100 * state_attr("media_player.kef_ls50", "volume_level")) | int }}%'
text_size: 16
icon_mdi: "volume-minus"
- special_type: go-to-page
special_type_data: 0
:link: 使用 !include
进行模块化配置
警告:当前此库的附加组件版本中此功能无法使用。
为了使您的配置更加有序和易于维护,您可以使用!include
指令将配置拆分为多个文件,就像在Home Assistant中做的那样。这对于大型设置或您想在多个设置中共享某些配置时特别有用。
例如,如果您有一组要在多个页面上使用的常用按钮,您可以在单独的YAML文件中定义它们,然后在主配置中包含它们。
# includes/home.yaml
- entity_id: light.bedroom_lights
service: light.toggle
text: |
Bedroom
lights
- icon: netflix.png
service: script.start_spotify
在您的主配置中
# configuration.yaml
pages:
- name: Home
buttons: !include includes/home.yaml
...
使用!include
,您可以保持配置干净且易于重用。
警告:此库不支持Home Assistant支持的其他指令,例如
!secret
或!include_dir_list
。
:clipboard: Config YAML 配置
每个YAML配置可以采用以下配置
变量名称 | 描述 | 默认值 | 类型 |
---|---|---|---|
pages |
配置中的Page 列表。 |
列表[Page] |
|
anonymous_pages |
配置中的匿名Page 列表。这些页面是隐藏的,在循环遍历页面时不会显示。它们只能通过special_type: 'go-to-page' 按钮访问。设计为单次使用,这些页面在点击按钮后将返回上一个页面。 |
列表[Page] |
|
state_entity_id |
用于同步显示状态的实体ID。例如input_boolean.streamdeck 或binary_sensor.anyone_home 。 |
None |
可选[str] |
brightness |
Stream Deck的默认亮度(0-100)。 | 100 |
int |
auto_reload |
如果为True,当配置YAML文件被修改时,配置将自动重新加载。 | False |
bool |
:bookmark_tabs: 页面 YAML 配置
每个按钮可以采用以下配置
变量名称 | 描述 | 默认值 | 类型 |
---|---|---|---|
name |
页面的名称。 | str |
|
buttons |
页面上的按钮列表。 | 列表[Button] |
|
dials |
页面上的旋钮列表。 | 列表[Dial] |
:white_square_button: 按钮 YAML 配置
每个按钮可以采用以下配置
变量名称 | 允许模板 | 描述 | 默认值 | 类型 |
---|---|---|---|---|
entity_id |
✅ | 此按钮控制的entity_id 。当按钮被按下时,将传递给service 。当此实体的状态发生变化时,按钮将重新渲染。 |
可选[str] |
|
linked_entity |
✅ | 用于更新图像和状态的辅助实体ID。 | 可选[str] |
|
service |
✅ | 当按钮被按下时将调用的service 。 |
可选[str] |
|
service_data |
✅ | 当按钮被按下时传递给service 的service_data 。如果为空,则传递entity_id 。 |
可选[Mapping[str, Any]] |
|
target |
✅ | 当按钮被按下时传递给service 的target 。 |
可选[Mapping[str, Any]] |
|
text |
✅ | 按钮上要显示的文本。如果为空,则不显示文本。您可能想要添加\n 字符以将文本扩展到多行,或者使用YAML中的| 字符创建多行字符串。 |
str |
|
text_color |
✅ | 文本颜色。如果为空,颜色为white ,除非指定了entity_id ,在这种情况下,当状态为on 时颜色为amber ,当状态为off 时颜色为white 。 |
可选[str] |
|
text_size |
❌ | 文本的整数大小。 | 12 |
int |
text_offset |
❌ | 文本的位置可以从按钮的中心向上或向下移动,这种移动以像素为单位衡量。值可以是正数(向上移动)或负数(向下移动)。 | int |
|
icon |
✅ | 按钮上显示的图标文件名。使路径为绝对路径(例如,/config/streamdeck/my_icon.png )或相对于assets 目录(例如,my_icon.png )。如果为空,将显示带有icon_background_color 和text 的图标。图标可以是图像的URL,如'url:https://www.nijho.lt/authors/admin/avatar.jpg' ,或spotify: 图标,如'spotify:album/6gnYcXVaffdG0vwVM34cr8' 。如果图标是spotify: 图标,图标将被下载并缓存。图标还可以显示部分完成的环形,例如进度条,或传感器值,如25%完成的环形表示为ring:25 。 |
可选[str] |
|
icon_mdi |
✅ | 按钮上显示的Material Design图标。如果为空,则不显示图标。请参见https://mdi.bessarabov.com/获取图标列表。SVG图标将被下载并缓存。 | 可选[str] |
|
icon_background_color |
✅ | 图标背景的颜色(十六进制格式,例如,'#FF0000')(如果没有指定icon )。 |
#000000 |
str |
icon_mdi_color |
✅ | Material Design图标的颜色(十六进制格式,例如,'#FF0000')。如果为空,颜色将从text_color 派生,但饱和度较低(混合了灰色)。 |
可选[str] |
|
icon_gray_when_off |
❌ | 指定icon 和entity_id 时,如果状态为off ,则图标将被转换为灰度。 |
bool |
|
delay |
✅ | 在调用service 之前延迟的时间(以秒为单位)。如果您想在调用service 之前等待,这很有用。从按按钮的时间开始倒计时。如果在倒计时过程中再次按按钮,计时器将被取消。应为浮点数或计算结果为浮点数的模板字符串。 |
Union[float, str] |
|
special_type |
❌ | 按钮的特殊类型。如果没有指定,则按钮为普通按钮。如果为next-page ,按钮将转到下一页。如果为previous-page ,按钮将转到上一页。如果为turn-off ,按钮将关闭SteamDeck直到任何按钮被按下。如果为empty ,按钮将为空。如果为go-to-page ,按钮将转到由special_type_data 指定的页面(可以是int 或str (页面的名称))。如果为light-control ,按钮将控制灯光,并且special_type_data 可以是一个字典。如果为reload ,按钮将被按下时重新加载配置文件。 |
Optional[Literal['next-page', 'previous-page', 'empty', 'go-to-page', 'turn-off', 'light-control', 'reload']] |
|
special_type_data |
✅ | 特殊类型按钮的数据。如果为go-to-page ,数据应为int 或str (页面的名称)。如果为light-control ,数据可以是一个可选的字典。该字典可以包含以下键:键colors 和值是最大(n_keys_on_streamdeck - 5 )个十六进制颜色列表。键color_temp_kelvin 和值是最大(n_keys_on_streamdeck - 5 )个开尔文颜色温度列表。键colormap 和值是一个colormap(https://matplotlib.net.cn/stable/tutorials/colors/colormaps.html)可以用来。这需要安装matplotlib 包。如果没有指定颜色列表或colormap,则使用10个等间隔的颜色。 |
Optional[Any] |
:bulb: 30 多种按钮配置想法
以下是Stream Deck与Home Assistant的>30个有趣用途(点击文本以展开)
1. 🎭 激活场景
- service: scene.turn_on
service_data:
entity_id: scene.movie_night
icon_mdi: movie
text: Movie Night
2. 🚪 切换盖子(例如,百叶窗或车库门)
- entity_id: cover.garage_door
service: cover.toggle
icon_mdi: "{{ 'garage-open' if is_state('cover.garage_door', 'open') else 'garage-lock' }}"
text: "{{ 'Open' if is_state('cover.garage_door', 'open') else 'Close' }}"
3. 🤖 启动或停止吸尘机器人
- entity_id: vacuum.cleaning_robot
service: >-
{% if is_state('vacuum.cleaning_robot', 'docked') %}
vacuum.start
{% else %}
vacuum.return_to_base
{% endif %}
icon_mdi: robot-vacuum
text: >-
{% if is_state('vacuum.cleaning_robot', 'docked') %}
Start
{% else %}
Stop
{% endif %}
4. 🔇 静音/取消静音媒体播放器
- entity_id: media_player.living_room_speaker
service: media_player.volume_mute
service_data:
entity_id: media_player.living_room_speaker
is_volume_muted: >-
{% if is_state_attr('media_player.living_room_speaker', 'is_volume_muted', true) %}
false
{% else %}
true
{% endif %}
icon_mdi: >-
{% if is_state_attr('media_player.living_room_speaker', 'is_volume_muted', true) %}
volume-off
{% else %}
volume-high
{% endif %}
text: >-
{% if is_state_attr('media_player.living_room_speaker', 'is_volume_muted', true) %}
Unmute
{% else %}
Mute
{% endif %}
5. 🌟 控制灯光亮度(按按钮时+10%)
- entity_id: light.living_room_lights
service: light.turn_on
service_data:
entity_id: light.living_room_lights
brightness: >-
{% set current_brightness = state_attr('light.living_room_lights', 'brightness') %}
{% set next_brightness = (current_brightness + 25.5) % 255 %}
{{ next_brightness | min(255) | int }}
text: >-
{% set current_brightness = state_attr('light.living_room_lights', 'brightness') %}
{% set brightness_pct = (current_brightness / 255) * 100 %}
{{ brightness_pct | round }}%
6. 🌀 切换风扇
- entity_id: fan.bedroom_fan
service: fan.toggle
icon_mdi: "{{ 'fan' if is_state('fan.bedroom_fan', 'on') else 'fan-off' }}"
text: |
Bedroom
{{ 'On' if is_state('fan.bedroom_fan', 'on') else 'Off' }}
7. 🔒 30秒后锁定/解锁门
- entity_id: lock.front_door
service: lock.toggle
delay: "{{ 30 if is_state('lock.front_door', 'unlocked') else 0 }}"
icon_mdi: "{{ 'door-open' if is_state('lock.front_door', 'unlocked') else 'door-closed' }}"
text: |
Front Door
{{ 'Unlocked' if is_state('lock.front_door', 'unlocked') else 'Locked' }}
text_size: 10
text_color: "{{ 'green' if is_state('lock.front_door', 'unlocked') else 'red' }}"
8. ⚠️ 30秒后布防/撤防报警系统
- entity_id: alarm_control_panel.home_alarm
delay: "{{ 0 if is_state('alarm_control_panel.home_alarm', 'armed_away') else 30 }}"
service: "{{ 'alarm_control_panel.alarm_disarm' if is_state('alarm_control_panel.home_alarm', 'armed_away') else 'alarm_control_panel.alarm_arm_away' }}"
icon_mdi: "{{ 'shield-check' if is_state('alarm_control_panel.home_alarm', 'armed_away') else 'shield-off' }}"
text: |
{{ 'Disarm' if is_state('alarm_control_panel.home_alarm', 'armed_away') else 'Arm' }}
Alarm
text_color: "{{ 'red' if is_state('alarm_control_panel.home_alarm', 'armed_away') else 'green' }}"
如果报警系统未布防,30秒后布防;如果已布防,立即撤防。
9. ⏰ 设置第二天闹钟时间
- service: input_datetime.set_datetime
service_data:
entity_id: input_datetime.alarm_time
time: "{{ '07:00:00' if states('input_datetime.alarm_time') != '07:00:00' else '08:00:00' }}"
icon_mdi: "alarm"
text: |
Set Alarm
{{ '7AM' if states('input_datetime.alarm_time') != '07:00:00' else '8AM' }}
10. ⏯️ 控制媒体播放器(播放/暂停)
- entity_id: media_player.living_room_speaker
service: media_player.media_play_pause
icon_mdi: "{{ 'pause' if is_state('media_player.living_room_speaker', 'playing') else 'play' }}"
text: "{{ 'Pause' if is_state('media_player.living_room_speaker', 'playing') else 'Play' }}"
11. 🎵 控制媒体播放器(跳过曲目)
- entity_id: media_player.living_room_speaker
service: media_player.media_next_track
icon_mdi: skip-next
text: Next Track
12. 🌈 设置灯光的特定颜色
- entity_id: light.living_room_light
service: light.toggle
service_data:
color_name: blue
icon_mdi: "{{ 'lightbulb-on' if is_state('light.living_room_light', 'on') else 'lightbulb-off' }}"
text: Blue Light
13. 🌡️ 在两个特定温度之间调整恒温器
- entity_id: climate.living_room
service: climate.set_temperature
service_data:
temperature: "{{ 17 if state_attr('climate.living_room', 'temperature') >= 22 else 22 }}"
icon_mdi: thermostat
text: |
Set
{{ '17°C' if state_attr('climate.living_room', 'temperature') >= 22 else '22°C' }}
({{ state_attr('climate.living_room', 'current_temperature') }}°C now)
14. 📲 触发脚本向您的移动设备发送通知
- service: script.send_mobile_notification
icon_mdi: bell
text: Send Notification
该脚本使用此脚本(需要在Home Assistant中定义)
send_mobile_notification:
alias: "Send Mobile Notification"
sequence:
- service: notify.mobile_app_<your_device_name>
data:
message: "Your custom notification message."
15. 🌆 切换白天/夜间模式(使用input_boolean)
- entity_id: input_boolean.day_night_mode
service: input_boolean.toggle
icon_mdi: "{{ 'weather-night' if is_state('input_boolean.day_night_mode', 'on') else 'weather-sunny' }}"
text: |
{{ 'Night' if is_state('input_boolean.day_night_mode', 'on') else 'Day' }}
Mode
16. 📺 控制电视(例如,开启/关闭或更改输入源)
- entity_id: media_player.living_room_tv
service: media_player.select_source
service_data:
source: HDMI 1
text: HDMI 1
17. 🔦 控制灯光组(例如,开启/关闭或更改颜色)
- entity_id: group.living_room_lights
service: light.turn_on
service_data:
color_name: red
icon_mdi: "{{ 'lightbulb-group' if is_state('group.living_room_lights', 'on') else 'lightbulb-group-off' }}"
text: Red Group Lights
18. 🔔 触发脚本以宣布门铃
- service: script.trigger_doorbell_announcement
text: Doorbell Announcement
该脚本使用此脚本(需要在Home Assistant中定义)
trigger_doorbell_announcement:
alias: "Trigger Doorbell Announcement"
sequence:
- service: tts.google_translate_say
data:
entity_id: media_player.<your_media_player>
message: "Someone is at the door."
19. ⏰ 启用/禁用睡眠定时器(使用input_boolean)
- entity_id: input_boolean.sleep_timer
service: input_boolean.toggle
icon_mdi: "{{ 'timer' if is_state('input_boolean.sleep_timer', 'on') else 'timer-off' }}"
text: |
{{ 'Cancel' if is_state('input_boolean.sleep_timer', 'on') else 'Set' }}
Sleep Timer
20. 🌡️ 显示当前温度
- entity_id: sensor.weather_temperature
text: '{{ states("sensor.weather_temperature") }}°C'
text_size: 16
icon_mdi: weather-cloudy
21. 📶 切换Wi-Fi的开启/关闭(使用开关)
- entity_id: switch.wifi_switch
service: switch.toggle
icon_mdi: "{{ 'wifi' if is_state('switch.wifi_switch', 'on') else 'wifi-off' }}"
text: |
{{ 'Disable' if is_state('switch.wifi_switch', 'on') else 'Enable' }}
Wi-Fi
22. 🗣️ 激活语音助手
- service: script.activate_voice_assistant
icon_mdi: microphone
text: Voice Assistant
该脚本使用此脚本(需要在Home Assistant中定义)
activate_voice_assistant:
alias: "Activate Voice Assistant"
sequence:
- service: media_player.play_media
target:
entity_id: media_player.<your_media_player>
data:
media_content_id: "http://<your_url>/<filename>.mp3"
media_content_type: "music"
23. 🌿 启动/停止空气净化器
- entity_id: switch.air_purifier
service: switch.toggle
icon_mdi: "{{ 'air-purifier' if is_state('switch.air_purifier', 'on') else 'air-purifier-off' }}"
text: |
{{ 'Stop' if is_state('switch.air_purifier', 'on') else 'Start' }}
Air Purifier
24. 📼 开始/停止安全摄像头录制
- service: script.toggle_security_camera_recording
icon_mdi: cctv
text: Toggle Camera Recording
该脚本使用此脚本(需要在Home Assistant中定义)
toggle_security_camera_recording:
alias: "Toggle Security Camera Recording"
sequence:
- service: camera.record
target:
entity_id: camera.<your_camera>
data:
duration: 10
lookback: 2
filename: "/config/www/recordings/camera_{{ now().strftime('%Y%m%d_%H%M%S') }}.mp4"
25. 🌙 30分钟后启用/禁用夜灯
- entity_id: light.nightlight
service: light.toggle
delay: 1800
icon_mdi: "{{ 'lightbulb-on' if is_state('light.nightlight', 'on') else 'lightbulb-off' }}"
text: "{{ 'Disable' if is_state('light.nightlight', 'on') else 'Enable' }} Nightlight"
text_color: "{{ 'red' if is_state('light.nightlight', 'on') else 'green' }}"
26. 🔥 控制智能壁炉
- entity_id: switch.smart_fireplace
service: switch.toggle
icon_mdi: "{{ 'fire' if is_state('switch.smart_fireplace', 'on') else 'fire-off' }}"
text: |
{{ 'Turn Off' if is_state('switch.smart_fireplace', 'on') else 'Turn On' }}
Fireplace
27. 🔌 切换智能插座的开启/关闭
- entity_id: switch.smart_plug
service: switch.toggle
icon_mdi: "{{ 'power-plug' if is_state('switch.smart_plug', 'on') else 'power-plug-off' }}"
text: |
{{ 'Turn Off' if is_state('switch.smart_plug', 'on') else 'Turn On' }}
Smart Plug
28. 💦 切换灌溉系统
- entity_id: switch.irrigation_system
service: switch.toggle
icon_mdi: "{{ 'water' if is_state('switch.irrigation_system', 'on') else 'water-off' }}"
text: |
{{ 'Turn Off' if is_state('switch.irrigation_system', 'on') else 'Turn On' }}
Irrigation
29. 🌤️ 改变遮盖物的位置(例如,百叶窗或窗帘)
- entity_id: cover.living_room_blinds
service: cover.set_cover_position
service_data:
position: "{{ 0 if state_attr('cover.living_room_blinds', 'position') >= 50 else 100 }}"
icon_mdi: window-shutter
text: |
{{ 'Close' if state_attr('cover.living_room_blinds', 'position') >= 50 else 'Open' }}
Blinds
30. 📺 切换媒体播放器(例如,电视)并显示不同的图像
- entity_id: media_player.tv
service: media_player.toggle
icon: >
{% if is_state('media_player.tv', 'on') %}
url:https://raw.githubusercontent.com/basnijholt/home-assistant-streamdeck-yaml/main/assets/fireplace.png
{% else %}
url:https://raw.githubusercontent.com/basnijholt/home-assistant-streamdeck-yaml/main/assets/hogwarts.png
{% endif %}
text: >
Turn {{ 'Off' if is_state('media_player.tv', 'on') else 'On' }}
31. ⏰ 60秒内关闭所有灯光
- entity_id: light.all_lights
service: light.turn_off
text: |
Turn off
in 60s
delay: 60
32. 🌡️ 使用环形指示器显示室外温度
- entity_id: sensor.temperature_sensor_outside_temperature
icon: >
{%- set temp = states('sensor.temperature_sensor_outside_temperature') -%}
{%- set min_temp = -10 -%}
{%- set max_temp = 40 -%}
{%- set pct = ((temp - min_temp) / (max_temp - min_temp)) * 100 -%}
ring:{{ pct | round }}
text: |
{%- set temp = states('sensor.temperature_sensor_outside_temperature') -%}
Outside
{{ temp | round(1) }}°C
这设置为0%为-10°C和100%为40°C。
33. 🔄 重新加载`configuration.yaml`文件
- special_type: reload
当按下时,将重新加载`configuration.yaml`。
附加文档
支持 Streamdeck Plus :plus
configuration.yaml
Streamdeck plus的`configuration.yaml`与常规Streamdeck的配置非常相似,如果您想使用它们,只需为每个页面添加旋钮即可,当然,如果您不想为特定页面使用旋钮,也可以保留它。一个包含旋钮的`configuration.yaml`示例看起来像这样。
brightness: 100
auto_reload: true
state_entity_id: input_boolean.streamdeck
pages:
- name: home
buttons: !include includes/home.yaml
- name: room_1
dials: !include includes/room_1_dials.yaml
buttons: !include includes/room_1.yaml
配置旋钮
旋钮的工作方式也与按钮非常相似,您只需指定一个事件类型,例如如果想要按下按钮或旋转,则指定为push;如果想要旋转事件,则指定为turn。以下是一个旋转事件旋钮控制灯光的示例,并显示环形指示器和亮度数值。
- entity_id: light.testing
service: light.turn_on
service_data:
brightness: '{{ dial_value | int}}'
icon: >
{%- set state = dial_value() -%}
{%- set min = dial_attr("min") -%}
{%- set max = dial_attr("max") -%}
{%- set pct = ((state - min) / (max - min)) * 100 -%}
ring:{{ pct | round }}
text: >
{%- set state = dial_value() -%}
{%- set ha_state = states('light.testing') -%}
{%- if ha_state == "off" and dial_value() == 0 -%}
{{"off"}}
{%- else -%}
{{state | int}}
{%- endif -%}
state_attribute: brightness
allow_touchscreen_events: true
delay: 0.5
dial_event_type: TURN
attributes:
min: 0
max: 100
step: 1
旋钮特定属性类型
直到`delay`的属性与按钮相同,但有一些特定的属性适用于旋钮。
变量名称 | 允许模板 | 描述 | 默认值 | 类型 |
---|---|---|---|---|
entity_id |
✅ | 此旋钮控制的`entity_id`。当旋钮旋转时,此实体将传递给`service`。当此实体的状态发生变化时,旋钮将重新渲染。 | 可选[str] |
|
linked_entity |
✅ | 用于更新图像和状态的辅助实体ID。 | 可选[str] |
|
service |
✅ | 当旋钮旋转时将调用的`service`。 | 可选[str] |
|
service_data |
✅ | 当旋钮旋转时将传递给`service`的`service_data`。如果为空,则传递`entity_id`。 | 可选[Mapping[str, Any]] |
|
target |
✅ | 当旋钮旋转时将传递给`service`的`target`。 | 可选[Mapping[str, Any]] |
|
text |
✅ | 显示在旋钮上方的文本。如果为空,则不显示文本。您可能需要添加`\n`字符以在多行中展开文本,或使用YAML中的`|`字符创建多行字符串。 | str |
|
text_color |
✅ | 文本颜色。如果为空,颜色为white ,除非指定了entity_id ,在这种情况下,当状态为on 时颜色为amber ,当状态为off 时颜色为white 。 |
可选[str] |
|
text_size |
❌ | 文本的整数大小。 | 12 |
int |
text_offset |
❌ | 文本的位置可以从旋钮中心向上或向下移动,这种移动以像素为单位。值可以是正数(向上移动)或负数(向下移动)。 | int |
|
icon |
✅ | 显示在旋钮上方的图标文件名。请设置路径为绝对路径(例如,/config/streamdeck/my_icon.png )或相对于assets 目录(例如,my_icon.png )。如果为空,则显示带有icon_background_color 和text 的图标。图标可以是图像的URL,如'url:https://www.nijho.lt/authors/admin/avatar.jpg' ,或spotify: 图标,如'spotify:album/6gnYcXVaffdG0vwVM34cr8' 。如果图标是spotify: 图标,则图标将被下载并缓存。图标还可以显示部分完成的圆环,如进度条,或传感器值,例如ring:25 表示25%完成的圆环。 |
可选[str] |
|
icon_mdi |
✅ | 显示在旋钮上方的材质设计图标。如果为空,则不显示图标。请参阅https://mdi.bessarabov.com/获取图标列表。SVG图标将被下载并缓存。 | 可选[str] |
|
icon_background_color |
✅ | 图标背景的颜色(十六进制格式,例如,'#FF0000')(如果没有指定icon )。 |
#000000 |
str |
icon_mdi_color |
✅ | Material Design图标的颜色(十六进制格式,例如,'#FF0000')。如果为空,颜色将从text_color 派生,但饱和度较低(混合了灰色)。 |
可选[str] |
|
icon_gray_when_off |
❌ | 指定icon 和entity_id 时,如果状态为off ,则图标将被转换为灰度。 |
bool |
|
delay |
✅ | 在调用service 之前延迟的时间(以秒为单位)。从指定时间开始倒计时,并收集调用的旋转事件,在旋钮未在指定延迟时间内旋转后,将捆绑的值发送到Home Assistant。 |
Union[float, str] |
|
dial_event_type |
✅ | 触发服务的旋钮的事件类型。可以是DialEventType.TURN 或DialEventType.PUSH 。 |
可选[str] |
|
state_attribute |
✅ | 用于旋钮状态的实体的属性。 | 可选[str] |
|
attributes |
✅ | 设置旋钮的属性。 min :旋钮的最小值。 max :旋钮的最大值。 step :事件增加旋钮值的步长。 |
可选[Mapping[str, float]] |
|
allow_touchscreen_events |
✅ | 是否允许来自触摸屏的事件,例如在SHORT 上设置最小值,在LONG 上设置最大值。 |
bool |
Jinja 变量
dial_value
:旋钮的当前本地值(如果设置了延迟,可能不同于状态值)dial_attr
:一个函数,它接受一个字符串作为参数并返回具有该名称的属性值states
:Home Assistant中实体的当前状态
触摸屏事件
- 如果你的Streamdeck有触摸屏,你可以通过在屏幕上左右滑动来切换页面。
- 如果你设置了
allow_touchscreen_events
属性,你也可以使用触摸屏通过点击或长按旋钮区域将旋钮的值设置为该旋钮的最大值或最小值。
包含变量
[!NOTE] 包含变量独立于Streamdeck plus功能,可以在每个支持的Streamdeck版本中使用。
你还可以通过包含标签将变量传递给包含的文件。这可以用于创建模板并在多个实体之间重用。以下是如何在配置中使用包含变量的示例
page.yaml
- !include {file: includes/button.yaml, vars: {entity_id: light.living_room, icon_mdi:lightbulb, text: Living Room Lights}}
- !include {file: includes/button.yaml, vars: {entity_id: light.bed, icon_mdi:lightbulb, text: Bed Room Lights}}
# Other files you might want to include...
在vars字典中且以${variable_name}
格式存在的内容将在启动应用程序时加载YAML文件时被替换。与同一格式相同但不在vars字典中的其他文本将不会被替换。
includes/button.yaml
- entity_id: ${entity_id}
service: light.toggle
icon_mdi: ${icon_mdi}
text: ${text}
在这种情况下,${entity_id}
、${icon_mdi}
和${text}
将替换为!include
标签中给出的值。
项目详情
home_assistant_streamdeck_yaml-2024.7.5.tar.gz的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 8505a9036bcddf258693f9d95d2e0ba584dc11c650a4b438abbf0ccc85d49540 |
|
MD5 | 1571194052e7697dc0571f06997c4d59 |
|
BLAKE2b-256 | ddfc444da62abc3268a96deda8bf35268a4994d0b3f19f56456160039a1f5ccd |
home_assistant_streamdeck_yaml-2024.7.5-py3-none-any.whl的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | c25d2cc90a0282f36e86e26ea5542611c2483016a11cc1c72b43f36c2a25ad57 |
|
MD5 | a003640bd132538ae9a86bee26090936 |
|
BLAKE2b-256 | 3cab65faf7584740935778ed41d9515101d260059bbc5d54ca09db8048a17eff |