Skip to content
Download

Toggle Flashlight

Turns the camera torch (flashlight) on, off or to the opposite of its current state.

An action in the Device Settings group. Its type is action.flashlight.

Port Label Flow Type
in in execution in
out out execution out
state state data out Object{enabled: Boolean, changed: Boolean}
Field Key Default Notes
State state on on, off, toggle

Toggle Flashlight drives the camera torch and reports what happened on its state port. It can set the torch on, set it off, or flip it to the opposite of whatever it is now.

  • State is the whole of the configuration: On, Off or Toggle.
  • The state output carries enabled (whether the torch is now lit) and changed (whether the system accepted the change).
  • It needs the camera grant. Without it the torch does not light and changed is false.
  • On and Off ask for that state outright, whatever the torch was doing.
  • Toggle first reads the torch through the same channel value.torch uses, then asks for the opposite.
  • The request goes to the first camera on the phone that has a flash unit.
  • The node pulses out either way. A torch that would not light does not stop the macro.
  • Add your trigger, then a Toggle Flashlight with State set to Toggle.
  • Wire the trigger into it.
  • Wire out into a Delay of 500 ms, then into a second Toggle Flashlight set to Off.

Explanation:

  • One button both lights and darkens, because Toggle reads before it writes.
  • The second node is set to Off rather than Toggle, so the macro cannot leave the torch lit if the first flip was already a darkening.

The other device switches - Wi-Fi, Bluetooth, Auto-rotate - offer On and Off only. Each of them writes a setting it is never told the previous value of, so a Toggle there would have nothing to invert. The torch is the one that has a reader behind it.

Toggle needs an answer to “is it lit right now?”, and three things leave that unanswered.

  • The phone has no flash unit.
  • Another app holds the camera.
  • The app has only just started and Android has not reported a torch mode yet.

The node then touches the torch not at all, writes a warning to the console, and reports changed as false. It does not guess a direction, because a guess is a coin flip that looks like a working macro. On and Off are unaffected: they need no reading.

  • changed is the field to branch on when it matters whether the torch actually moved. enabled is what the node asked for and got.
  • The torch stays lit after the macro ends. Nothing turns it off for you.
  • Reading the torch back is value.torch, which needs no permission of its own.
  • A torch lit from the quick-settings tile is seen by Toggle exactly as one lit by a macro.