Skip to content

Add templates to MQTT climate#11623

Merged
pvizeli merged 2 commits into
home-assistant:devfrom
tinloaf:mqtt_climate_templates
Jan 14, 2018
Merged

Add templates to MQTT climate#11623
pvizeli merged 2 commits into
home-assistant:devfrom
tinloaf:mqtt_climate_templates

Conversation

@tinloaf
Copy link
Copy Markdown
Contributor

@tinloaf tinloaf commented Jan 13, 2018

Description:

This replaces #11347. The primary use case I have in mind is still the same as over there:

This targets a (probably pretty common) use case of using the MQTT thermostat with another HA instance on the other side, and using mqtt_statestream for the *_STATE channels. Since #9872 , the values set from the "master" HA instance will be echoed in a quoted form on the state channels by the "slave" HA instance, causing errors. There is currently no easy way of circumventing this.

However, providing the possibility to parse payloads via a template is definitely less hacky. I added the possibility to apply one template to all state topics (via value_template) as well as setting individual templates per state topic.

Related issue (if applicable): fixes parts of #10209

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

Example entry for configuration.yaml (if applicable):

climate:
  - platform: mqtt
    name: Study
    modes:
      - off
      - on
      - auto
    mode_command_topic: "study/ac/mode/set"
    mode_state_topic: "study/ac/mode/state"
    mode_state_template: "{{ value_json }}"

Checklist:

  • The code change is tested and works locally.

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

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.

@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Jan 13, 2018

I'm fine with the code. I'm not sure about the value_template. Is the problem that we do things wrong with the #9872? I think we should cast this as str and not as json per default... @balloob ?

@tinloaf
Copy link
Copy Markdown
Contributor Author

tinloaf commented Jan 14, 2018

The reason we decided in #9872 to go with JSON instead of casting to string is that attributes can contain more complex data structures, e.g., lists (lights contain RGB tuples as lists, climate devices have mode lists, …)

Sure, we could cast lists to string, but that solves this problem exactly for lists, and not arbitrary serializable data types.

@pvizeli pvizeli merged commit 0550baa into home-assistant:dev Jan 14, 2018
@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Jan 14, 2018

Anyway I think we should remove the value_template while it mess up the code and we don't have this on any other mqtt platform. Yeah first time you need set a lot of templates but we can add this into documentation and user need only copy paste this.

@IceStuff
Copy link
Copy Markdown

Can templates be added/applied to temperature_command_topic as well? Setpoint needs to be multiplied by 100 for my MQTT HVAC. Then read temperature needs to be divided by 100 which the above template addition should take care of that.

Thanks,
IceStuff

@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants