Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1.  
  2. /*
  3.  
  4. Bitte lege dieses Script im IOBroker unter scripte an -> als Javascript -> dieses script muss in den Ordner Global
  5. unten musst du deine fibaro benutzerdaten noch eintragen
  6.  
  7. Das Script wurde von Nico Bode von https://www.intelligentes-haus.de entwickelt.
  8.  
  9. Die Anleitung inkl. Video findest du hier:
  10.  
  11. */
  12.  
  13.  
  14. var fibaro_username = ''; // Fibaro Admin Loginname
  15. var fibaro_password = ''; // Fibaro Password
  16. var fibaro_ip = ''; // Fibaro IP adresse
  17.  
  18.  
  19. function fibaro_create_global_var(fibaro_global_name,fibaro_global_value,fibaro_create_when_not_exist=true) {
  20.  
  21. request.post({
  22. url: 'http://'+fibaro_username+':'+fibaro_password+'@'+fibaro_ip+'/api/globalVariables/',
  23. form: '{"name":"'+fibaro_global_name+'","value":"'+fibaro_global_value+'"}'
  24.  
  25. }, function(error, response, body) {
  26. if (error) {
  27. //log(error, 'error');
  28. } else {
  29. if (response.statusCode == 201) {
  30. log('Variable '+ fibaro_global_name+' bei Fibaro mit dem Wert '+fibaro_global_value+' angelegt ','info');
  31. } else {
  32. log('HTTP Fehler2','info');
  33. log(JSON.stringify(response), 'error');
  34. }
  35.  
  36. }
  37.  
  38.  
  39. });
  40.  
  41. }
  42.  
  43.  
  44. function fibaro_update_global_var(fibaro_global_name,fibaro_global_value,fibaro_create_when_not_exist=true) {
  45.  
  46. toString(fibaro_global_name);
  47. toString(fibaro_global_value);
  48.  
  49. request.put({
  50. url: 'http://'+fibaro_username+':'+fibaro_password+'@'+fibaro_ip+'/api/globalVariables/'+fibaro_global_name,
  51. form: '{"name":"'+fibaro_global_name+'","value":"'+fibaro_global_value+'"}'
  52.  
  53. }, function(error, response, body) {
  54. if (error) {
  55. log(error, 'error');
  56. } else {
  57. if (response.statusCode == 200) {
  58. log('Variable '+ fibaro_global_name+' bei Fibaro mit dem Wert '+fibaro_global_value+' gespeichert ','info');
  59. } else {
  60.  
  61. if(response.statusCode == 404 && fibaro_create_when_not_exist === true) {
  62. log('Variable wird angelegt','info');
  63. fibaro_create_global_var(fibaro_global_name,fibaro_global_value);
  64. } else {
  65. log('HTTP Fehler','info');
  66. log(JSON.stringify(response), 'error');
  67.  
  68. }
  69.  
  70. }
  71.  
  72. }
  73.  
  74.  
  75. });
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement