I want to start by apologizing for possibly posting under the wrong section, and using all the wrong terms on my following request. With English as a second language is hard for me to find online what I’m looking for due to using the wrong terminology. With that being said, I’ve managed to set up OpenHab successfully, mosquito MQTT client, Habpanel; very simple, very basic, switch-driven Habpanel UI; and I’ve been using it for some time now.
I’m not good at scripting or using any programming language, so I tend to copy and paste a lot, and edit things to my needs.
Brace yourselves, and forgive me for using the wrong terms next:
I have buttons on my habpanel that send httpPost requests, this communicates with my RM Pro (an infrared device) which runs a macro that turns on my tv, receiver, inputs, android box, etc. When clicked the button sends an ON command, and when clicked again an OFF command, which turns all these devices on or off, very basic, very simple. The TV has wifi, and I can bind the ip and see it in OpenHab, so I know when the TV is online or not. Using this I want the button to send an ON command when TV is ‘offline’, and an OFF command when the TV is ‘online’. Why? There is a series of buttons that must be “pressed” in the macro to get the TV to the right input, and they’re different when turning all the devices ON and when turning them OFF, so while the TV is ON, and I’m meaning to turn everything OFF, I don’t want the button to send the ON command. Everything has to be triggered by a click (ngclick type of script?)
Basically I’m looking for something like this:
If TV is 'off’
off = (TV’s ip bind that shows when it’s online or offline)
then if ngclick httpPost (http link here ON)
else
ngclick httpPost (http link here OFF)
in other words: if TV’s wifi is offline then when button is clicked it’ll send the httppost link that turns everything ON, else if the TV is online then if the button is clicked it should send the off httppost link.
Right now I’m managing with two separate buttons, one for OFF, and one for ON. I need one button that can tell when the TV is on or not and send the correct command accordingly (only when clicked)
Guys I hope some of above made sense and that you are able to help and/or provide a sample script that I can use in a template within habpanel. Thank you so much in advance!
EDIT: this is how the two buttons work now. I want it to be one button that checks the TV state and chooses the right command:
<button style="width: 100%; height: 1em;
border: 0; color: green; background: transparent;
font-size: 16px" ng-click="sendCmd('Movie_Mode_On', 'ON')">
<img src="https://home.myopenhab.org/icon/switch?format=svg" style="width:20px;height:20px;"></img>
</button>
<br />
<br />
<button style="width: 100%; height: 1em;
border: 0; color: red; background: transparent;
font-size: 16px" ng-click="sendCmd('Movie_Mode_Off', 'ON')">
<i class="glyphicon glyphicon-off"></i>
</button>
<br />