Rules File Help for ADB FireStick

Are you sure that is the item that is being updated by HABpanel?

Add a logInfo(“test”, “some message”) to the top of the rule.

See

To debug the executeCommandLine calls themselves.

Are the brackets optional? afaik switch would be like

switch (value) {
    case a : { }
    case b : { }
    ...
}

The brackets are optional if the case statement consists of only one line, similar to how they are optional for if statements with only one line.

When checking the logs, the state of my item is being updated by HABPanel. Sample log entry:

2017-08-26 15:19:52.895 [ItemCommandEvent          ] - Item 'ftv1' received command down
2017-08-26 15:19:52.895 [ItemStateChangedEvent     ] - ftv1 changed from next to down

I have a Command type thing that’s input is bound to the item 'ftv1’
Is the ‘command’ field where I should be calling the .rules file? I called the batch files directly from here, and it worked, but obviously since the buttons in HABPanel only have one state, I couldn’t set up a bunch of commands to use as button pushes.

But you wrote the rule to trigger on changes to fireTVStick, not ftv1.

The trigger is the event that causes the role to execute.

I’m sorry, I should have included the new rules file. I updated to 2.1 and did a little bit of housekeeping on the names of my items and things. I changed the rule to ‘ftv1’

rule "FTV Commands"

when
    Item ftv1 received command
then
    switch receivedCommand.toString {
        case "[back]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVBack.bat")
	case "[down]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVDown.bat")
        case "[enter]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVEnter.bat")
        case "[home]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVHome.bat")
        case "[initializeserver]": executeCommandLine("C:\AutoDI\FTVCommands\pressFireTV\FTVInitializeServer.bat")
        case "[left]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVLeft.bat")
        case "[menu]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVMenu.bat")
        case "[next]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVNext.bat")
        case "[playpause]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVPlayPause.bat")
        case "[previous]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVPrevious.bat")
        case "[right]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVRight.bat")
        case "[up]": executeCommandLine("C:\AutoDI\customScripts\FTVCommands\FTVUp.bat")
    }
end

I am now gettinga new error message when I look at the logs:

19:37:42.782 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while executing 'C:\AutoDI\conf\rules\ftvCommands.rules' : 'Cannot run program "C:\AutoDI\conf\rules\ftvCommands.rules": CreateProcess error=193, %1 is not a valid Win32 application'

I don’t have any spaces in the file path that would cause an issue.

You need to escape the \ in the paths perhaps

E.g.

C:\\AutoDI\\customScripts\\FTVCommands\\FTVBack.bat

According to this thread, CreateProcess requires an executable.

A .rules file is not an executable.

Interesting. When I had the Command “thing” directly call and execute the batch files, it worked. I guess I would be able to make a “thing” for each command (each batch file), but would need a way to set the state of the item (used to trigger the command) back to NULL immediately after each trigger.

Use the express binding or use a rule for this.

aspinwalld,

would you share one of you bat files you are using with your firestick. I would love to see an example. Also one of your items.

Sure! I haven’t had time to work on this in a week or so, so don’t have the items bound yet, but the working batch files look something like this:

Initializes ADB: I just run this every night at 3am, and have a HABPanel button that can manually run if needbe.

adb kill-server
adb start-server
adb connect 10.0.88.xxx
adb disconnect

The button push files are like this (this one triggers ‘home’):

adb connect 10.0.88.xxx
adb shell input keyevent 3
adb disconnect

Great thanks a lot. I need to implement something like this as well. Will you also give an example of your items file. I’m sure I can figure it out but for those that want to copy you can you give an example.

I’m still working out what the best logical way to handle items will be. Once I have this fully implemented and working I will create a new topic with step-by-step instructions on getting it working in openHAB and HABPanel (and will link that here).

Great, thanks for sharing. I am differently interested in seeing the finished product.

no luck getting this working better yet?

1 Like

trying to get it working without success, you can give an example of your items file? thanks in advance

I have since moved into a new place and haven’t had much time to work on this. I have quite a bit of time in the upcoming weeks, and plan on nuking the entire automation system and starting from scratch to clean it up. I’ll post in this thread again once I get the system working.

1 Like

I’ve moved since the original thread posts. I plan on starting from scratch in the next few weeks and will further optimize the implementation of this. I’ll post a guide on it once I’ve got it working. (If you don’t see something in this thread by january bug me about it…)

1 Like