<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Automation could not be saved when using multiple &amp;quot;for&amp;quot; commands in Smart Home Developer Forum</title>
    <link>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Automation-could-not-be-saved-when-using-multiple-quot-for-quot-commands/m-p/774289#M11253</link>
    <description>&lt;P&gt;Well, I turned to Gemini for help. It first recommended exactly how I wrote my script. I didn't give it my current script, just explained what I was trying to accomplish and it spit out what I already wrote. When I explained this fails to save, one of the 3 alternative options it gave me was to write a separate script for each sensor. another alternative as to only rely on 1 sensor for the time duration and I forgot the 2nd alternative, but it wasn't as functional.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway... the "separate script" path should work but it's not as clean. Basically, I added a Starter - sensor 1, then the conditions and actions in the script, followed by Starter - Sensor 2, then the exact same conditions and actions; then the same with the 3rd sensor. Basically, 1 script combining all 3 as if they're separate scripts - if that makes sense.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I don't like is if I decide to adjust the actions (add or remove smart devices to control), I have to remember to adjust those for each sensor within the script.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just wrote it, but haven't tested it yet. Logically, it should work. So we'll see.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Dec 2025 22:50:39 GMT</pubDate>
    <dc:creator>Gk1984</dc:creator>
    <dc:date>2025-12-18T22:50:39Z</dc:date>
    <item>
      <title>Automation could not be saved when using multiple "for" commands</title>
      <link>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Automation-could-not-be-saved-when-using-multiple-quot-for-quot-commands/m-p/772557#M11225</link>
      <description>&lt;P&gt;I'm writing a script to turn lights off when multiple presence sensors show unoccupied for 30 min. I have the script written just fine - I'm pretty comfortable here. The issue is when I add "for: 30min" to my starters, the "Routine Could Not Be Saved" error appears. Perhaps I'm misusing the "for" command?&lt;/P&gt;&lt;P&gt;I'm able to add "for: 30 min" to one of my presence sensor starters, but as soon as I add a second or 3rd for my additional sensors, I'm no longer able to save the automation. Would that mean "for" affects&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;all&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the starters? Or am I right to assume it's only counting the sensor I've "attached it to?"&lt;/P&gt;&lt;P&gt;Below is my script when I add the "for" command for each starter. I did try moving "for" in a different order within each starter too, but that doesn't seem to make a difference.&lt;/P&gt;&lt;P&gt;Is there perhaps a better way to turn off the devices when there's no occupancy for 30 minutes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# ------------------------------------------------------------------------------------------ #&lt;/P&gt;&lt;P&gt;# Lines starting with “#” are comments and will be ignored by the automation.&lt;/P&gt;&lt;P&gt;# Indentation determines hierarchy within the script.&lt;/P&gt;&lt;P&gt;# Visit&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://g.co/home/script-editor-docs" target="_blank" rel="noopener nofollow noreferrer ugc"&gt;g.co/home/script-editor-docs&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for full documentation.&lt;/P&gt;&lt;P&gt;# ------------------------------------------------------------------------------------------ #&lt;/P&gt;&lt;P&gt;metadata:&lt;/P&gt;&lt;P&gt;name: Basement off when no presence detected # Choose a short name that summarizes important starters and actions, like “Sunset lights”.&lt;/P&gt;&lt;P&gt;description: Turn off basement devices when no presence is detected for 30 minutes # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”&lt;/P&gt;&lt;P&gt;automations:&lt;/P&gt;&lt;P&gt;# “starters” and “actions” are required; “conditions” are optional.&lt;/P&gt;&lt;P&gt;# Use Ctrl + Space to see autocomplete suggestions.&lt;/P&gt;&lt;P&gt;# ---- STARTERS ---- #&lt;/P&gt;&lt;P&gt;# Starters describe events that will start the automation.&lt;/P&gt;&lt;P&gt;# To add more than one starter, duplicate the "- type" section under "starters".&lt;/P&gt;&lt;P&gt;# If you add multiple starter events, any one of them happening will start the automation.&lt;/P&gt;&lt;P&gt;starters:&lt;/P&gt;&lt;P&gt;- type: device.state.OccupancySensing # For devices that can detect occupancy, whether through PIR, ultrasonic, or physical contact sensing.&lt;/P&gt;&lt;P&gt;state: occupancy&lt;/P&gt;&lt;P&gt;# Whether the device senses occupancy. [available operators: is, isNot]&lt;/P&gt;&lt;P&gt;is: UNOCCUPIED&lt;/P&gt;&lt;P&gt;device: Bar presence sensor - Bar&lt;/P&gt;&lt;P&gt;for: 30min&lt;/P&gt;&lt;P&gt;- type: device.state.OccupancySensing # For devices that can detect occupancy, whether through PIR, ultrasonic, or physical contact sensing.&lt;/P&gt;&lt;P&gt;state: occupancy&lt;/P&gt;&lt;P&gt;# Whether the device senses occupancy. [available operators: is, isNot]&lt;/P&gt;&lt;P&gt;is: UNOCCUPIED&lt;/P&gt;&lt;P&gt;device: Basement main presence sensor - Basement&lt;/P&gt;&lt;P&gt;for: 30min&lt;/P&gt;&lt;P&gt;- type: device.state.OccupancySensing # For devices that can detect occupancy, whether through PIR, ultrasonic, or physical contact sensing.&lt;/P&gt;&lt;P&gt;state: occupancy&lt;/P&gt;&lt;P&gt;# Whether the device senses occupancy. [available operators: is, isNot]&lt;/P&gt;&lt;P&gt;is: UNOCCUPIED&lt;/P&gt;&lt;P&gt;device: Basement presence sensor - Basement Living Room&lt;/P&gt;&lt;P&gt;for: 30min&lt;/P&gt;&lt;P&gt;# ---- CONDITIONS ---- #&lt;/P&gt;&lt;P&gt;# Conditions are optional. Delete this section if it’s empty.&lt;/P&gt;&lt;P&gt;# Conditions will prevent an automation from starting if the conditions aren’t met.&lt;/P&gt;&lt;P&gt;# See&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://g.co/home/script-editor-docs" target="_blank" rel="noopener nofollow noreferrer ugc"&gt;g.co/home/script-editor-docs&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for documentation about how to use logical operators like “and”, “or”, and “not”.&lt;/P&gt;&lt;P&gt;condition:&lt;/P&gt;&lt;P&gt;type: and&lt;/P&gt;&lt;P&gt;# "AND" together two or more conditionals&lt;/P&gt;&lt;P&gt;conditions:&lt;/P&gt;&lt;P&gt;- type: device.state.OccupancySensing # For devices that can detect occupancy, whether through PIR, ultrasonic, or physical contact sensing.&lt;/P&gt;&lt;P&gt;state: occupancy&lt;/P&gt;&lt;P&gt;# Whether the device senses occupancy. [available operators: is, isNot]&lt;/P&gt;&lt;P&gt;is: UNOCCUPIED&lt;/P&gt;&lt;P&gt;device: Bar presence sensor - Bar&lt;/P&gt;&lt;P&gt;- type: device.state.OccupancySensing # For devices that can detect occupancy, whether through PIR, ultrasonic, or physical contact sensing.&lt;/P&gt;&lt;P&gt;state: occupancy&lt;/P&gt;&lt;P&gt;# Whether the device senses occupancy. [available operators: is, isNot]&lt;/P&gt;&lt;P&gt;is: UNOCCUPIED&lt;/P&gt;&lt;P&gt;device: Basement main presence sensor - Basement&lt;/P&gt;&lt;P&gt;- type: device.state.OccupancySensing # For devices that can detect occupancy, whether through PIR, ultrasonic, or physical contact sensing.&lt;/P&gt;&lt;P&gt;state: occupancy&lt;/P&gt;&lt;P&gt;# Whether the device senses occupancy. [available operators: is, isNot]&lt;/P&gt;&lt;P&gt;is: UNOCCUPIED&lt;/P&gt;&lt;P&gt;device: Basement presence sensor - Basement Living Room&lt;/P&gt;&lt;P&gt;# ---- ACTIONS ---- #&lt;/P&gt;&lt;P&gt;# Actions will start when a starter event takes place and all conditions are met.&lt;/P&gt;&lt;P&gt;# Actions will start in the order they appear in the script and with any delay specified.&lt;/P&gt;&lt;P&gt;# To add more than one action, duplicate the "- type" section under "actions".&lt;/P&gt;&lt;P&gt;actions:&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: false&lt;/P&gt;&lt;P&gt;devices: Basement Lights - Basement&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: false&lt;/P&gt;&lt;P&gt;devices: Bar Switch - Bar&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: false&lt;/P&gt;&lt;P&gt;devices: Basement Living Room Lights - Basement Living Room&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: false&lt;/P&gt;&lt;P&gt;devices: Laundry room Lights - Laundry room&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: false&lt;/P&gt;&lt;P&gt;devices: Basement Roku - Basement&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: false&lt;/P&gt;&lt;P&gt;devices: Bar Roku - Bar&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: false&lt;/P&gt;&lt;P&gt;devices: Fireplace outlet - Basement Living Room&lt;/P&gt;&lt;P&gt;- type: time.delay&lt;/P&gt;&lt;P&gt;# Adjust duration as needed. Supported units: sec, min, hour&lt;/P&gt;&lt;P&gt;for: 5sec&lt;/P&gt;&lt;P&gt;- type: device.command.OnOff # Turn the device on or off.&lt;/P&gt;&lt;P&gt;# Whether to turn the device on or off.&lt;/P&gt;&lt;P&gt;on: true&lt;/P&gt;&lt;P&gt;devices: Fireplace outlet - Basement Living Room&lt;/P&gt;</description>
      <pubDate>Fri, 12 Dec 2025 15:25:56 GMT</pubDate>
      <guid>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Automation-could-not-be-saved-when-using-multiple-quot-for-quot-commands/m-p/772557#M11225</guid>
      <dc:creator>Gk1984</dc:creator>
      <dc:date>2025-12-12T15:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Automation could not be saved when using multiple "for" commands</title>
      <link>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Automation-could-not-be-saved-when-using-multiple-quot-for-quot-commands/m-p/774289#M11253</link>
      <description>&lt;P&gt;Well, I turned to Gemini for help. It first recommended exactly how I wrote my script. I didn't give it my current script, just explained what I was trying to accomplish and it spit out what I already wrote. When I explained this fails to save, one of the 3 alternative options it gave me was to write a separate script for each sensor. another alternative as to only rely on 1 sensor for the time duration and I forgot the 2nd alternative, but it wasn't as functional.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway... the "separate script" path should work but it's not as clean. Basically, I added a Starter - sensor 1, then the conditions and actions in the script, followed by Starter - Sensor 2, then the exact same conditions and actions; then the same with the 3rd sensor. Basically, 1 script combining all 3 as if they're separate scripts - if that makes sense.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I don't like is if I decide to adjust the actions (add or remove smart devices to control), I have to remember to adjust those for each sensor within the script.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just wrote it, but haven't tested it yet. Logically, it should work. So we'll see.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Dec 2025 22:50:39 GMT</pubDate>
      <guid>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Automation-could-not-be-saved-when-using-multiple-quot-for-quot-commands/m-p/774289#M11253</guid>
      <dc:creator>Gk1984</dc:creator>
      <dc:date>2025-12-18T22:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Automation could not be saved when using multiple "for" commands</title>
      <link>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Automation-could-not-be-saved-when-using-multiple-quot-for-quot-commands/m-p/775272#M11372</link>
      <description>&lt;P class="p1"&gt;Thanks for reaching out. &lt;STRONG&gt;For&lt;/STRONG&gt; can only be applied to individual &lt;STRONG&gt;starters&lt;/STRONG&gt; or used within a time.delay &lt;STRONG&gt;action&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P class="p1"&gt;Could you try removing&amp;nbsp;&lt;STRONG&gt;for&lt;/STRONG&gt; from starters and add it to &lt;STRONG&gt;Actions.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="hljs-attr"&gt;actions:&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="hljs-bullet"&gt;-&lt;/SPAN&gt; &lt;SPAN class="hljs-attr"&gt;type:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;time.delay&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="hljs-attr"&gt;for:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;30min&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN class="hljs-comment"&gt;# Only runs if the conditions remained true for the full 30 mins&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="hljs-comment"&gt;&lt;SPAN class="hljs-bullet"&gt;-&lt;/SPAN&gt; &lt;SPAN class="hljs-attr"&gt;type:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;device.command.OnOff&lt;/SPAN&gt; &lt;SPAN class="hljs-attr"&gt;on:&lt;/SPAN&gt; &lt;SPAN class="hljs-literal"&gt;false&lt;/SPAN&gt; &lt;SPAN class="hljs-attr"&gt;devices:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;Basement&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;Lights&lt;/SPAN&gt; &lt;SPAN class="hljs-bullet"&gt;-&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;Basement&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="hljs-comment"&gt;# ... add your other devices here&lt;BR /&gt;&lt;BR /&gt;Let me know if these worked.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Dec 2025 21:32:35 GMT</pubDate>
      <guid>https://www.googlenestcommunity.com/t5/Smart-Home-Developer-Forum/Automation-could-not-be-saved-when-using-multiple-quot-for-quot-commands/m-p/775272#M11372</guid>
      <dc:creator>arm_dpe</dc:creator>
      <dc:date>2025-12-22T21:32:35Z</dc:date>
    </item>
  </channel>
</rss>

