# Device Enable on remote gateway?

**URL:** <https://forum.inductiveautomation.com/t/device-enable-on-remote-gateway/17974>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [May 9, 2018, 5:20pm UTC](https://forum.inductiveautomation.com/t/device-enable-on-remote-gateway/17974 "2018-05-09T17:20:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AIO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aio/32/87549_2.png) [@AIO](https://forum.inductiveautomation.com/u/AIO)\
**Post date:** [May 9, 2018, 5:20pm UTC](https://forum.inductiveautomation.com/t/device-enable-on-remote-gateway/17974/1 "2018-05-09T17:20:15Z")

</div>

Hey folks,

We’re running a remote gateway as our tag provider, and I would like to allow maintenance to enable / disable devices on the remote gateway from the client.

I can use `system.device.setDeviceEnabled(device, bool)` on the local gateway, but cannot figure out how to pass this command to the remote gateway.

Is this possible?

Cheers,  
Andrew

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 9, 2018, 5:59pm UTC](https://forum.inductiveautomation.com/t/device-enable-on-remote-gateway/17974/2 "2018-05-09T17:59:52Z")

</div>

You can use [`system.util.sendMessage`](https://docs.inductiveautomation.com/display/DOC79/system.util.sendMessage) to send messages between gateways over the gateway network - which you would need to combine with a message handler on the receiving gateway that would then execute the setDeviceEnabled command.

---

<div class="post-metadata">

**Author:** ![AIO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aio/32/87549_2.png) [@AIO](https://forum.inductiveautomation.com/u/AIO)\
**Post date:** [May 9, 2018, 6:02pm UTC](https://forum.inductiveautomation.com/t/device-enable-on-remote-gateway/17974/3 "2018-05-09T18:02:40Z")

</div>

Thanks PG, I’ll give it a shot and see where I wind up.

---

<div class="post-metadata">

**Author:** ![AIO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aio/32/87549_2.png) [@AIO](https://forum.inductiveautomation.com/u/AIO)\
**Post date:** [May 9, 2018, 7:03pm UTC](https://forum.inductiveautomation.com/t/device-enable-on-remote-gateway/17974/4 "2018-05-09T19:03:00Z")

</div>

Here’s where I wound up. I was having hard time getting the bool to convert properly, thus the if/elif statement in the message handler. If you have any recommendations to improve the script or handle that boolean, I’d be happy to hear it.

## Message Script

```auto
admin='Administrator'
mechanic='Mechanic'
dataIn=system.dataset.toPyDataSet(event.source.Roles)
i=0
security = 0

for row in dataIn:
  if row['Rolename'] == admin or row['Rolename'] == mechanic:
    security=1
    break
  i+=1

if security == 1: 
	device = event.source.parent.getComponent('Container').getComponent('Label').text
	state = event.source.parent.getComponent('Container').getComponent('Dropdown').selectedValue
	
	project= "Transaction_Groups"
	messageHandler = "deviceMessages"
	message = {'device': device, 'state': state, 'security': security}
	scope = "G"
	server = ["Ignition"]
	
	system.util.sendMessage(project=project, messageHandler=messageHandler, payload=message, scope=scope, remoteServers=server)
else:
	system.gui.warningBox('User not authorized to make changes', 'Error')

```

## Message Handling

```auto
	first = payload['first']
	second = payload['second']
	if second > 0:
		bool = 1
	elif second < 1:
		bool = 0
	system.tag.write('Gateway_First', first)
	system.tag.write('Gateway_Second', bool)
	system.device.setDeviceEnabled(first, bool)

```
