Defining multiple attributes of a specific device with a single "macro"

Begonnen von peg, 06 Juni 2014, 15:02:47

Vorheriges Thema - Nächstes Thema

peg

Hi,

I'm currently using FHEM for datalogging multiple sensor with same characteristics.
The configuration file as some lines multpilied as many times as number of sensors I use.

Could I defined a kind of Macro to reduced fhem config file.
See example below that shows number of configuration lines that are the same except the identifier (2c26 or 2c24)

In advance thank's

Pierre-emmanuel

###############
## TH: 2c26  #
###############
define W6th2c26 W6TH aaaa::ff:fe00:2c26
attr W6th2c26 BR_CFG PWS,3,1,14400,1,1 RECBAT,4,1,14400,50,10 DISPBAT,5,1,14400,50,10 SOLHARV,6,1,14400,50,10
attr W6th2c26 BR_HUMID 1,1,3600,100,100
attr W6th2c26 BR_PRESENTVALUE 2,1,3600,5,5
attr W6th2c26 BR_TAGSZ 3
attr W6th2c26 BR_TEMP 0,1,3600,30,20
attr W6th2c26 room 0_Sensors

define FileLog_th2c26 FileLog /home/root/fhemtmp/log/th2c26-b-%Y.log W6th2c26
attr FileLog_th2c26 logtype w6plot_pw_br_solar:pwr_solar,w6plot_pw_br_recharg:pwr_recharg,w6plot_pw_br:pwbr,w6plot_th_br:thbr,w6plot_rpt_stat:stat,text
attr FileLog_th2c26 room logs

define wl_th2c26_pw_br_solar SVG FileLog_th2c26:w6plot_pw_br_solar:CURRENT
attr wl_th2c26_pw_br_solar room Plots-th2c26
attr wl_th2c26_pw_br_solar title "Battery source and Solar level"

define wl_th2c26_pw_br_recharg SVG FileLog_th2c26:w6plot_pw_br_recharg:CURRENT
attr wl_th2c26_pw_br_recharg room Plots-th2c26
attr wl_th2c26_pw_br_recharg title "Battery source and Rechargeable level"

define wl_th2c26_ai_pv SVG FileLog_th2c26:w6plot_ai_br:CURRENT
attr wl_th2c26_ai_pv room Plots-th2c26
attr wl_th2c26_ai_pv title "% luminosity"

define wl_th2c26_sz SVG FileLog_th2c26:w6plot_rpt_stat:CURRENT
attr wl_th2c26_sz room Plots-th2c26
attr wl_th2c26_sz title "Report sizes"

define wl_th2c26_th SVG FileLog_th2c26:w6plot_th_br_mpo:CURRENT
attr wl_th2c26_th room Plots-th2c26
attr wl_th2c26_th title "Temperature Humidity"


###############
## TH: 2c24 #
###############
define W6th2c24 W6TH aaaa::ff:fe00:2c24
attr W6th2c24 BR_CFG PWS,3,1,14400,1,1 RECBAT,4,1,14400,50,10 DISPBAT,5,1,14400,50,10 SOLHARV,6,1,14400,50,10
attr W6th2c24 BR_HUMID 1,1,3600,100,100
attr W6th2c24 BR_PRESENTVALUE 2,1,3600,5,5
attr W6th2c24 BR_TAGSZ 3
attr W6th2c24 BR_TEMP 0,1,3600,30,20
attr W6th2c24 room 0_Sensors


define FileLog_th2c24 FileLog /home/root/fhemtmp/log/th2c24-b-%Y.log W6th2c24
attr FileLog_th2c24 logtype w6plot_pw_br_solar:pwr_solar,w6plot_pw_br_recharg:pwr_recharg,w6plot_pw_br:pwbr,w6plot_ai_br:ai_pv,w6plot_th_br:thbr,w6plot_rpt_stat:stat,text
attr FileLog_th2c24 room logs

define wl_th2c24_pw_br_solar SVG FileLog_th2c24:w6plot_pw_br_solar:CURRENT
attr wl_th2c24_pw_br_solar room Plots-th2c24
attr wl_th2c24_pw_br_solar title "Battery source and Solar level"

define wl_th2c24_pw_br_recharg SVG FileLog_th2c24:w6plot_pw_br_recharg:CURRENT
attr wl_th2c24_pw_br_recharg room Plots-th2c24
attr wl_th2c24_pw_br_recharg title "Battery source and Rechargeable level"

define wl_th2c24_ai_pv SVG FileLog_th2c24:w6plot_ai_br:CURRENT
attr wl_th2c24_ai_pv room Plots-th2c24
attr wl_th2c24_ai_pv title "% luminosity"

define wl_th2c24_sz SVG FileLog_th2c24:w6plot_rpt_stat:CURRENT
attr wl_th2c24_sz room Plots-th2c24
attr wl_th2c24_sz title "Report sizes"

define wl_th2c24_th SVG FileLog_th2c24:w6plot_th_br_mpo:CURRENT
attr wl_th2c24_th room Plots-th2c24
attr wl_th2c24_th title "Temperature Humidity"

....

justme1968

this is currently not possible.

the closest thing inside fhem  is the copy command to copy a complete device.

i'm planing to extend it so it can copy attributes only from one device to another. but i don't think it will habe macro functionality to replace device namens inside of definitions or attributes.

maybe the simplest thing dir you to do is create the 'macro' inside an external editor using copy/paste/replace to get all your definitions and then paste all lines to a telnet connection to fhem.
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

rudolfkoenig

There is a setdefaultattr command, which most probably will go away in the future, as it is not compatible with save.

IMHO the size of the fhem.cfg file should not bother you. You should not even take a look into the file, just imagine that the configuration file is not human readable, and can only be edited through FHEM.