# Home Assistant データテンプレート

**URL:** https://forum.ficusonline.com/t/topic/286
**Category:** Automation
**Created:** [2019 年 3 月 11 日午後 2:40 UTC](https://forum.ficusonline.com/t/topic/286 "2019-03-11T14:40:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 3 月 11 日午後 2:40 UTC](https://forum.ficusonline.com/t/topic/286/1 "2019-03-11T14:40:58Z")

</div>

テンプレートはセンサの条件出しやデータ取得時間の表示などに必要な機能であるため、Home Assistant導入段階で良く理解する必要が有ります。

> **[Templating](https://www.home-assistant.io/docs/configuration/templating/)**
>
> Instructions on how to use the templating feature of Home Assistant.

**バイナリセンサのタイムスタンプの取得方法（開発者ツールのテンプレートにより確認）**

```python
    {{ as_timestamp(states.binary_sensor.motion_2.last_changed) | timestamp_local }}
    {{ states.binary_sensor.motion.last_updated }}
    {{ now() }}
    {{ is_state('binary_sensor.motion_2', 'on') }}
    {{ states.sensor.si_t.state_with_unit }}

```

**出力結果**

```
2019-03-11 23:32:11
2019-03-11 13:50:17.570430+00:00
2019-03-11 23:32:14.698594+09:00
False
19.5 °C

```

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2021 年 7 月 9 日午前 2:19 UTC](https://forum.ficusonline.com/t/topic/286/2 "2021-07-09T02:19:42Z")

</div>

### 入れ子形式のJSONデータの抽出方法

> **[Processing incoming data - Templating](https://www.home-assistant.io/docs/configuration/templating/#processing-incoming-data)**
>
> This is an advanced feature of Home Assistant. You’ll need a basic understanding of: | Instructions on how to use the templating feature of Home Assistant.

一つのデバイスから複数のIDによるデータをパブリッシュする場合、ID別にデータを入れ子にします。

**送信フォーマット：入れ子JSONデータ**

```auto
{
  "id1": {
    "hr": "65",
    "spo2": "98",
    "temp":"36.56"
  }
}

```

受信側（Home Assistant）では以下のフォーマットで入れ子のデータを抽出します。

**受信側(Home Assistant)でデータ抽出**

```auto
"{{ value_json['id1']['hr'] }}"
"{{ value_json['id1']['spo2'] }}"
"{{ value_json['id1']['temp'] }}"

```
