Switch state from network binding combined with wake-on-lan action

Thank you Russ. Seems very useful, but I do not know how to use HTTP GET. Is the HTTP binding the one to use? What do I need to do? Thanks for the support.

sendHttpGetRequest is one of the core actions. Call it in a rule and insert the URL from RSM.

Thank you. Do I have to use DSL script or may I use blokly to create the rule?

A quick search for “sendHTTP Blockly” provides an answer:

Thank you. Was not sure if that was pertinent to my case as it requires the installation of OH4.2 Still not sure what I need to do, but will give it a shot. Thanks for now.

If you don’t want to install a milestone or wait for the upcoming official release of 4.2, try inserting the code into an inline-script block. I haven’t used Blockly much yet, so I don’t know how that works.

Alternatively, you can make a UI rule with a script action.

Finally I managed with the script in DSL and with the help of ChatGPT. Still necessary to know Java scripting and unfortunately one of the bigest limits of Openhab is exactly that: if you are not familiar with Java there are no examples showing what to do. Still like Openhab overall, but at times it can be daunting. Thank you for your help. Your hints pointed me in the right direction.

What did you need Java for? I don’t know any Java.

For a UI rule, you’d just insert the command into a DSL script. I thought you can do the same with the script block, but maybe I’m wrong about that.

As wrote my knowledge of these langauges is NULL. DSL or Java for me are just the same. The script is a little more complex than just copying the GET command into a string. I ended up with

val result = sendHttpGetRequest(“http://xxx.xxx.xxx.xxx:5001/”)
logInfo(“HTTP Response”, "Received: " + result)

I initially thought it would be sufficient to use the sendHTTP command without any other line of code. This is were I find it a little difficult to interact with the community as everyone presumes you are at a certain level with coding / understanding of the programming language.
Anyhow, I managed with getting it working also with your help. Maybe you can help me with send ssh instructions to a device :slight_smile: Have a good weekend

Hi folks

Old reply but this is exactly what I would like to do. Today I have one status item and one switchitem mapped to commands wol and shutdown and rules for it, bjt how could I really combine this into one item.

As far as I know, it is. Here’s what I have in my DSL rule:

sendHttpGetRequest("http://xxx.xxx.xxx.xxx:5001/password/suspend")

That’s pretty much what’s in the docs I pointed you to. Hence, I didn’t feel it necessary to provide an example.

I don’t expect anyone to know more than I do, and all I know is some basic HTML and the DSL I’ve cobbled together from searching the community.

When people ask questions without showing their work, it starts to feel like they just want us to do the work for them…even if that’s not actually true. That’s when a lot of frustration happens, because no one is getting what they need to move the conversation forward.

To avoid this sort of misunderstanding, my friendly advice is to provide more detail in your posts. If you had shown what you tried earlier and explained your thought process, then I could immediately see where you’ve gone awry and offer a correction. Without that, I could only respond to the questions you asked.

This may seem inconsistent, because there are times when community members do provide extensive answers without being given much of a starting point. I can’t speak for others, but in my case it directly relates to how much time I have available at the moment. If I want to help someone but I’m particularly busy, a quick question is going to get a quick answer.

Bottom line is that if you show us your work, we’ll have a better understanding of where you’re going wrong, and no one will need to make assumptions. :wink:

Sorry, I have no idea how to do this. If you figure it out, I’d be interested to learn the solution.

Thanks Russ for the suggestions on how to go about requesting for support. I surely will bear that in mind in my future requests. I may start a new thread on the SSH issue and see if anyone is willing to help. Thank you again for your patience. I always appreciate the time and effort that someone puts in in explaining and helping out.

1 Like

It’s really easy :slight_smile: just link all channels needed to one Item, like this:

Thing vdr:vdr:vdrServer "vdr Server" [
    host="192.168.178.15",
    port=6419,
    refresh=30
]
Thing network:pingdevice:vdrserv "NH vdr Server" [
    hostname="192.168.178.15",
    port=0,
    retry=1,
    timeout=5000,
    refreshInterval=60000,
    macAddress="01:23:45:67:89:ab"
]

and the Item:

Switch VDR_FF_Server_Power "VDR Server Power" {channel="vdr:vdr:vdrServer:power", channel="network:pingdevice:vdrserv:online", autoupdate="false"}

So the ON-command will be sent as WOL through the network addon, and the OFF-command will be sent through the vdr addon.

Notation is “old style” but it’s the same story via Main UI, the trick is to use just one Item.

1 Like

I prefer old style easier for maintanence atleast for me.

My head was a little bit wrong I had a String Item called PC status and the rule for it work but I guess I can’t get a status with dynamic icon to work with a String item.

Can VDV addon shutdown windows computers? I uses IOT link for now and network bindning for wol.

Maybe even that is possible to skip rule if I combine the mqtt send command for switch == OFF and WOL for on and ping for icon?

rule "HTPC WOL and shutdown"
when
	Item WZ_PC_Command received command
then
    if(receivedCommand=="shutdown")
        {
        logInfo("mqtt", "regel triggad")
        val actions = getActions("mqtt","mqtt:broker:bc3e71556e")
        actions.publishMQTT("openHAB/pc/system/started","true")
        actions.publishMQTT("iotlink/taxfree/htpc/commands/shutdown", "")
        }


	if(receivedCommand=="start")
        {
        val actions = getActions("network", "network:pingdevice:htpc")
        logInfo("WoL", "HTPC Startad")
        if (actions === null) {
        logInfo("actions", "Actions not found, check thing ID")
        return
        }
        else
        {
            actions.sendWakeOnLanPacketViaMac(true)
}}
end

Items

Switch HTPC_status "HTPC STATUS"  {channel="network:pingdevice:htpc:online"}
DateTime HTPC_last_seen "HTPC Last Seen [%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM]" <clock>  {channel="network:pingdevice:htpc:lastseen"}



String WZ_PC_Command "HTPC Command" <network> {channel="network:pingdevice:htpc:online"}

Sitemap

Switch item=WZ_PC_Command mappings=[shutdown="Shutdown", start="WoL"]

the vdr binding is to control a vdr instance (video disk recorder) and vdr has an API which has a power OFF command. Of course if you want to shutdown a Desktop Computer (or something similar) you will have to use a script so send the correct sommand, so exec binding will be your friend.

Thanks for your input, when I finally did get some time for myself I did set up one Item that via a script controls one of my pc’s running windows. Before I used two items one for command and one for state. I did also applied visibility test so I only se the opposite of pc’s state.

Bindings used networkbinding and IoT Link via mqtt all summarized below if someone else could use it.

.Items

Switch WZ_PC_Command "HTPC control" <network> {channel="network:pingdevice:htpc:online" ,autoupdate="false"}

.rules

rule "HTPC WOL and shutdown"
when
	Item WZ_PC_Command received command
then
    if(receivedCommand==OFF)
        {
        logInfo("mqtt", "regel triggad")
        val actions = getActions("mqtt","mqtt:broker:bc3e71556e")
        actions.publishMQTT("openHAB/pc/system/started","true")
        actions.publishMQTT("iotlink/taxfree/htpc/commands/shutdown", "")
        }


	if(receivedCommand==ON)
        {
        val actions = getActions("network", "network:pingdevice:htpc")
        logInfo("WoL", "HTPC Startad")
        if (actions === null) {
        logInfo("actions", "Actions not found, check thing ID")
        return
        }
        else
        {
            actions.sendWakeOnLanPacketViaMac(true)
}}
end

.sitemap

Switch item=WZ_PC_Command mappings=[ON="WoL"] visibility=[WZ_PC_Command==OFF]
Switch item=WZ_PC_Command mappings=[OFF="Shutdown"] visibility=[WZ_PC_Command==ON]