Heatmap with categorical axis labels #215
Replies: 3 comments 5 replies
-
This is soo great. Thx a lot. |
Beta Was this translation helpful? Give feedback.
-
Here an adopted one with
Of course my copy&paste-JS-capabilities is leading to quick and most probably dirty code and is most proably easily to improve, but at least it is working for now and will be my starting point for other measures like CPU-temp, DSL-speed or whatever else is good to read on a heatmap to see differences and outliers and rules.
|
Beta Was this translation helpful? Give feedback.
-
Adapted these to pull out On/Off values from a Hue motion sensor, converted to detection durations to display when rooms are most active. Thanks so much for including these new graphs, been looking to get heatmaps for ages (can you tell what time I'm cooking?) type: custom:plotly-graph
entities:
- entity: binary_sensor.kitchen_motion_sensor_1_motion
filters:
- deduplicate_adjacent
fn: |
$fn ({ xs, ys, vars }) => {
const colorscale = [
['0.0', 'rgb(12, 51, 131)' ],
['0.2', 'rgb(10, 136, 186)' ],
['0.5', 'rgb(242, 211, 56)' ],
['0.6', 'rgb(242, 143, 56)' ],
['1.0', 'rgb(217, 30, 30)' ],
];
var days = [];
var durations = [];
var prevOnindex = -1;
ys.forEach( function( y, index, arr) {
if( y == "off" && prevOnindex > -1) {
const lastOnDate = xs[ prevOnindex ];
const lastOnTime = lastOnDate.getTime();
const lastOffTime = xs[ index ].getTime();
const duration = ( lastOffTime - lastOnTime ) / 1000 / 60; // Convert to mins
days.push( lastOnDate );
durations.push( duration );
}
else
prevOnindex = index;
} );
const day = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", ];
const timeSpan = [
"11pm","10pm","9pm","8pm","7pm","6pm","5pm","4pm","3pm","2pm","1pm","Midday",
"11am","10am","9am","8am","7am","6am","5am","4am","3am","2am","1am","Midnight",
];
// const timeSpan = ["Morning", "Afternoon", "Evening"];
const sum = timeSpan.map((time) => day.map((day) => 0));
debugger;
for (let i = 0; i < days.length; i++) {
const date = days[i];
const time = 23 - date.getHours();
// const time = Math.floor(date.getHours() / 8); // 24/8 gives us Morning/Afternoon/Evening
const day = date.getDay();
sum[time][day] += +durations[i];
}
const z = sum.map((row, time) =>
row.map((val, day) => val == 0 ? null : val )
);
vars.x = day;
vars.y = timeSpan;
vars.z = z;
vars.colorscale = colorscale;
};
x: $fn ({ vars }) => vars.x
'y': $fn ({ vars }) => vars.y
z: $fn ({ vars }) => vars.z
type: heatmap
hoverongaps: false
colorscale: $fn ({ vars }) => vars.colorscale
raw_plotly_config: true
hours_to_show: current_week
title: Kitchen Motion (last 7 days)
layout:
height: 500
margin:
t: 20
|
Beta Was this translation helpful? Give feedback.
-
Adapted from https://plotly.com/javascript/heatmaps/#heatmap-with-categorical-axis-labels
Beta Was this translation helpful? Give feedback.
All reactions