Skip to content

Instantly share code, notes, and snippets.

@willwhui
Created December 6, 2017 02:29
Show Gist options
  • Save willwhui/25bfe2b213c1728bb9e02dbd6a8ca5ab to your computer and use it in GitHub Desktop.
Save willwhui/25bfe2b213c1728bb9e02dbd6a8ca5ab to your computer and use it in GitHub Desktop.
使用模板生成数据
@willwhui
Copy link
Author

willwhui commented Dec 6, 2017

根据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

@willwhui
Copy link
Author

willwhui commented Dec 6, 2017

时间的格式化:
{{ 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