{"id":371,"date":"2017-10-31T10:00:29","date_gmt":"2017-10-31T10:00:29","guid":{"rendered":"https:\/\/www.cribbstechnologies.com\/?p=371"},"modified":"2017-10-30T21:45:24","modified_gmt":"2017-10-30T21:45:24","slug":"dynamic-service-calls","status":"publish","type":"post","link":"https:\/\/www.cribbstechnologies.com\/index.php\/2017\/10\/31\/dynamic-service-calls\/","title":{"rendered":"Dynamic Service Calls"},"content":{"rendered":"<p>[et_pb_section bb_built=&#8221;1&#8243; admin_label=&#8221;section&#8221;][et_pb_row admin_label=&#8221;Row&#8221;][et_pb_column type=&#8221;4_4&#8243;][et_pb_text admin_label=&#8221;Text&#8221; background_layout=&#8221;light&#8221; text_orientation=&#8221;left&#8221; use_border_color=&#8221;off&#8221; border_color=&#8221;#ffffff&#8221; border_style=&#8221;solid&#8221;]<\/p>\n<p>You&#8217;ve got a sweet automation but you need to grab some data from whatever triggered it. Luckily Home Assistant has the ability to use Jinja in automation via templates so you can get your information to another service. In my example, I&#8217;m using an automation where someone has arrived home so I use the TTS engine to welcome them home based on the name of the person who came home.<\/p>\n<pre lang=\"yaml\">automation:\r\n  - id: welcome_home\r\n    alias: Welcome Home\r\n    initial_state: True\r\n    trigger:\r\n      - platform: state\r\n        entity_id: device_tracker.brian\r\n        from: 'not_home'\r\n        to: 'home'\r\n        for:\r\n          minutes: 2\r\n      - platform: state\r\n        entity_id: device_tracker.christina\r\n        from: 'not_home'\r\n        to: 'home'\r\n        for:\r\n          minutes: 2\r\n    action:\r\n      service: script.welcome_home\r\n      data_template:\r\n        user: '{{trigger.to_state.attributes.friendly_name}}'\r\n<\/pre>\n<p>You can also use templates to control <strong>which<\/strong> entities are passed to the service call; this example is an Alexa intent. You can see both the player and source keys are used to determine the entity and which source to use.<\/p>\n<pre lang=\"yaml\">  MediaPlayerSourceIntent:\r\n    action:\r\n      service: media_player.select_source\r\n      data_template:\r\n        entity_id: 'media_player.{{player|replace(\" \", \"_\")|lower}}'\r\n        source: '{{source}}'\r\n    speech:\r\n      text: 'OK. Changing {{player}} to {{source}}'\r\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[et_pb_section bb_built=&#8221;1&#8243; admin_label=&#8221;section&#8221;][et_pb_row admin_label=&#8221;Row&#8221;][et_pb_column type=&#8221;4_4&#8243;][et_pb_text admin_label=&#8221;Text&#8221; background_layout=&#8221;light&#8221; text_orientation=&#8221;left&#8221; use_border_color=&#8221;off&#8221; border_color=&#8221;#ffffff&#8221; border_style=&#8221;solid&#8221;] You&#8217;ve got a sweet automation but you need to grab some data from whatever triggered it. Luckily Home Assistant has the ability to use Jinja in automation via templates so you can get your information to another service. In my example, I&#8217;m using an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,17,15,19],"tags":[21,20],"class_list":["post-371","post","type-post","status-publish","format-standard","hentry","category-blog","category-configuration","category-home-assistant","category-jinja","tag-home-assistant","tag-jinja"],"_links":{"self":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts\/371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/comments?post=371"}],"version-history":[{"count":3,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts\/371\/revisions"}],"predecessor-version":[{"id":374,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/posts\/371\/revisions\/374"}],"wp:attachment":[{"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/media?parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/categories?post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cribbstechnologies.com\/index.php\/wp-json\/wp\/v2\/tags?post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}