Autor Thema: Vorschlag m.d.B. um konstruktive Kritik: Shelly-Switch-Template  (Gelesen 902 mal)

Offline supernova1963

  • Sr. Member
  • ****
  • Beiträge: 521
Hallo zusammen,

ich finde FHEMapp ist ein super Ansatz für eine alternative Visualisierung von FHEM, vielen Dank an @jemu75.

Vorschlag templ_SHSW.json als fhem device:
defmod templ_SHSW MQTT2_DEVICE
attr templ_SHSW userattr template:textField-long templatefile templatename
attr templ_SHSW IODev mqtt
attr templ_SHSW devicetopic fhemapp/template/templ_SHSW
attr templ_SHSW room 99_SYSTEM->fhemapp
attr templ_SHSW setList FA_readTemplate:noArg { FAU_ReadTemplate($NAME) } \
FA_writeTemplate:noArg { FAU_WriteTemplate($NAME) }
attr templ_SHSW template {\
  "name": "shsw1",\
  "author": "supernova1963",\
  "date": "2021-04-20",\
  "status": {\
    "bar": ["state:on:100:success","state:off:0:success"],\
    "error": ["online:^(?!true):100:error:keine Verbindung"]\
  },\
  "main": [\
    {\
      "leftBtn": "mdi-power-off",\
      "leftClick": ["state::off"],\
      "text": ["state:on:an","state:off:aus","state::%s"],\
      "rightBtn": "mdi-power-on",\
      "rightClick": ["state::on"]\
    },\
    {\
      "leftBtn": ["auth:true:mdi-lock","auth:false:mdi-lock-open-alert"],\
      "leftClick": ["auth:false:shelly_HTTPCommand /settings/login?enabled=1&username=admin&password=12345"],\
      "leftLong": ["auth:false:shelly_HTTPLoginSet admin:97895"],\
      "text": ["login::%s"],\
      "rightBtn": ["login:unprotected:mdi-lock-open-alert","login:unknown:mdi-account-off","login:wrong:mdi-account-off","login:unlocked:mdi-account-check"],\
      "rightClick": ["auth:false:shelly_HTTPCommand /settings/login?enabled=1&username=admin&password=12345"],\
      "rightLong": ["auth:false:shelly_HTTPLoginSet admin:12345"]\
    },\
    {\
      "text": ["ip::%s"],\
      "rightBtn": "mdi-dots-vertical",\
      "rightMenu": ["announce:announce","update:shelly_update","shelly:shelly","fw_update:shelly_update_fw"]\
    }\
  ],\
  "info": {\
    "left1": ["inputs_1_event:S::mdi-checkbox-marked-outline:red","inputs_1_event:L::mdi-checkboxes-multiple-marked-outline:red","inputs_1_input:::mdi-checkbox-blank-outline:lime"],\
    "left2": ["new_fw:true::mdi-reload-alert:red","new_fw:true::"],\
    "mid1": ["meters_1_power:0.1:%n.2w"],\
    "mid2": ["relays_1_timer_remaining:0.1:%n.0sec"],\
    "right1": ["mqtt_connected:true::mdi-android-messages:lime","mqtt_connected::mdi-message-bulleted-off:red","cloud_connected:true:mdi-cloud-outline:red","cloud_connected::mdi-cloud-off-outline:lime"],\
    "right2": ["online:true::mdi-wifi:lime","online:::mdi-wifi-off:red"]\
  }\
}
attr templ_SHSW templatefile /opt/fhemapp.repository/fhemApp/www/fhemapp/cfg/templ_shsw.json
attr templ_SHSW templatename shsw

Damit die setList commands funktionieren, hier ein entsprechendes Muster Utils für "OWN MODULES AND HELPER FILES": 99_myFhemAppUtils.pm:
##############################################
# $Id: 99_myFhemAppUtils.pm by supernova1963
#

package main;

use strict;
use warnings;
use POSIX;
use HttpUtils;
use JSON;
use File::Fetch;
use Blocking;

sub
myFhemAppUtils_Initialize($$)
{
  my ($hash) = @_;
}

# Enter you functions below _this_ line.

sub FAU_ReadConfig

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/config.json");
}
Log3 $name, 5, "FAU_ReadConfig ".$name.": config.json Pfad = ".$filename;
open (FILEHANDLE,"<".$filename);
my $config = do { local $/; <FILEHANDLE> };
Log3 $name, 5, "FAU_ReadConfig $name: Dateiinhalt: $config";
my $json = new JSON;
    my $perl_scalar = $json->decode($config);
if($@)
{
        Log3 $name, 5, $name.": json error: $@ in:\n".$config."\n";
fhem "set ".$name." json error; $@!";
        return "json error; $@!";
    }
# my $rc_json2nameValue = json2nameValue($config);
# my $perl_scalar = $json->decode($config);
# $hash->{helper}{config} = $json->pretty->encode($perl_scalar);
# $attr{$name}{config} = $config;
readingsSingleUpdate($hash, "config", $config, 1);
# while (my ($key, $value) = each %{$rc_json2nameValue})
# {
# readingsSingleUpdate($hash, $key, $value, 1);
# }
fhem "setreading ".$name." OK";

}

################################################################################
sub FAU_WriteConfig

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/config.json");
}
Log3 $name, 5, "FAU_ReadConfig ".$name.": config.json = ".$filename;
open (FILEHANDLE, ">".$filename) or die "Write ".$filename.": ".$!;
    print FILEHANDLE AttrVal($name,"config","");
close (FILEHANDLE);
fhem "setreading ".$name." OK";

}

################################################################################
sub FAU_ReadTemplate

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
if (!defined(AttrVal($name,"templatefile",undef))) {
if (!defined(AttrVal($name,"templatename",undef))) {
Log3 $name, 3, "FAU_WriteTempl ".$name.": not defined = ".$filename;
return "target file not defined";
}
else {
$filename = "/opt/fhem/fhemapp/www/cfg/templ_".AttrVal($name,"templatename",InternalVal($name,"NAME","templ_switch")).".json";
}
}
else {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/templ_switch.json");
}
}
Log3 $name, 5, "FAU_ReadConfig ".$name.": template file = ".$filename;

open (FILEHANDLE,"<".$filename);
my $template = do { local $/; <FILEHANDLE> };
Log3 $name, 5, "FAU_ReadTempl ".$name.": ".$template;
my $json = new JSON;
    my $perl_scalar = $json->decode($template);
if($@)
{
        Log3 $name, 5, $name.": json error: $@ in:\n".$template."\n";
fhem "setreading ".$name." state Write ".$filename.": json error; $@!";
        return "FAU_ReadTempl: json error; $@!";
    }
#### json2nameValue
# my $rc_json2nameValue = json2nameValue($templ);
# my $perl_scalar = $json->decode($templ);
# $hash->{helper}{templ} = $json->pretty->encode($perl_scalar);
# $attr{$name}{templ} = $config;
# while (my ($key, $value) = each %{$rc_json2nameValue})
# {
# readingsSingleUpdate($hash, $key, $value, 1);
# }
readingsSingleUpdate($hash, "template", $template, 1);
fhem "setreading ".$name." state OK";
}

################################################################################
sub FAU_WriteTemplate

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = "";
if ( AttrVal($name,"templatefile","") eq "" ) {
if ( AttrVal($name,"templatename","") eq "" ) {
Log3 $name, 3, "FAU_WriteTempl ".$name.": not defined file!";
return "FAU_WriteTemplate target file not defined";
}
else {
$filename = "/opt/fhem/fhemapp/www/cfg/".AttrVal($name,"templatename",InternalVal($name,"NAME","templ_xxx")).".json";
}
}
else {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/templ_xxx.json");
}
}
Log3 $name, 5, "FAU_WriteConfig ".$name.": template file = ".$filename;

open (FILEHANDLE, ">".$filename) or die "Write ".$filename.": ".$!;
print FILEHANDLE AttrVal($name,"template","");
close (FILEHANDLE);
fhem "setreading ".$name." state OK";

}

################################################################################


1;

Über jede "kritische Würdigung" würde ich mich sehr freuen.

Danke,

Gernot

Edit: 03.06.2021, 17:54:12 rawDefinition vom MQTT2_DEVICE und 99_myFhemAppUtils.pm geändert !!!
« Letzte Änderung: 04 Juni 2021, 07:08:35 von supernova1963 »

Offline jemu75

  • Moderator
  • Sr. Member
  • ***
  • Beiträge: 707
    • FHEM App
Hallo zusammen,

ich finde FHEMapp ist ein super Ansatz für eine alternative Visualisierung von FHEM, vielen Dank an @jemu75.

Vorschlag templ_SHSW.json als fhem device:
defmod templ_SHSW MQTT2_DEVICE
attr templ_SHSW userattr template:textField-long templatefile templatename
attr templ_SHSW IODev mqtt
attr templ_SHSW devicetopic fhemapp/template/templ_SHSW
attr templ_SHSW room 99_SYSTEM->fhemapp
attr templ_SHSW setList FA_readTemplate:noArg { FAU_ReadTemplate($NAME) } \
FA_writeTemplate:noArg { FAU_WriteTemplate($NAME) }
attr templ_SHSW template {\
  "name": "shsw1",\
  "author": "supernova1963",\
  "date": "2021-04-20",\
  "status": {\
    "bar": ["state:on:100:success","state:off:0:success"],\
    "error": ["online:^(?!true):100:error:keine Verbindung"]\
  },\
  "main": [\
    {\
      "leftBtn": "mdi-power-off",\
      "leftClick": ["state::off"],\
      "text": ["state:on:an","state:off:aus","state::%s"],\
      "rightBtn": "mdi-power-on",\
      "rightClick": ["state::on"]\
    },\
    {\
      "leftBtn": ["auth:true:mdi-lock","auth:false:mdi-lock-open-alert"],\
      "leftClick": ["auth:false:shelly_HTTPCommand /settings/login?enabled=1&username=admin&password=97895"],\
      "leftLong": ["auth:false:shelly_HTTPLoginSet admin:97895"],\
      "text": ["login::%s"],\
      "rightBtn": ["login:unprotected:mdi-lock-open-alert","login:unknown:mdi-account-off","login:wrong:mdi-account-off","login:unlocked:mdi-account-check"],\
      "rightClick": ["auth:false:shelly_HTTPCommand /settings/login?enabled=1&username=admin&password=97895"],\
      "rightLong": ["auth:false:shelly_HTTPLoginSet admin:97895"]\
    },\
    {\
      "text": ["ip::%s"],\
      "rightBtn": "mdi-dots-vertical",\
      "rightMenu": ["announce:announce","update:shelly_update","shelly:shelly","fw_update:shelly_update_fw"]\
    }\
  ],\
  "info": {\
    "left1": ["inputs_1_event:S::mdi-checkbox-marked-outline:red","inputs_1_event:L::mdi-checkboxes-multiple-marked-outline:red","inputs_1_input:::mdi-checkbox-blank-outline:lime"],\
    "left2": ["new_fw:true::mdi-reload-alert:red","new_fw:true::"],\
    "mid1": ["meters_1_power:0.1:%n.2w"],\
    "mid2": ["relays_1_timer_remaining:0.1:%n.0sec"],\
    "right1": ["mqtt_connected:true::mdi-android-messages:lime","mqtt_connected::mdi-message-bulleted-off:red","cloud_connected:true:mdi-cloud-outline:red","cloud_connected::mdi-cloud-off-outline:lime"],\
    "right2": ["online:true::mdi-wifi:lime","online:::mdi-wifi-off:red"]\
  }\
}
attr templ_SHSW templatefile /opt/fhemapp.repository/fhemApp/www/fhemapp/cfg/templ_shsw.json
attr templ_SHSW templatename shsw

Damit die setList commands funktionieren, hier ein entsprechendes Muster Utils für "OWN MODULES AND HELPER FILES": 99_myFhemAppUtils.pm:
##############################################
# $Id: 99_myFhemAppUtils.pm by supernova1963
#

package main;

use strict;
use warnings;
use POSIX;
use HttpUtils;
use JSON;
use File::Fetch;
use Blocking;

sub
myFhemAppUtils_Initialize($$)
{
  my ($hash) = @_;
}

# Enter you functions below _this_ line.

sub FAU_ReadConfig

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/config.json");
}
Log3 $name, 5, "FAU_ReadConfig ".$name.": config.json Pfad = ".$filename;
open (FILEHANDLE,"<".$filename);
my $config = do { local $/; <FILEHANDLE> };
Log3 $name, 5, "FAU_ReadConfig $name: Dateiinhalt: $config";
my $json = new JSON;
    my $perl_scalar = $json->decode($config);
if($@)
{
        Log3 $name, 5, $name.": json error: $@ in:\n".$config."\n";
fhem "set ".$name." json error; $@!";
        return "json error; $@!";
    }
# my $rc_json2nameValue = json2nameValue($config);
# my $perl_scalar = $json->decode($config);
# $hash->{helper}{config} = $json->pretty->encode($perl_scalar);
# $attr{$name}{config} = $config;
readingsSingleUpdate($hash, "config", $config, 1);
# while (my ($key, $value) = each %{$rc_json2nameValue})
# {
# readingsSingleUpdate($hash, $key, $value, 1);
# }
fhem "setreading ".$name." OK";

}

################################################################################
sub FAU_WriteConfig

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/config.json");
}
Log3 $name, 5, "FAU_ReadConfig ".$name.": config.json = ".$filename;
open (FILEHANDLE, ">".$filename) or die "Write ".$filename.": ".$!;
    print FILEHANDLE AttrVal($name,"config","");
close (FILEHANDLE);
fhem "setreading ".$name." OK";

}

################################################################################
sub FAU_ReadTemplate

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
if (!defined(AttrVal($name,"templatefile",undef))) {
if (!defined(AttrVal($name,"templatename",undef))) {
Log3 $name, 3, "FAU_WriteTempl ".$name.": not defined = ".$filename;
return "target file not defined";
}
else {
$filename = "/opt/fhem/fhemapp/www/cfg/templ_".AttrVal($name,"templatename",InternalVal($name,"NAME","templ_switch")).".json";
}
}
else {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/templ_switch.json");
}
}
Log3 $name, 5, "FAU_ReadConfig ".$name.": template file = ".$filename;

open (FILEHANDLE,"<".$filename);
my $template = do { local $/; <FILEHANDLE> };
Log3 $name, 5, "FAU_ReadTempl ".$name.": ".$template;
my $json = new JSON;
    my $perl_scalar = $json->decode($template);
if($@)
{
        Log3 $name, 5, $name.": json error: $@ in:\n".$template."\n";
fhem "setreading ".$name." state Write ".$filename.": json error; $@!";
        return "FAU_ReadTempl: json error; $@!";
    }
#### json2nameValue
# my $rc_json2nameValue = json2nameValue($templ);
# my $perl_scalar = $json->decode($templ);
# $hash->{helper}{templ} = $json->pretty->encode($perl_scalar);
# $attr{$name}{templ} = $config;
# while (my ($key, $value) = each %{$rc_json2nameValue})
# {
# readingsSingleUpdate($hash, $key, $value, 1);
# }
readingsSingleUpdate($hash, "template", $template, 1);
fhem "setreading ".$name." state OK";
}

################################################################################
sub FAU_WriteTemplate

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = "";
if ( AttrVal($name,"templatefile","") eq "" ) {
if ( AttrVal($name,"templatename","") eq "" ) {
Log3 $name, 3, "FAU_WriteTempl ".$name.": not defined file!";
return "FAU_WriteTemplate target file not defined";
}
else {
$filename = "/opt/fhem/fhemapp/www/cfg/".AttrVal($name,"templatename",InternalVal($name,"NAME","templ_xxx")).".json";
}
}
else {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/templ_xxx.json");
}
}
Log3 $name, 5, "FAU_WriteConfig ".$name.": template file = ".$filename;

open (FILEHANDLE, ">".$filename) or die "Write ".$filename.": ".$!;
print FILEHANDLE AttrVal($name,"template","");
close (FILEHANDLE);
fhem "setreading ".$name." state OK";

}

################################################################################


1;

Über jede "kritische Würdigung" würde ich mich sehr freuen.

Danke,

Gernot

Edit: 03.06.2021, 17:54:12 rawDefinition vom MQTT2_DEVICE und 99_myFhemAppUtils.pm geändert !!!

Hallo Gernot,

das sieht interessant aus, ich bin aber noch nicht ganz durchgestiegen. Kannst du den Ansatz bitte mal noch etwas erläutern.
Und was deiner Meinung nach, der Vorteil zur Definition der Templates in den separaten Json-Files ist.

Vielen Dank schon mal
Jens  :)

Offline supernova1963

  • Sr. Member
  • ****
  • Beiträge: 521
Hallo @jemu75,

ich habe mir für jedes eigene Template ein fhem "dummy" device angelegt damit ich zum einen
  • den fhem integrierten Editor für die Attributbearbeitung verwenden kann,
  • nach einem Löschen des fhemapp Verzeichnisses meine template Files wiederherstellen kann und
  • bei der Nutzung meines iPad, im Browser bleiben kann.
Zunächst habe ich ein FHEM dummy device verwendet, aber da mußte ich den Aufruf der Sub im myUtils immer über ein notify durchführen.
Das spare ich mir, wenn ich ein MQTT2_DEVICE verwende. Hier kann man im setList einen Perl Befehl eingeben.
Die anderen userAttr: templatefile und templatename, frage ich in den Sub's FAU_ReadTemplate() und FAU_WriteTemplate().

Für die Datei config.json, die bei mir derzeit bei jedem fhemapp update überschrieben wird, habe ich ein vergleichbaren Dummy angelegt, mit dem Unterschied, dass setList FAU_ReadConfig($) und FAU_WriteConfig verwendet wird.

Das kann man sicher besser lösen, aber so funktioniert's und hilft's mir.
« Letzte Änderung: 04 Juni 2021, 08:12:20 von supernova1963 »

Offline supernova1963

  • Sr. Member
  • ****
  • Beiträge: 521
Auch, wenn meine Dummies und meine 99_myFAUtils.pm hier eher "Off Topic" sind, hier mein aktueller Stand mit einem json Format-Check.

##############################################
# $Id: 99_myFhemAppUtils.pm by supernova1963
#

package main;

use strict;
use warnings;
use POSIX;
use HttpUtils;
use JSON;
use File::Fetch;
use Blocking;

sub
myFhemAppUtils_Initialize($$)
{
  my ($hash) = @_;
}

# Enter you functions below _this_ line.

sub FAU_ReadConfig

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/config.json");
}
Log3 $name, 5, "FAU_ReadConfig ".$name.": config.json Pfad = ".$filename;

open (FILEHANDLE,"<".$filename) or die "Couldn't open file $filename, $!";
my $config = do { local $/; <FILEHANDLE> };
Log3 $name, 5, "FAU_ReadConfig $name: Dateiinhalt: $config";

readingsSingleUpdate($hash, "config", $config, 1);
fhem "setreading ".$name." OK";

### json Format-Check
my $json = new JSON;
my $perl_scalar = $json->decode($config);
if($@)
{
        Log3 $name, 5, $name.": FAU_ReadConfig has json error: $@ in:\n".$config."\n";
fhem "set ".$name." FAU_ReadConfig has json error; $@!";
        return "FAU_ReadConfig has json error; $@!";
}
#### end json Format-Check

### json2nameValue
# my $rc_json2nameValue = json2nameValue($config);
# my $perl_scalar = $json->decode($config);
# $hash->{helper}{config} = $json->pretty->encode($perl_scalar);
# $attr{$name}{config} = $config;
# while (my ($key, $value) = each %{$rc_json2nameValue})
# {
# readingsSingleUpdate($hash, $key, $value, 1);
# }
#### end json2nameValue

}

################################################################################
sub FAU_WriteConfig

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/config.json");
}

### json Format-Check
my $template = AttrVal($name,"config","");
my $json = new JSON;
my $perl_scalar = $json->decode($template);
if($@)
{
        Log3 $name, 5, $name."FAU_WriteConfig json error: $@ in:\n".$template."\n";
fhem "setreading ".$name." state FAU_WriteConfig: json error; $@!";
        return "FAU_WriteConfig: json error; $@!";
}
#### end json Format-Check

Log3 $name, 5, "FAU_ReadConfig ".$name.": config.json = ".$filename;
open (FILEHANDLE, ">".$filename) or die "Write ".$filename.": ".$!;
    print FILEHANDLE AttrVal($name,"config","");
close (FILEHANDLE);
fhem "setreading ".$name." OK";

}

################################################################################
sub FAU_ReadTemplate

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
if (!defined(AttrVal($name,"templatefile",undef))) {
if (!defined(AttrVal($name,"templatename",undef))) {
Log3 $name, 3, "FAU_WriteTempl ".$name.": not defined = ".$filename;
return "target file not defined";
}
else {
$filename = "/opt/fhem/fhemapp/www/cfg/templ_".AttrVal($name,"templatename",InternalVal($name,"NAME","templ_switch")).".json";
}
}
else {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/templ_switch.json");
}
}

Log3 $name, 5, "FAU_ReadConfig ".$name.": template file = ".$filename;

open (FILEHANDLE,"<".$filename);
my $template = do { local $/; <FILEHANDLE> };
Log3 $name, 5, "FAU_ReadTempl ".$name.": ".$template;

### json Format-Check
my $json = new JSON;
my $perl_scalar = $json->decode($template);
if($@)
{
        Log3 $name, 5, $name.": FAU_ReadTemplate json error: $@ in:\n".$template."\n";
fhem "setreading ".$name." state FAU_ReadTemplate: json error; $@!";
return "FAU_ReadTempl: json error; $@!";
}
#### end json Format-Check

#### json2nameValue
# my $rc_json2nameValue = json2nameValue($templ);
# my $perl_scalar = $json->decode($templ);
# $hash->{helper}{templ} = $json->pretty->encode($perl_scalar);
# $attr{$name}{templ} = $config;
# while (my ($key, $value) = each %{$rc_json2nameValue})
# {
# readingsSingleUpdate($hash, $key, $value, 1);
# }
#### end json2nameValue

readingsSingleUpdate($hash, "template", $template, 1);
fhem "setreading ".$name." state OK";
}

################################################################################
sub FAU_WriteTemplate

{
my ($name,$filename) = @_;
my $hash = $defs{$name};
if (!defined($filename) || $filename eq "") {
$filename = "";
if ( AttrVal($name,"templatefile","") eq "" ) {
if ( AttrVal($name,"templatename","") eq "" ) {
Log3 $name, 3, "FAU_WriteTempl ".$name.": not defined file!";
return "FAU_WriteTemplate target file not defined";
}
else {
$filename = "/opt/fhem/fhemapp/www/cfg/".AttrVal($name,"templatename",InternalVal($name,"NAME","templ_xxx")).".json";
}
}
else {
$filename = AttrVal($name,"templatefile","/opt/fhem/fhemapp/www/cfg/templ_xxx.json");
}
}

### json Format-Check
my $template = AttrVal($name,"template","");
my $json = new JSON;
my $perl_scalar = $json->decode($template);
if($@)
{
        Log3 $name, 5, $name.": FAU_WriteTemplate json error: $@ in:\n".$template."\n";
fhem "setreading ".$name." state FAU_WriteTemplate: json error; $@!";
        return "FAU_WriteTempl: json error; $@!";
}
#### end json Format-Check


Log3 $name, 5, "FAU_WriteConfig ".$name.": template file = ".$filename;
open (FILEHANDLE, ">".$filename) or die "Write ".$filename.": ".$!;
print FILEHANDLE AttrVal($name,"template","");
close (FILEHANDLE);
fhem "setreading ".$name." state OK";

}

################################################################################


1;

lg

Gernot

 

decade-submarginal