|  Developer
Updated on December 2, 2022

function/pulse

  • The PULSE function allows generating a sequence of state transitions for the when block while its children are in the state. The function keeps as the output of a when block for a specified duration and then switches to for another period and it repeats a certain number of times. The duration of states is fixed and is always the same even if the condition of a when block becomes unsatisfied. When the condition is no longer satisfied – the function immediately exits in .

Parameters

Field Type Required Description
blockOptions.function.pulse object Settings of a PULSE function.
blockOptions.function.pulse.truePeriod object + Time in seconds for saving state of condition. Should be positive.
blockOptions.function.pulse.falsePeriod object Time in seconds for saving state of condition after timeout. Should be non-negative. Optional, default is seconds.
blockOptions.function.pulse.times int How many pulses should be generated. Should be positive. Optional, if not specified the function will produce the pulses infinitely.
  • If all function’s children become , the operator becomes instantly. is held as the output of the function operator for seconds regardless of children’s state changes. The function operator immediately cancels the pulse generation in if any child switches to state during the period or if it already switched to during the last .
  • For example, we have a switch and a siren. We want to force the siren to make a sound for 30 seconds 5 times with 20 seconds delay between activations, while the switch is ON. In this case, we should set the pulse.truePeriod to 30 seconds, the pulse.falsePeriod to 20 seconds, the pulse.times to 5, and add a when block checking if the state of the switch is ON. So the function will generate a 30-second output, followed by a 20-second output 5 times while the switch is in ON state.
  • NOTE: The PULSE function state is not saved between the scene service restarts, so, the function operator should not be used to handle large periods of time like hours and days. It is only intended to handle periods in seconds.

This feature is available since advanced_scenes/1.29.
The default behavior for the case when the “times” param is not specified was changed in . In prior versions absent “times” parameter was leading to generating of single transition to “true”.

Examples:

				
					{
   "blockOptions":{
        "method":{
            "args":{
                "blocks":"blocks"
            },
            "name":"function"
        },
        "function": {
            "pulse":{
                "truePeriod": 30,
                "falsePeriod": 20,
                "times": 5
            }
        }
    },
    "blockType":"when",
    "fields":[
        {
            "name":"blocks",
            "type":"blocks",
            "value": [
                __WHEN_BLOCK__, ..., __WHEN_BLOCK__
            ]
        }
    ]
}				
			

Here, the stands for any valid when block, like a final event or a logical operator.