fields:
minutes:
description: 'The amount of time to wait before turning on the living room lights'
example: 1
but under the delay: part it shows nothing. Thought that might have been a typo, so went ahead and checked the source (to maybe PR that typo), but then it reads:
which isnt transported to the doc example apparently.
So, what does the âfieldâ variable do? Is it merely an explanation of what the minutes variable would do in the script, or is it actually being used by the {{minutes}} template in the script itselfâŚ?
Isnât it what will appear in the dev tools when you select that script?
I think itâs a pointless addition personally, same as description and most of the other âstuffâ thatâs been added to automations and scripts in recent months. No improvement in productivity, and just makes a mess of the configuration for no real purpose.
It lets you pass service data to the script. Look at the notify example, particularly this part:
action:
service: script.notify_pushover
data:
title: 'State change'
message: 'The light is on!'
It lets you pass the title and message to the script instead of putting those data directly in the script so you can use the same script for multiple things.
The fields field is a way to provide documentation for the fields of your script. When you go to the âServicesâ tab of the âDeveloper Toolsâ and select your script there, you should see the description field of the script and a table of the parameters you described with fields.
It has no other purpose than documentation. You do not need to list a parameter in fields in order to be able to use it.
Also the source of the example you checked does in fact have an error, it should be:
Note the {% raw %} and {% endraw %} that Iâve added. The source is actually a template that is processed prior to show the documentation to the user. So the variables that must appear as-is in the final display have to be escaped with raw. If you check other examples in the same page, youâll see they are escaped like this.
also, doing so, would it show a value in the documentation example? It really should because now it just seems to allow an empty delay field, which I would think is an error also.
A very old thread but this is still a problem. I wasted so much time with not understanding why the default values from field always were giving None âŚ
field really is just for docs purposesâŚ