Skip to content

Add json_attributes_template#22981

Merged
balloob merged 1 commit intohome-assistant:devfrom
emontnemery:mqtt_json_attr_template
Apr 19, 2019
Merged

Add json_attributes_template#22981
balloob merged 1 commit intohome-assistant:devfrom
emontnemery:mqtt_json_attr_template

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery commented Apr 10, 2019

Description:

Add json_attributes_template to give a little bit of flexibility to json_attributes_topic, which has been requested several times, most recently in #22924.

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#9332

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: mqtt
    name: "Timer 1"
    state_topic: "tele/sonoff/sensor"
    value_template: "{{ value_json.Timer1.Arm }}"
    json_attributes_topic: "tele/sonoff/sensor"
    json_attributes_template: "{{ value_json.Timer1 | tojson }}"

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@emontnemery emontnemery requested a review from a team as a code owner April 10, 2019 20:26
@ghost ghost assigned emontnemery Apr 10, 2019
@ghost ghost added the in progress label Apr 10, 2019
@github-actions
Copy link
Copy Markdown

Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with a integration (mqtt) you are listed as a codeowner for? Thanks!

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2019

Codecov Report

Merging #22981 into dev will decrease coverage by 0.12%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev   #22981      +/-   ##
==========================================
- Coverage   94.11%   93.98%   -0.13%     
==========================================
  Files         448      449       +1     
  Lines       36718    36765      +47     
==========================================
- Hits        34558    34555       -3     
- Misses       2160     2210      +50
Impacted Files Coverage Δ
homeassistant/helpers/service.py 93.19% <0%> (-0.08%) ⬇️
homeassistant/helpers/entity_component.py 96.18% <0%> (-0.03%) ⬇️
homeassistant/components/demo/media_player.py 95.42% <0%> (ø) ⬆️
homeassistant/components/esphome/camera.py 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72af427...50f9c33. Read the comment docs.

@balloob
Copy link
Copy Markdown
Member

balloob commented Apr 17, 2019

This won't help the issue since json.dumps is not available in a template?

@emontnemery
Copy link
Copy Markdown
Contributor Author

@balloob not json.dumps exactly, but filter tojson is available , so a template like this should be fine: 'json_attributes_template': "{{ value_json['Timer1'] | tojson }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants