Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT Payload Template Not Rendering in Button Call-Service #907

Open
mbonaccors opened this issue Feb 3, 2025 · 3 comments
Open

MQTT Payload Template Not Rendering in Button Call-Service #907

mbonaccors opened this issue Feb 3, 2025 · 3 comments
Labels
FR Feature Request

Comments

@mbonaccors
Copy link

After the deprecation of payload_data for MQTT, we were instructed to use payload exclusively for static and template-based payloads. While testing MQTT messages with template data in Developer Tools, everything works correctly. However, when using a Lovelace button (via a tap_action calling mqtt.publish) that includes a template variable in the payload, the variable is not rendered and the literal template string is passed through instead. For example:

tap_action:
action: call-service
service: mqtt.publish
service_data:
payload: {{ states("input_boolean.studio_mode_chill") }}
topic: eventghost

will just render as:

{{ states("input_boolean.studio_mode_chill") }}

Is there a way to move the jinja2 rendering over to the payload key now that everything has been switched over?

@mbonaccors mbonaccors added the FR Feature Request label Feb 3, 2025
@ngocjohn
Copy link

ngocjohn commented Feb 3, 2025

Create a script or automation for the tap action trigger... like action: script.turn_on

@endic-sam928281
Copy link

Hello, we tried to solve the issue.

This is what we did:

Modify the handleAction function to render Jinja2 templates in MQTT publish payloads before sending the action. This addresses the issue where template variables in Lovelace button tap_actions for MQTT publish were not being rendered.

You can review changes in this commit: endic-sam928281@ac824aa.

Caution

Disclaimer: The concept of solution was created by AI and you should never copy paste this code before you check the correctness of generated code. Solution might not be complete, you should use this code as an inspiration only.


Latta AI seeks to solve problems in open source projects as part of its mission to support developers around the world. Learn more about our mission at https://latta.ai/ourmission . If you no longer want Latta AI to attempt solving issues on your repository, you can block this account.

@mbonaccors
Copy link
Author

mbonaccors commented Feb 3, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FR Feature Request
Projects
None yet
Development

No branches or pull requests

3 participants