I am trying to get an automation with a template running. I have a hardcoded, working version that does not use a template. I am struggling to reproduce one line that contains single quotes in my Action (everything else works).
The goal is to get this line, with single quotes around the number:
- region_id: '3'
Assume that trigger.payload is set to βroom_oneβ.
When using "{{ iif( trigger.payload == 'room_one', '3', '999') }}", I get no quotes around my 3:
- region_id: 3
When I escape like this region_id: "{{ iif( trigger.payload == 'room_one', '\\'3\\'', '999') }}", I get triple quotes:
- region_id: '''3'''
I didnβt manage to get just single quotes. Thanks for any hints.
I think it is not enough. With your suggestion, the autromation is executed, my device (a roomba) received the command and beeps but does not execute the action. I guess it is the quotes, because the hardcoded version with the quotes works.
The first suggestion gives me a parse error when saving the automation. I think this is not a case of yaml escaping, as for yaml everything is inside double quotes anyway. It seems to be a case of jinja excaping, hence my try with the backslashes.
The second suggestion is not what I need. I need an output with singke quotes, but no matter what I try, in the trace I see only either no single quotes or triple single quotes, as described in my original post.
I did. I donβt want trigger.payload to match "'room_one', '3', '999'", I want to get a β3β if trigger.payload matches room_one, elser a β999β.
I tried barious combinations of escaping, using > and a separate line, all to no avail. I either get no single quotes around my 3, or triple single quotes, or even 5 single quotes, but not β3β.
The vacuum works this way. It seems a big hack, if I give the number as a int or string it fails. When a 0 is added before the number, it seems to see that it needs ββ to keep it the same