Hi @Josar,
please find below my coding for 433 MHz transceiver:
import java.util.concurrent.locks.ReentrantLock
// Val for Transmitter, that no problems if two calls comming
val ReentrantLock transmitter = new ReentrantLock
//////////////////////
//////// Switching 433 MHz Devices
//////////////////////
rule "Single Plug"
when
Member of G_All_Plugs received command
// Item of Group Power Plugs received command or
then
logInfo("Power_Plug", "Schalter" + triggeringItem.name + " to " + receivedCommand)
try {
// Lock transmitter so other executed rules dont't use it at the same time, Concurrent calls of the rule will wait till the resource is free again.
transmitter.lock()
// Get the item which triggered the rule, Split the name and get the second part, the number to set as command.
val num = triggeringItem.name.toString.split("Power_Plug_Socket_").get(1)
// Set the command which should be executed to the output channel, Auto trigger will then execute the Thing.
if(receivedCommand == ON){
Remote_Send_Args.sendCommand("1ABC1 " + num +" 1")
}else{
Remote_Send_Args.sendCommand("1ABC1 " + num +" 0")
}// Wait for the command to complete
while(Remote_Send.state != OFF){
Thread::sleep(100)
}// Mulltiple trigger do not work if there is no break here, maybe external skript needs some time to properly free resources.
Thread::sleep(400)
logInfo("Power_Plug", Remote_Send_Out.state.toString.replaceAll("\r|\n"," ") )
} catch(Throwable t) {}
finally
{ // Free the resource for the next call.
transmitter.unlock()
}
end
//////////////////////
//////// Update of Status Power Plugs by using manual shutter
//////////////////////
rule "Poweroutlet Update"
when
Item MQTT_data changed
then
switch MQTT_data.state
{
case "26ABC5": Power_Plug_Socket_1.postUpdate(ON)
case "26ABC8": Power_Plug_Socket_1.postUpdate(OFF)
case "26ABC7": Power_Plug_Socket_2.postUpdate(ON)
case "26ABC0": Power_Plug_Socket_2.postUpdate(OFF)
case "26ABC5": Power_Plug_Socket_3.postUpdate(ON)
case "26ABC8": Power_Plug_Socket_3.postUpdate(OFF)
//case "26ABC7": Power_Plug_Socket_4.postUpdate(ON)
//case "26ABC0": Power_Plug_Socket_4.postUpdate(OFF)
}
if(MQTT_data.state.toString !="") MQTT_data.postUpdate("")
end
//////////////////////////
/////// Leinwand_Remote
//////////////////////////
rule "Leinwand"
when
Item Leinwand_Remote received command
then
try { //new
// Lock transmitter so other executed rules dont't use it at the same time, Concurrent calls of the rule will wait till the resource is free again.
transmitter.lock() //new
switch (receivedCommand){
case UP:
{
Remote_CodeSend_Args.sendCommand("ABC") // first stop command due to physical device that first needs stop command
Thread::sleep(1000) // 1 Second to wait, else the system can not execute both commands.
Remote_CodeSend_Args.sendCommand("ABC")
}
case STOP: Remote_CodeSend_Args.sendCommand("ABC")
case DOWN:
{
Remote_CodeSend_Args.sendCommand("ABC")
Thread::sleep(1000)
Remote_CodeSend_Args.sendCommand("ABC")
}
}logInfo("Leinwand", "Results are: \n" + Remote_CodeSend_Out.state)
// Mulltiple trigger do not work if there is no break here, maybe external skript needs some time to properly free resources.
Thread::sleep(400) //new
} catch(Throwable t) {} //new
finally //new
{ // Free the resource for the next call. //new
transmitter.unlock() //new
}
end
//////////////////////////
/////// Leinwand Steuerung Alexa
//////////////////////////
rule "Leinwand Steuerung"
when
Item Leinwand_Remote_Alexa_UpDown received command
then
try { //new
// Lock transmitter so other executed rules dont't use it at the same time, Concurrent calls of the rule will wait till the resource is free again.
transmitter.lock() //new
// 0% is up, 100% down, 50% stop (workaround....)
switch (receivedCommand){
case 0:
{
Remote_CodeSend_Args.sendCommand("ABC") // first stop command due to physical device that first needs stop command
Thread::sleep(1000) // 1 Second to wait, else the system can not execute both commands.
Remote_CodeSend_Args.sendCommand("ABC")
}
case 50: Remote_CodeSend_Args.sendCommand("ABC")
case 100:
{
Remote_CodeSend_Args.sendCommand("ABC")
Thread::sleep(1000)
Remote_CodeSend_Args.sendCommand("ABC")
}
}logInfo("Leinwand", "Results are: \n" + Remote_CodeSend_Out.state)
// Mulltiple trigger do not work if there is no break here, maybe external skript needs some time to properly free resources.
Thread::sleep(400) //new
} catch(Throwable t) {} //new
finally //new
{ // Free the resource for the next call. //new
transmitter.unlock() //new
}
end
/////////////////////////////////////////////////////////////////////////
/////// Power Plugs Lidl, old Code
//////////////////////////
rule "Poweroutlet Lidl 1"
when
Item Power_Plug_Lidl_1 received command
then
try {
// Lock transmitter so other executed rules dont't use it at the same time, Concurrent calls of the rule will wait till the resource is free again.
transmitter.lock()
if(receivedCommand == ON){
Remote_CodeSend_Args.sendCommand("ABC 4")
}else{
Remote_CodeSend_Args.sendCommand("ABC 4")
}
// wait for the command to complete
while(Remote_Send.state != ON){
Thread::sleep(500)
}
// Mulltiple trigger do not work if there is no break here, maybe external skript needs some time to properly free resources.
Thread::sleep(400)
logInfo("Power_Plug_Lidl_1", "Results are: \n" + Remote_CodeSend_Out.state )
} catch(Throwable t) {}
finally
{ // Free the resource for the next call.
transmitter.unlock()
}
end
rule "Poweroutlet Lidl 2"
when
Item Power_Plug_Lidl_2 received command
then
try {
transmitter.lock()
// Get the item which triggered the rule, Split the name and get the second part, the number to set as command.
if(receivedCommand == ON){
Remote_CodeSend_Args.sendCommand("ABC 4")
}else{
Remote_CodeSend_Args.sendCommand("ABC 4")
}
// wait for the command to complete
while(Remote_Send.state != ON){
Thread::sleep(500)
}
// Mulltiple trigger do not work if there is no break here, maybe external skript needs some time to properly free resources.
Thread::sleep(400)
logInfo("Power_Plug_Lidl_2", "Results are: \n" + Remote_CodeSend_Out.state )
} catch(Throwable t) {}
finally
{ // Free the resource for the next call.
transmitter.unlock()
}
end
rule "Poweroutlet Lidl 3"
when
Item Power_Plug_Lidl_3 received command
then
try {
transmitter.lock()
// Get the item which triggered the rule, Split the name and get the second part, the number to set as command.
if(receivedCommand == ON){
Remote_CodeSend_Args.sendCommand("ABC 4")
}else{
Remote_CodeSend_Args.sendCommand("ABC 4")
}
// wait for the command to complete
while(Remote_Send.state != ON){
Thread::sleep(500)
}
// Mulltiple trigger do not work if there is no break here, maybe external skript needs some time to properly free resources.
Thread::sleep(400)
logInfo("Power_Plug_Lidl_3", "Results are: \n" + Remote_CodeSend_Out.state )
} catch(Throwable t) {}
finally
{ // Free the resource for the next call.
transmitter.unlock()
}
end
rule "Poweroutlet Lidl 4"
when
Item Power_Plug_Lidl_4 received command
then
try {
// Lock transmitter so other executed rules dont't use it at the same time, Concurrent calls of the rule will wait till the resource is free again.
transmitter.lock()
if(receivedCommand == ON){
Remote_CodeSend_Args.sendCommand("ABC 4")
}else{
Remote_CodeSend_Args.sendCommand("ABC 4")
}
// wait for the command to complete
while(Remote_Send.state != ON){
Thread::sleep(500)
}
// Mulltiple trigger do not work if there is no break here, maybe external skript needs some time to properly free resources.
Thread::sleep(400)
logInfo("Power_Plug_Lidl_4", "Results are: \n" + Remote_CodeSend_Out.state )
} catch(Throwable t) {}
finally
{ // Free the resource for the next call.
transmitter.unlock()
}
end
This is the code for the dht22, which wasn’t working any longer as well after the 433 plugs are not working any longer:
//Rule to read transfer the string of the dht22 temperature sensor
rule "Temp"
when
Item Temp_wohnzimmer_out received update
then
Klima_temp_wz.postUpdate(Temp_wohnzimmer_out.state.toString)
Thread::sleep(5000)
logInfo("temp", "Temperatur: " + Klima_temp_wz.state + "°C")
end
//Rule to read transfer the string of the dht22 humidty sensor
rule "Hum"
when
Item Hum_wohnzimmer_out received update
then
Klima_hum_wz.postUpdate(Hum_wohnzimmer_out.state.toString)
Thread::sleep(5000)
logInfo("Humi", "Luftfeuchtigkeit: " + Klima_hum_wz.state + "%")
end
Log file is providing the following eg testet this morning:
2019-02-08 09:44:56.665 [INFO ] [se.smarthome.model.script.Power_Plug] - SchalterPower_Plug_Socket_3 to ON
2019-02-08 09:44:57.733 [INFO ] [se.smarthome.model.script.Power_Plug] - using pin 0 sending systemCode[1ABC1] unitCode[3] command[1]
2019-02-08 09:45:00.035 [INFO ] [se.smarthome.model.script.Power_Plug] - SchalterPower_Plug_Lidl_2 to ON
2019-02-08 09:45:12.483 [INFO ] [se.smarthome.model.script.Power_Plug] - SchalterPower_Plug_Socket_1 to ON
As you can see, first switch worked and then nothing was happening. Shouldn’t it be the case that even if the system is still working the request wait until the transmitter is free again?
Sorry, I am a bit lost.
Thank you in advance.