Replacement for physicalgraph.device.HubAction command on ST


I am not a ST or Hubitat developer but have very simple custom apps on my ST installation.
Now I am trying to move some simple smart apps from Smartthings hub to Hubitat.

Obviously there are differences between Hubitat and ST implementation of HTTP requests.

SO now I'm looking for the correct replacement for following command on ST:

> def hubAction = new physicalgraph.device.HubAction(
>     method: method,
>     path: path,
>     headers: headers
>     )
>     sendHubCommand(hubAction)

I know there is documentation below but since I am not a Hubitat developer I really did not understand how to use it. Maybe in time, I can get used to the commands, but for now I need a quick solution to replace the command. Can anybody show me the correct command for this local http request ? Or any example ?

That particular call should work if you just change physicalgraph to hubitat. There are more things you can do, possibly differently than on ST, but I believe that code should work otherwise (assuming that you have method, path, and headers defined somewhere, as must have also been the case with that snippet).

That being said, Hubitat has HTTP methods you can use without using HubAction at all, e.g., httpGet(). The "regular"/synchronous varieties of these should be about equivalent to the HubAction on either platform. Hubitat also has a vareity of asynchttp...() methods that I would strongly encourage you to use instead unless you really need the synchronous behavior (most notably: the async methods won't hold your code up while it waits for a response but instead wake your app/driver back up with the callback method when needed). These are all documented-ish here:

However, for the async calls, this post (by a former staff member, likely the one who wrote the hub code that actually implements these methods) probably has better information:

Good luck!


thanks. that was a very detailed answer.
the simple part " change physicalgraph to hubitat" solved my issue, but I'm sure the rest of your answer will also help me in upcoming days.

now, is it possible to add a custom device template ?
I have a coffee machine device with several buttons for "americano", "capuccino" etc.
how can I display these functions on the dashboard ?

1 Like

now, is it possible to add a custom device template ?
I have a coffee machine device with several buttons for "americano", "capuccino" etc.
how can I display these functions on the dashboard ?

on the device itself, I can see the buttons but not on the dashboard.

I'm not sure what you mean with "device template," but if you mean on Dashboard, no. Hubitat Dashboard can only use the built-in templates, but one of those is the "Attribute" template, which can be used to display the current value of any device attribute (anything under "Current States" on the device page), which you can use if any of the stock templates don't otherwise show what you want. However, there is no corresponding template to allow to to execute a custom command, so you'll need some workaround for that. I assume this is what you are trying to do.

If that is correct, a common workaround is to create a virtual button device--either one device with multiple buttons, or multiple devices with one (or however many) buttons each. You can then add those virtual button devices to the Dashboard using the "Button" template, specify the button number to push (1 or whatever button--depending on how you set this up), and then create an automation to respond to that button event and run your custom command on the "real" device. Button Controller would work well for this, but so would Rule Machine with a "Button Device" trigger. In either case, just create an action for the appropriate button device/event that runs the custom action/command on your device (under "Set Mode or Variables, Run Custom Action," choose "Run Custom Action," any capability you device supports, the device itself, your command, and don't add any parameters unless it needs one--which you'd probably know since you're writing/porting the driver).

how can I add a virtual button device with multiple buttons ?
actually I see a lot of button devices but which one is a multiple button and how can I present it on dashboard with multiple buttons ?

If you create a new virtual device, use the Virtual Button driver. Then, use the preference you'll see in that device to set the number of buttons. A Dashboard tile can only run a single button action, so if that part is where you're getting stuck, you'll need one tile per button number (or button device if you take that approach instead); you can specify the button number to push after you choose the button template in Dashboard. It should also be noted that push commands are the only ones you can directly run from Dashboard (not hold or release, for example).

and push buttons dont work well in the dashboard as there is no depress/release graphic to show the button press.

that said i still use it for my tesla dashboard as it makes the rule easier to write and i don't need 20 different virtual buttons.


what's the point of setting multiple buttons to a virtual button if we can't show multiple buttons on a tile ?
I mean, I can understand that it can be used with multiple tiles for each button, but is there an advantage of doing that over creating a new button for each command and assigning each button to a tile ?

also, instead of creating a button for each action on my device, would it be possible to convert my actions to something which could be called through a button tile ?
this way , I wouldn't need to create a virtual device ?

I didn't understand this (well maybe because English is not my native language)
what do you use , and recommend to use ?

It's your choice if you want one virtual button with multiple buttons or just separate virtual button devices; the advantage of the former is that you only need to create one button device and can also configure its actions in a single Button Controller or Rule app instance. I'm not sure if this was clear before: you can't use the same tile with multiple buttons (Hubitat Dashboard is basically one device per tile, regardless of what kind of device), but you can use the same button device on multiple tiles, and they can do different things if you use different button numbers (and have those button numbers tied to different actions in your app or rule).

This reminds me of a "trick" some people use on their Dashboards, by the way: make it twice as tall (double the number of rows) as you want, then make most tiles have a height of 2. Then, when you make a tile have a height of 1 put a similarly configured tile underneath, it looks like you have two "half" tiles. If you want to make it look like you have two buttons on one tile, this may help you.

Sort of: a tile with template "Button" can only run the "Push" command on a device (this takes one number, the button number, as a parameter). To get virtual buttons out of the picture, your driver would have to implement, at least, the "PushableButton" capability and then push() command and associated attribute. Alternatively, you can use "standard" commands from other capabilities with the device in the first place so you can use more common templates that can call your desired command directly. For example, the "Switch" template can call the "On" or "Off" commands (depending on the current state), which you could have on a driver that implements the "Switch " capability. With custom commands,Ike you have in this driver, you habe to find ways to make it work, with virtual buttons and rules to make those virtual buttons call your custom commands being one way.

1 Like

You can also use Tile Master 2 to create a custom tile that can handle multiple devices on one tile.
One of my tiles has 3 locks on it and I can touch just one part of the tile to open or close a particular lock.

well, this is a good solution without additional virtual devices.
can I use one push() command and call several functions in my driver according to the button number parameter ?
if yes, can you give me a short example ?
is it like this :

push(buttonnumber) {
if (buttonnumber==1) {
if (buttonnumber==2) {
if (buttonnumber==3) {

since I already have on() and of() functions for power on/off of the coffeemachine, I can't use switch functions for other purpose.

btw, there is a "tile master" app here:

with following description:
"Create a tile with multiple devices and customization options."

do you know anything about it ?
would it help about multiple tiles in one tile ?

what is that Tile Master 2 ?
where can I find it ?

You can! And what you wrote is almost exactly what you'd want to do. :slight_smile: (In fact, assuming you have methods like makecapuccino() defined in your driver, that would work, but capitalization matters, and something like makeCapuccino() is more common and will display a bit better in the Hubitat UI.)

But since you know that only one of the conditions will be true, you could do something like this instead:

void push(buttonNumber) {
  if (buttonNumber == 1) {
  else if (buttonNumber == 2) {
  else if (buttonNumber == 3) {
  else {
    log.error "Invalid button number $buttonNumber specified in push()"


or just rule like this

it worked. thanks.

I just had to;
add capability and command :

capability "PushableButton"
command "push"

AND put the parameter in quotes like:

void push(buttonNumber) {
  if (buttonNumber == "1") {
  else if (buttonNumber == "2") {
  else if (buttonNumber == "3") {
  else if (buttonNumber == "4") {
  else {
    log.error "Invalid button number $buttonNumber specified in push()"

it works :slight_smile:

btw, is it possible to change the name off the button from "Button 1" to "Espresso" ?

what is that Tile Master 2 ?
where can I find it ?

It’s a user-contributed app.

I usually have code to handle integer inputs as well as string inputs in my PushableButton drivers. As you noticed (by having to put quotes around the button numbers), the data is supplied to your push() handler as a string.

You can put anything in for the button 'number' in a dashboard tile configuration, so if you handle possible string inputs values in your driver it will just work.

But Rule Machine only allows an integer input for button number.

My point is: it depends on which apps you will want to use to interact with your driver whether or not you can refer to the button by a name instead of a number.

1 Like