-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colored graph for tibber #1
Comments
I don't have control on the colors on that screen where you are, but we probably can have a card on your dashboard with the right colors.
This is pretty easy. I already have a "min" attribute a other sensor giving the lowest value available (which includes today and tomorrow) and another one called "future_min", which is kind of the same, but excluding the past hours of today. |
Well I was thinking about a seperate card (maybe Apexcharts) with only the colored bars for the prices.
Maybe on a "text-card" like |
Sorry, @6thGuest, I've been quite busy those days and couldn't work at this chart yet, but I was playing a bit with a table card that might help you in the meantime: This is the card I've used for this: https://github.com/edwardtfn/HomeAssistant-Config/blob/main/lovelace/library/cards/card_electricity_price_table.yaml |
Hey Edward, |
This card is using the attribute |
Perfect. |
Hey Edward, Now I tried to define a variable which changes the text-color (of only the energy-price cell) corresponding to the energy-price. But now I fail to define the comparison to "0". Can you help once more? |
Could you please share the yaml of your card as it is now? |
Try this:
|
This is like it is now:
I only want to change the textcolor in the "Strompreis" tab (energy). |
Try this: type: custom:flex-table-card
title: Strompreis-Level
entities:
include: sensor.electricity_price
sort:
- future_prices+
columns:
- name: Sorting columns
data: future_prices
modify: x.startsAt
hidden: true
- name: beginnt
data: future_prices
modify: |
{
var colors = [
{ level: "VERY_EXPENSIVE", color: "red" },
{ level: "EXPENSIVE", color: "goldenrod" },
{ level: "NORMAL", color: "green" },
{ level: "CHEAP", color: "limegreen" },
{ level: "VERY_CHEAP", color: "lightgreen" } ]
var startsAt = new Date(x.startsAt)
var d = new Date()
var sday = ""
if (startsAt.getDay() == d.getDay())
sday = "heute"
else
sday = "morgen";
'<div style="color: black; background-color: ' + colors.find(c => c.level === x.level).color + '">'
+ sday + " ab " + startsAt.getHours().toLocaleString('en-US', {minimumIntegerDigits: 1}) + " Uhr" +
'</div>'
}
align: center
- name: Level
data: future_prices
modify: |
{
var colors = [
{ level: "VERY_EXPENSIVE", color: "red" },
{ level: "EXPENSIVE", color: "goldenrod" },
{ level: "NORMAL", color: "green" },
{ level: "CHEAP", color: "limegreen" },
{ level: "VERY_CHEAP", color: "lightgreen" } ]
'<div style="color: black; background-color: ' + colors.find(c => c.level === x.level).color + '">'
+ x.level.replace('CHEAP', 'günstig').replace('NORMAL', 'normal').replace('EXPENSIVE', 'teuer').replace('VERY_', 'sehr ') +
'</div>'
}
align: center
- name: Strompreis
data: future_prices
modify: |
{
'<div style="color: black; background-color: ' + ( x.energy <= 0 ? 'green' : 'red') + '">'
+ (x.energy * 100).toFixed(2) +
' Ct/kWh</div>'
}
align: center
- name: Steuer/Gebühr
data: future_prices
modify: |
{
var colors = [
{ level: "VERY_EXPENSIVE", color: "red" },
{ level: "EXPENSIVE", color: "goldenrod" },
{ level: "NORMAL", color: "green" },
{ level: "CHEAP", color: "limegreen" },
{ level: "VERY_CHEAP", color: "lightgreen" } ]
'<div style="color: black; background-color: ' + colors.find(c => c.level === x.level).color + '">'
+ (x.tax * 100).toFixed(2) +
' Ct/kWh</div>'
}
align: center
- name: Gesamtpreis
data: future_prices
modify: |
{
var colors = [
{ level: "VERY_EXPENSIVE", color: "red" },
{ level: "EXPENSIVE", color: "goldenrod" },
{ level: "NORMAL", color: "green" },
{ level: "CHEAP", color: "limegreen" },
{ level: "VERY_CHEAP", color: "lightgreen" } ]
'<div style="color: black; background-color: ' + colors.find(c => c.level === x.level).color + '">'
+ (x.total * 100).toFixed(2) +
' Ct/kWh</div>'
}
align: center |
Yeah - thanks again
|
Great. - name: Level
data: future_prices
modify: |
{
var table = [
{ level: "VERY_EXPENSIVE", color: "red", translation: "Sehr teuer" },
{ level: "EXPENSIVE", color: "goldenrod", translation: "Teuer" },
{ level: "NORMAL", color: "green", translation: "Normal" },
{ level: "CHEAP", color: "limegreen", translation: "Günstig" },
{ level: "VERY_CHEAP", color: "lightgreen" }, translation: "Sehr günstig" ]
'<div style="color: black; background-color: ' + table.find(c => c.level === x.level).color + '">'
+ table.find(c => c.level === x.level).translation +
'</div>'
}
align: center |
Okay - I'll try this. This is my try:
This drives me maaaaaaaad :-( |
The problem is on the data format. This card is not prepared to handle fields inside an attribute, so all your columns are showing the same attribute ( Something like this: type: custom:flex-table-card
sort_by:
- today+
title: Tibber - Test
entities:
include: sensor.electricity_price
columns:
- name: Sorting column
data: today
modify: x.total
hidden: true
- name: beginnt
data: today
modify: |
{
var colors = [
{ level: "VERY_EXPENSIVE", color: "red" },
{ level: "EXPENSIVE", color: "goldenrod" },
{ level: "NORMAL", color: "green" },
{ level: "CHEAP", color: "limegreen" },
{ level: "VERY_CHEAP", color: "lightgreen" } ]
var startsAt = new Date(x.startsAt)
var d = new Date()
var sday = ""
if (startsAt.getDay() == d.getDay())
sday = "heute"
else
sday = "morgen";
'<div style="color: black; background-color: ' + colors.find(c => c.level === x.level).color + '">'
+ sday + " ab " + startsAt.getHours().toLocaleString('en-US', {minimumIntegerDigits: 1}) + " Uhr" +
'</div>'
}
align: center
- name: Gesamtpreis
data: today
modify: |
{
var colors = [
{ level: "VERY_EXPENSIVE", color: "red" },
{ level: "EXPENSIVE", color: "goldenrod" },
{ level: "NORMAL", color: "green" },
{ level: "CHEAP", color: "limegreen" },
{ level: "VERY_CHEAP", color: "lightgreen" } ]
'<div style="color: black; background-color: ' + colors.find(c => c.level === x.level).color + '">'
+ (x.total * 100).toFixed(2) +
' Ct/kWh</div>'
}
align: center |
It is a YAML using Javascript to create a HTML with CSS... |
Slowly but surely I seem to get in... I added an additional attribute to the sensor (for the future prices of only today)...
And now I can sort the prices of only today in ascending order:
|
Short feedback... |
Hey Edward,
since I am totally unexperienced in programming I had to use "copy-paste" and "try-and-error" for integrating the tibber price graphs into HA.
I only used your rest-sensor:
It also states "Cheap, normal and expensive".
Now I wonder if it is possible to create a line or bar chart with the different colors for it.
E.g. cheap=green, normal=yellow and expensive=red and/or a sensor which states the times with the cheapest prices maybe like this:
"Cheapest today: 01:00:00 - 02:00:00
15:00:00 - 16:00:00"
"Cheapest tomorrow: 07:00:00 - 08:00:00"
Do you think it is possible to create something like this?
THANKS so far!
The text was updated successfully, but these errors were encountered: