Sensor template: influxDB

Hello,

I have setup a template sensor that calculates watts from amps and voltage:

home_load:
            friendly_name: "Home load"
            icon_template:  mdi:flash
            value_template: >
                {% set tvalue = ( ( states.sensor.average_battery_current.state|float - states.sensor.whizbangjr_amps.state|float ) * states.sensor.average_battery_voltage.state|float  )|round  %}
                {%- if tvalue|int >= 0 %}
                    {{ tvalue }}W
                {%- else %}
                    External Load Detected
                {%- endif %}

It works well but doesn’t update my influxDB database.

Is it a bug ?

That depends on how you have set up the influxdb component in configuration.yaml.

@gpbenton would you mind elaborating? Which indexedb specific configuration were you thinking about ? It is pretty basic, host, user, password, database …

But I think I found the issue. I guess that because of added the ‘W’ unit something goes wrong in storing the value in InfluxDB.

I created a new “raw” sensor and then tuned this one. Now the raw data get stored in InfluxDB:

home_load_raw:
            unit_of_measurement: "W"
            value_template: >
                {% set tvalue = ( ( states.sensor.average_battery_current.state|float - states.sensor.whizbangjr_amps.state|float ) * states.sensor.average_battery_voltage.state|float  )|round  %}
                {%- if tvalue|int >= 0 %}
                    {{ tvalue }}
                {%- else %}
                    ''
                {%- endif %}

        home_load:
            icon_template:  mdi:flash
            value_template: >
                {%- if states.sensor.home_load_raw.state|int >= 0 %}
                    {{ states.sensor.home_load_raw.state|int }}W
                {%- else %}
                    External Load Detected
                {%- endif %}

For example, you could have had an include or exclude section, which could have prevented it being added it to the database. Without that information, nobody could tell if it was a bug or not. But I am glad you fixed the problem.

I am not sure, but you may find your original template in a ‘W’ measurement stream, as I have a C stream for temperature measurements.

1 Like