I am in the process of transferring my HA configuration to a new server and cleaning things up along the way. I had a script that would send an SMS using the Joaoapps Join component. The script should send the information from a sensor I create called sensor.shopping_list. I know the Joaoapps component is working correctly because I can send a simple text, but it fails if I try to send Template Data. The following script worked in my previous HA install but now fails.
send_shopping_list_via_sms:
alias: Text Shopping List
sequence:
- service: joaoapps_join.myphone_send_sms
data_template:
number: 8675309
message: 'Shopping List:
{{ states(''sensor.shopping_list'') }}'
The following errors appear in the log:
can only concatenate str (not âintâ) to str
can only concatenate str (not âdictâ) to str
can only concatenate str (not âNoneTypeâ) to str
can only concatenate str (not âintâ) to str
previous HA instance was: 0.106.6
New instance is: 0.107.0
This should be fine. Quotes can be used for multi line strings. I would recommend using a block scalar, though it isnât needed (it looks better and does some extra formatting for you). That website shows you all the different once you can do. In your case, Iâd use the block literal and strip newlines at the end (|-). This will preserve all newlines you put in (so the one between Shopping List and the actual list, and remove any empty lines at the end in case sensor.shopping_list has them.
send_shopping_list_via_sms:
alias: Text Shopping List
sequence:
- service: joaoapps_join.myphone_send_sms
data_template:
number: "8675309"
message: |-
Shopping List:
{{ states('sensor.shopping_list') }}
But this doesnât answer your question. Looking at the documentation, in their example, number is passes with quotes. Iâd try adding quotes around the phone number maybe? Itâs complaining that it canât append a number to a string. The sensor.shopping_list is a string for sure, so my guess is the phone number is the âintâ itâs complaining about.
I believe itâs something to do with the fancy quotes around sensor.shopping_list
That one bugged me forever! The dang gui does single quotes for everything.
But I later learned that a double single quote is perfectly valid and evaluates to a single quote in yaml.
In double quoted strings if you need to include a literal double quote in your string you can escape it by prefixing it with a backslash \ (which you can in turn escape by itself). In single quoted strings the single quote character can be escaped by prefixing it with another single quote, basically doubling it. Backslashes in single quoted strings do not need to be escaped.
So a double single quote is essentialy escaping the quote for you. It keeps the parsing simpler as they donât need to keep track of double/single quotes and can just put single quotes around everything. Further, the \ doesnât need to be escaped in single quote strings.
It does make some ugly output though with all those double single quotes!