Hello Josar,
used your rule with a longer sleep time
rule "Execute Script and get back return value"
when
Item ExecuteComand changed
then
RunScript.sendCommand(ON)
// Wait for the command to complete.
while(RunScript.state != OFF){
Thread::sleep(1000)
}
logInfo("Script executed", TF_Outdoor_Temperature_out.state.toString)
end
and one time, i see this on the log:
[el.core.internal.ModelRepositoryImpl] - Refreshing model 'tf_outdoorweather_exe.rules'
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Execute Script and get back return value': An error occurred during the script execution: null
I altered the rule a bit
rule "Execute Script and get back return value"
when
Item ExecuteComand changed
then
RunScript.sendCommand(ON)
// Wait for the command to complete.
/* while(RunScript.state != OFF){
Thread::sleep(1000)
} */
Thread::sleep(5000)
logInfo("Script executed", TF_Outdoor_Temperature_out.state.toString)
end
this time, i’m seeing this
[INFO ] [arthome.model.script.Script executed] - NULL
Then i started a new try, this time using the demo phython script from tinkerforge:
user@openhab:~/tinkerforge$ sudo -u openhab python /home/user/tinkerforge/example_callback.py
Press key to exit
21
21
21
“21” is the humidity, it occours after 25s after the call, and will be repeated, till you press a key.
New Thing:
Thing exec:command:weatherstation_humidity "Luftfeuchtigkeit" [command="python /home/user/tinkerforge/example_callback.py", transform="REGEX((.*?))", interval=60, timeout=50, autorun=true]
and new items:
Number Weatherstation_Humidity "Luftfeuchtigkeit [%.1f %%]" <humidity>
String humidity_out { channel="exec:command:weatherstation_humidity:output" }
and a rule (also tried the commented section)
rule "Weatherstation Humidity"
when
//Item humidity_out received update
Item ExecuteCommandHumidity changed
then
logInfo("Humidity Phython Script executed", humidity_out.state.toString)
// Weatherstation_Humidity.postUpdate(
// ( Float::parseFloat(humidity_out.state.toString) as Number )
//)
end
(i looked at this example: OpenHAB Raspberry Weatherstation )
BUT, no result in Openhab:
[INFO ] [ipt.Humidity Phython Script executed] - NULL
Wooaah, that is really difficult!
The Tinkerforge python script:
user@openhab:~/tinkerforge$ cat example_callback.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
HOST = "192.168.178.137"
PORT = 4223
UID = "Es8" # Change XYZ to the UID of your Outdoor Weather Bricklet
from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_outdoor_weather import BrickletOutdoorWeather
# Callback function for station data callback
def cb_station_data(identifier, temperature, humidity, wind_speed, gust_speed, rain,
wind_direction, battery_low):
print("Identifier (Station): " + str(identifier))
print("Temperature (Station): " + str(temperature/10.0) + " °C")
print("Humidity (Station): " + str(humidity) + " %RH")
print("Wind Speed (Station): " + str(wind_speed/10.0) + " m/s")
print("Gust Speed (Station): " + str(gust_speed/10.0) + " m/s")
print("Rain (Station): " + str(rain/10.0) + " mm")
print("Wind Direction (Station): " + str(wind_direction))
print("Battery Low (Station): " + str(battery_low))
print("")
# Callback function for sensor data callback
def cb_sensor_data(identifier, temperature, humidity):
# print("Identifier (Sensor): " + str(identifier))
# print("Temperature (Sensor): " + str(temperature/10.0) + " °C")
print(str(humidity)) # Here i disabled the other outputs: station identifier and temperature
# print("")
if __name__ == "__main__":
ipcon = IPConnection() # Create IP connection
ow = BrickletOutdoorWeather(UID, ipcon) # Create device object
ipcon.connect(HOST, PORT) # Connect to brickd
# Don't use device before ipcon is connected
# Enable station data callbacks
ow.set_station_callback_configuration(True)
# Enable sensor data callbacks
ow.set_sensor_callback_configuration(True)
# Register station data callback to function cb_station_data
ow.register_callback(ow.CALLBACK_STATION_DATA, cb_station_data)
# Register sensor data callback to function cb_sensor_data
ow.register_callback(ow.CALLBACK_SENSOR_DATA, cb_sensor_data)
raw_input("Press key to exit\n") # Use input() in Python 3
ipcon.disconnect()
I wrote “Theo” a message, but it seems, that he is not active in this forum anymore.