great piece of work but i got some questions
I have several sensors available for use and couple of them are a negative input when i’m using power or are negative when i’m injecting my surplus of solar power to the grid, is there a way to also display the injection?
I tried to adapt for the negative part myself but i must be like missing something somewhere.
besides that is it possible to work from both sides of the strip? Because I also have a batterysystem connected to my solar inverter and it would be nice to display the state of charge also…
So if i got a strip of 100 leds if i could use like 50 for power usage/injection and the other 50 for displaying the battery status.
This is what i got for the moment:
alias: Energy Usage LED
description: Display a meter bar for the house energy usage
trigger:
- platform: state
entity_id:
- sensor.p1_meter_3c39e7243e44_active_power
action:
- service: rest_command.wled_update
data:
payload: "{\"on\": true}"
- service: rest_command.wled_update
data:
payload: >-
{##### INPUTS #####} {# Use the value of the entity that has triggered
the automation #} {% set sensor_entity_id = trigger.entity_id %} {% set
sensor_entity_id = "sensor.p1_meter_3c39e7243e44_active_power" %} {#
Value that should fill the complete meter #} {% set max_value = 5000 %}
{# Number of leds in the strip #} {% set led_count = 100 %} {#####
CALCULATION #####} {# Fraction of the meter that should be on #} {% set
sensor_value = states(sensor_entity_id) | float(default=0) %} {% set
fraction = sensor_value / max_value %} {% set brightness = 100 %} {# LED
parts: normal for the active bar, then highlight the exact value, then
lowlight the inactive part #} {% set highlight_end_leds = (fraction *
led_count) | int %} {% set normal_end_leds = highlight_end_leds - 3 %}
{% set lowlight_start_leds = highlight_end_leds %} {# Resulting segments
to send to WLED #} {# - Start with turning everything off #} {% set
result = namespace(segments=[0, led_count, [0,0,0]]) %} {##### HELPERS
#####} {# Add a segment, while a possible scaledown in brightness #} {#
- Reversed start/end because strip is upside down #} {% macro
segment(start_led, end_led, color, scaledown=1) -%}
{%
set result.segments = result.segments + [
led_count - end_led,
led_count - start_led,
[
(color[0] / scaledown) | round(0, 'ceil'),
(color[1] / scaledown) | round(0, 'ceil'),
(color[2] / scaledown) | round(0, 'ceil'),
]
]
%}
{%- endmacro %} {# List of color blocks, references sensor values #} {%
set blocks = [
{"start": -2000, "end": 0, "color": [0, 0, 255]},
{"start": 0, "end": 1000, "color": [0, 255, 0]},
{"start": 1000, "end": 2500, "color": [255, 255, 0]},
{"start": 2500, "end": max_value, "color": [255, 0, 0]},
]
%} {% for block in blocks %}
{# Convert sensor values of the block to led counts #}
{% set block_start_leds = (block.start / max_value * led_count) | round %}
{% set block_end_leds = (block.end / max_value * led_count) | round %}
{# NORMAL segment #}
{% if normal_end_leds >= block_start_leds %}
{{
segment(
[block_start_leds, 0] | max,
[block_end_leds, normal_end_leds] | min,
block.color,
scaledown = 1
)
}}
{% endif %}
{# HIGHLIGHT segment: If the highlight overlaps this block, add a highlight #}
{% if ([block_start_leds, normal_end_leds] | max) <= ([block_end_leds, highlight_end_leds] | min) %}
{{
segment(
[block_start_leds, normal_end_leds] | max,
[block_end_leds, highlight_end_leds] | min,
block.color,
scaledown = 1
)
}}
{% endif %}
{# LOWLIGHT segment: when a part of this block is inactive #}
{% if lowlight_start_leds <= block_end_leds %}
{{
segment(
[block_start_leds, lowlight_start_leds] | max,
[block_end_leds, led_count] | min,
block.color,
scaledown = 100
)
}}
{% endif %}
{% endfor %} {# Print results, passing it to the rest command #} {# -
Use full segment brightness, but lower strip brightness #} {# - Turn
on/off based on living room usage #} {{
{
"bri": brightness,
"seg": {
"bri": 255,
"i": result.segments
}
}
}}
mode: restart
Thanks in advance for any input!