Marius, testing with adding attributes.
Is it possible to reduce this code?
customize_glob:
binary_sensor.zzzzzzzzzzzzzzzzz*:
templates:
attr_1: >
function Foo(string) {
return AAAAAAAAA;
};
.... use Foo() ....
return XXX;
attr_2: >
function Foo(string) {
return AAAAAAAAA;
};
.... use Foo() ....
return YYY;
attr_3: >
function Foo(string) {
return AAAAAAAAA;
};
.... use Foo() ....
return ZZZ;
The issue is that some function is supposed to be used for each attribute…
The most important question.
I cannot understand why my “Template” tab does not see added attributes - at least if they are added as templates.
Here is a customization:
customize_glob:
binary_sensor.battery_charging_life360_*:
templates:
battery_level: >
var SOURCE_DEVICE = entity.entity_id.split('battery_charging_life360_')[1];
var SOURCE_SENSOR_FULL = 'sensor.battery_life360_' + SOURCE_DEVICE;
var LEVEL = parseFloat(entities[SOURCE_SENSOR_FULL].state);
return (LEVEL / 100.0);
hide_attributes:
- templates
The battery level is taken from the paired sensor.
The results:
But this added attribute is not available in the Template tab:
Does that mean that Custom UI templates work ONLY for presentation and cannot be used for any calculations on server side?
Now I see that I cannot use the added attributes at least in auto-entities::template
, in card-mod
templates.
Then I will have to use Custom UI only for:
- icon
- icon color
- entity picture
- device_class
Just for test - let’s add "device_class"
by Custom UI (not as template):
customize_glob:
binary_sensor.battery_charging_life360_*:
device_class: battery_charging
templates:
battery_level: >
var SOURCE_DEVICE = entity.entity_id.split('battery_charging_life360_')[1];
var SOURCE_SENSOR_FULL = 'sensor.battery_life360_' + SOURCE_DEVICE;
var LEVEL = parseFloat(entities[SOURCE_SENSOR_FULL].state);
return (LEVEL / 100.0);
The result - there is a "device_class"
attribute:
The Template tab so far is OK:
And now let’s add the "device_class"
as a template:
customize_glob:
binary_sensor.battery_charging_life360_*:
# device_type: mobile
# device_class: battery_charging
templates:
battery_level: >
var SOURCE_DEVICE = entity.entity_id.split('battery_charging_life360_')[1];
var SOURCE_SENSOR_FULL = 'sensor.battery_life360_' + SOURCE_DEVICE;
var LEVEL = parseFloat(entities[SOURCE_SENSOR_FULL].state);
return (LEVEL / 100.0);
device_class: return 'battery_charging';
The result - there is a "device_class"
attribute:
The Template tab - same problem, the added "device_class"
does not exist: