Hi all
I have a senor entity_id ensor.sigfox_4d30a7
which has the state {"t":189012}
, i.e. a json payload. I want to display 189012
in its own sensor using a template sensor. To do so I must use a value_template
but the following config gives an error Could not render template Sigfox time: UndefinedError: 'value_json' is undefined
. Any ideas?
sensor:
- platform: template
sensors:
sigfox_time:
friendly_name: "Sigfox time"
unit_of_measurement: 'time'
entity_id: sensor.sigfox_4d30a7
value_template: '{{value_json.t}}'
VDRainer
(π»)
March 24, 2018, 8:10am
2
I think it should be
value_template: '{{ states.sensor.sigfox_4d30a7.state.t }}'
The entity_id in the template sensor is for reacting on state changes.
No errors but the sensor is blank (no data)β¦
metbril
(Robert π³π±πͺπΊ)
March 24, 2018, 8:30pm
4
Iβm afraid you might need a custom component
Hereβs what Iβm trying to do. I have a REST sensor to get status from my rooted TV:
sensor:
- platform: rest
resource: !secret samygo_tv_living_channelinfo
method: GET
name: TV Living Channel Info
scan_interval: '00:05'
The data returned by this sensor is in JSON format and has several fields (extracted from the entitiy view for sensor.tv_living_channel_info):
{"source":"TV (0)","pvr_status":"NONE","powerstate":"Normal","tv_mode":"Cable (1)","volume":"7","channel_number":"45β¦
home-assistant:dev
β mad-ady:dev
opened 01:15PM - 09 Nov 17 UTC
## Description:
Truncates the state to 255 characters, to comply with https:/β¦ /github.com/home-assistant/home-assistant/pull/9696
Tries to automatically parse REST output as JSON, and if there are no parsing issues, stores all data inside attributes (even if the variable is templated).
Supporting documentation for this is a separate PR. I will reference it as soon as I get an ID.
## Checklist:
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated in [home-assistant.github.io](https://github.com/home-assistant/home-assistant.github.io) -- examples for clarity
If the code communicates with devices, web services, or third-party tools:
- [ ] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**
- [ ] New dependencies have been added to the `REQUIREMENTS` variable ([example][ex-requir]).
- [ ] New dependencies are only imported inside functions that use them ([example][ex-import]).
- [ ] New dependencies have been added to `requirements_all.txt` by running `script/gen_requirements_all.py`.
- [ ] New files were added to `.coveragerc`.
If the code does not interact with devices:
- [ ] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**
- [ ] Tests have been added to verify that the new code works.
[ex-requir]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L14
[ex-import]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L54
1 Like