# Asterisk 18.x AMI SetVar with no channel for functions like DEVICE\_STATE()

**URL:** <https://community.asterisk.org/t/asterisk-18-x-ami-setvar-with-no-channel-for-functions-like-device-state/95059>\
**Category:** Asterisk APIs\
**Created:** [December 10, 2022, 2:18pm UTC](https://community.asterisk.org/t/asterisk-18-x-ami-setvar-with-no-channel-for-functions-like-device-state/95059 "2022-12-10T14:18:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkervaski](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/bkervaski/32/4091_2.png) [@bkervaski](https://community.asterisk.org/u/bkervaski)\
**Post date:** [December 10, 2022, 2:18pm UTC](https://community.asterisk.org/t/asterisk-18-x-ami-setvar-with-no-channel-for-functions-like-device-state/95059/1 "2022-12-10T14:18:29Z")

</div>

Hellooooooo!

I’m attempting to set DEVICE\_STATE() with AMI’s SetVar action after receiving the AMI Hangup event.

The channel that triggered the Hangup is no longer available to use with SetVar, however, I don’t need to actual channel to set the device state.

Is there a trick that I’m missing? Perhaps a pseudo channel of some kind that can be used to run functions through AMI?

Thanks for any advice 😃

BK

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [December 10, 2022, 2:21pm UTC](https://community.asterisk.org/t/asterisk-18-x-ami-setvar-with-no-channel-for-functions-like-device-state/95059/2 "2022-12-10T14:21:34Z")

</div>

The channel name isn’t required[1]. If not set then it is considered global, and will run the dialplan function without a channel. The implementation of DEVICE\_STATE itself also does not require a channel.

If you don’t specify a channel, is it not working?

[1] [Asterisk 20 ManagerAction\_Setvar - Asterisk Project - Asterisk Project Wiki](https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+ManagerAction_Setvar)

---

<div class="post-metadata">

**Author:** ![bkervaski](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/bkervaski/32/4091_2.png) [@bkervaski](https://community.asterisk.org/u/bkervaski)\
**Post date:** [December 10, 2022, 2:25pm UTC](https://community.asterisk.org/t/asterisk-18-x-ami-setvar-with-no-channel-for-functions-like-device-state/95059/3 "2022-12-10T14:25:18Z")

</div>

Just checked again and to my chagrin, it is working with no channel … I did test that but must have had a bug as I was getting a “channel not found” response.

Thanks for taking the time to reply on a Saturday morning, it’s much appreciated, sorry to bother ☹

BK

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [January 9, 2023, 2:25pm UTC](https://community.asterisk.org/t/asterisk-18-x-ami-setvar-with-no-channel-for-functions-like-device-state/95059/4 "2023-01-09T14:25:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
