Hello!
First time poster so I hope I am posting this the correct way...
I am trying to send a variable (the HA username) of the person activating the rest_command sendtestsms
But failing misserably. The command works and the payload is sent but the variable is not sent with it.
This is what I have got so far, does anyone have a solution to this?
rest_command:
sendtestsms:
url: "http://192.168.53.250/cgi-bin/sms_send?"
method: POST
payload: "username=*MYUSERNAME*&password=*MY_PASSWORD*&text={{ user }} Sent a test SMS&number=*MY_PHONE_NUMBER*"
content_type: "application/x-www-form-urlencoded"
Oh, maybe I should add... The command works but does not send the variable.
Can you give us a bit more detail on how you want to use this?
Are you on Linux or Mac, if so you can test what this request looks like with the terminal command nc.
Like this:
nc -l 8080
And change the url to your PC/MAC ip and port 8080.
http://192.168.53.250:8080/cgi-bin/sms_send?
And you will see the request in you terminal, to see what all variables will be populated to or not.
This is activated by a simple button which is configured like this.
What I want to achieve is that the name of the user who pushed the button (the user who is logged in) is sent in the payload
show_name: true
show_icon: true
type: button
entity: ""
tap_action:
action: call-service
service: rest_command.sendtestsms
color: deep-purple
icon: mdi:comment-text
name: Send test SMS
Instead of calling the rest command directly, call a script that calls the rest command:
alias: Helper Script for SendSMS Button
description: ""
sequence:
- variables:
get_user: >
{{ (states.person
| selectattr('attributes.user_id', '==', context.user_id)
| map(attribute='name') | first
| default('unknown user')).split(' ')[0] }}
- action: rest_command.sendtestsms
metadata: {}
data:
user: "{{get_user}}"
show_name: true
show_icon: true
type: button
entity: ""
tap_action:
action: call-service
service: script.helper_script_for_sendsms_button
color: deep-purple
icon: mdi:comment-text
name: Send test SMS
Maybe I am not explaining this good enough..
The command itself works, the payload is sent when the button is pressed but where I expect the username variable to be included {{ user }} there is nothing in the payload.
her is what nc returned:
POST /cgi-bin/sms_send HTTP/1.1
Host: 192.168.53.**:9999
User-Agent: HomeAssistant/2026.7.0 aiohttp/3.14.1 Python/3.14
Content-Type: application/x-www-form-urlencoded
Accept: /
Accept-Encoding: gzip, deflate, br
Content-Length: 92
username=CORRECT_USERNAME&password=CORRECT_PASSWORD&text=sent a test SMS&number=CORRECT_PHONE_NO
What I expected to get:
POST /cgi-bin/sms_send HTTP/1.1
Host: 192.168.53.**:9999
User-Agent: HomeAssistant/2026.7.0 aiohttp/3.14.1 Python/3.14
Content-Type: application/x-www-form-urlencoded
Accept: /
Accept-Encoding: gzip, deflate, br
Content-Length: 92
username=CORRECT_USERNAME&password=CORRECT_PASSWORD&text=HOME ASSISTANT USERNAME sent a test SMS&number=CORRECT_PHONE_NO
Sorry, payload looks exactly the same even with the helper script...
Everything is there except for the variable/username...
Allright, so doing this:
rest_command:
sendtestsms:
url: "http://192.168.53.**:9999/cgi-bin/sms_send?"
method: POST
payload: {{user}}
content_type: "application/x-www-form-urlencoded"
I get the HA username is sent, of course now without the rest of the payload...
If that's working, try concatenating it inside the template delimiters.
payload: {{"username=*MYUSERNAME*&password=*MY_PASSWORD*&text="~ user ~" Sent a test SMS&number=*MY_PHONE_NUMBER*"}}
Sorry, no dice... Got this when checking config.
Error loading /config/configuration.yaml: while parsing a flow mapping
in "/config/configuration.yaml", line 58, column 15
expected ',' or '}', but got ''
in "/config/configuration.yaml", line 58, column 68
Allright, I manged to get it solved. This was a weird one...
This is how the variable should have been added to the payload:
rest_command:
sendatestsms:
url: "http://192.168.53.**:9999/cgi-bin/sms_send?"
method: POST
payload: 'username=*SECRET*&password=*SECRET*&text= {{ user }} Sent a test SMS&number=*SECRET*'
content_type: "application/x-www-form-urlencoded"
And it would not work if called directly from the button but using the helper script posted by @Didgeridrew it will work.
alias: script_sendatestsms
description: ""
sequence:
- variables:
get_user: >
{{ (states.person
| selectattr('attributes.user_id', '==', context.user_id)
| map(attribute='name') | first
| default('unknown user')).split(' ')[0] }}
- action: rest_command.sendatestsms
metadata: {}
data:
user: "{{get_user}}"