Using of " "

Hi All,

First of all Happy late Xmas :smiley:

I rewrite my yaml files to make them nice and clean.
Im testing now to do it this way:

---
platform: "ping"
host: "192.168.100.26"
scan_interval: "60"
name: "MQTT Server"

instead of:

---
platform: ping
host: 192.168.100.26
scan_interval: 60
name: "MQTT Server"

everything between " ". It seems to work correct. When I open de configurator I see nice 2 colors, so easy to understand.

BUT: Will it give problems when I do this for all my yaml files? Or do you have a good reason not to do this?

Greets

Ah, i also want to know this…
I never know if i should use single quotes, double quotes or nothing.
Is there some general rule on this?

As far as I know there is no general rule on how to do this.

I can only tell you how I do it:

  • numbers → no quotes
  • time → quotes
  • text without special characters or whitespace → no quotes
  • text with special character or whitespace → quotes
  • value “on” or “off” → quotes, because otherwise HA doesn’t recognize it correctly

In my opinion the second example you showed looks cleaner and nicer than the one you propose, but that’s just my view. And to be honest, I don’t really care whether there are quotes around a string or not as long as the thing works as intented.

I think it’s not necessary, it will not provide any additional value for you or others reading your code and therefore I see it as a thing to do, when you have nothing else to do. I care more about readability of my code.

Thanks for the answer. Then I leave it how it is now. This is how I have everything

  • numbers -> no quotes
  • time -> quotes
  • text without special characters or whitespace -> quoted
  • text with special character or whitespace -> quotes
  • value “on” or “off” -> quotes, because otherwise HA doesn’t recognize it correctly

all text between quotes.

:smiley:

1 Like

All states are stored as strings so really the only critical one is this:

text with special character or whitespace -> quotes

This incluedes:

time -> quotes

As it has special characters ( : ).

2 Likes

How about on/off do they need to be in quotes or not? I remember something that you need to enclose them in brackets, maybe I’m mixing things up here.

yes you add them between " "

Oh yeah them too.

on, off, true, false, are reserved words.

1 Like

As long as it doesn’t break these rules:

https://yaml.org/spec/1.2/spec.html

you should be ok