Hi,
I’m working on a rest sensor which does a POST request and requires a start and end date.
I read in the official docs that only a string is allowed for the payload.
is there no other way to use a template in there?
What I’m trying to achieve but doesn’t work unfortunately:
What does the response look like without dates? Can you create a template sensor from that sensor that extracts what you wish? I use a rest sensor payload like this:
payload: '{"KEYLIST": [{"CODESET": {{ codeset | int }},"CODE": {{ code | int }},"ACTION":"KEYPRESS"}]}'
Watching your single/double quotes and putting it all in a string (of JSON).
OK, thanks. I’ve now implemented ‘payload_template’ in a POST command to a remote server but am having problems - I’m clearly missing something / making a simple mistake and would massively appreciate some assistance.
I have successfully used ‘payload_template’ with the following code (plus multiple other derivatives that all use a fixed text string like below):
payload_template: >-
{% set fr_text = '{ \"text\" : [\"' + 'A test string' + '\"], \"target_lang\" : \"EN\" }' %}
{{ fr_text }}
… but when I substitute ‘A test string’ with the state value of a sensor the payload is no longer considered valid by the remote server.
Unfortunately the remote server doesn’t provide any error response so I can’t easily debug. I have however tried using the above code (and multiple other versions) in ‘Developer Tools / Template’ and frustratingly they all appear to work fine and return exactly the same output as when using the static text.