Created
December 6, 2017 02:29
-
-
Save willwhui/25bfe2b213c1728bb9e02dbd6a8ca5ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
使用模板生成数据 |
根据automation的tigger数据来调用不同的服务
参见:https://community.home-assistant.io/t/different-actions-depending-on-trigger-data-value/22440/3
比如,根据旋转方向来调整音量
alias: "TTS on Magic Cube rotate: volume"
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000103a704
action_type: rotate
action:
- service_template: >
{% if trigger.event.data.action_value > 0 %}
media_player.volume_up
{% else %}
media_player.volume_down
{% endif %}
entity_id: media_player.living_room_home
- service: tts.google_say
entity_id: media_player.living_room_home
data_template:
message: >
It is {{ states("sensor.time")}} now.
- service: timer.cancel # restart timer
entity_id: timer.timer_on_magic_tube_rotated
- service: timer.start
entity_id: timer.timer_on_magic_tube_rotated
时间的格式化:
{{ now().strftime('%-I:%M %P') }}
结果:
10:18 pm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在automation中使用template
专门文档:
https://home-assistant.io/docs/automation/templating/
这里 https://home-assistant.io/components/binary_sensor.xiaomi_aqara/#gas
还提到:
这是如何获取其他属性的方法。
另外某处提到还有个写法: