Using ping <solved>

having trouble with a script i am pinging a device with nodered and get back a number or false
how can i use this to set a item either on or off ? any help welcome

if ping == false {
setitem.sendCommand(OFF)
}else if ping (not equal) false {
setitem.sendCommand(ON)
}
end

thanks Stuart

We need more infromation. What kind/type of variable is ping? If ping is an item your schould write

ping.state

the item is a string and its either a number if available or false if not

does that mean ping is declared as a string item?
So it contains a number, e.g. ā€œ27.5ā€ or ā€œfalseā€ as a string?

Then you should compare

ping.state.toString().contains("false")

instead of

ping==false

BTW the topic is very misleading. By reading the title i was about to suggest the network binding if you want to ping a device

1 Like

sorry about the misleading title i am using nodered to ping every 60 seconds it either comes back with a number if its on the network or false if not its put in to an item but i need to be able to set another item either on or off if its on the network i know the if and else if is wrong but was asking how to set out to write to the setitem.sendCommand(ON) or setitem.sendCommand(OFF)

if (ping.state.toString == ā€œfalseā€) {
setitem.sendCommand(OFF)
} else if (ping.state.toString != ā€œfalseā€) {
setitem.sendCommand(ON)
}
end

Thatā€™s if the number/false item is a string type. And youā€™ll need to replace the ā€œ marks (canā€™t change on phone to the correct version)

1 Like

thanks thatā€™s exactly what i was after

You might want to handle null in there aswell for startup purposes. Can use || for ā€˜orā€™ and null to use === not ==.