Iām trying to have an SVG icon moving around over everything of the dashboard, (mimik a robot vacuum cleaning the house) with this JS code. The JS code wonāt seem to make it move, is there some limitation with HA or i made a mistake?
type: custom:config-template-card
entities: []
card:
type: custom:html-template-card
content: |
<div id="vacuum">
<img src="/local/appliances/robot_shark_anime_thickW.svg" width="50px" height="50px" />
</div>
<script>
$(document).ready(function(){
animateDiv();
});
function makeNewPosition(){
var h = $(window).height() - 50;
var w = $(window).width() - 50;
var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);
return [nh, nw];
}
function animateDiv(){
var newq = makeNewPosition();
var oldq = $('#vacuum').offset();
var speed = calcSpeed([oldq.top, oldq.left], newq);
$('#vacuum').animate({ top: newq[0], left: newq[1] }, speed, function(){
animateDiv();
});
}
function calcSpeed(prev, next) {
var x = Math.abs(prev[1] - next[1]);
var y = Math.abs(prev[0] - next[0]);
var greatest = x > y ? x : y;
var speedModifier = 0.1;
var speed = Math.ceil(greatest / speedModifier);
return speed;
}
</script>
Hey, Iād like to use the dashboard-wide variables feature, which I understand is only in the master branch (not yet released). But HACS only gives me a spinning wheel forever, when I try to install the master branch. Is there a trick, I am missing?
Hi, I canāt see an answer in this thread but it may have been covered beforeā¦I want to show different cards depending on a variable state (if rain is coming, show the graph, otherwise show a markdown card that says no rain is coming)
I have the card working to show the graph and using a call to a variable it changes the title of the chart, but now I just want to be able to switch which card is used (or maybe change the style so the one I donāt want is hidden via CSS).
is that possible?
Current card, if its useful, is:
- type: custom:config-template-card
variables:
getWeatherStatus: >
var entity =
states['sensor.openweather_all'].attributes.minutely;
var data = [];
var nextTime = 0;
for (let i = 0; i < 59; i++) {
if (Object.values(entity[i])[1] > 0 ) {nextTime = 1000 * Object.values(entity[i])[0];break;}
}
console.log(Math.floor(((Date.now() - nextTime) / 1000)/60));
var nextMessage = "No rain expected in the next hour";
if (nextTime > 0) {
if (Math.floor(((nextTime - Date.now()) / 1000)/60) <= 5) {
console.log("soon");
nextMessage = "š§ļø is expected very soon";
} else {
console.log("later");
nextMessage = "Rain expected in " + Math.floor(((nextTime - Date.now()) / 1000)/60) + " minutes";
}
}
nextMessage;
entities:
- sensor.openmeteo_15min_data
- sensor.openweather_all
card:
type: custom:apexcharts-card
stacked: true
header:
show: true
title: ${ getWeatherStatus }
apex_config:
yaxis:
show: false
max: 0.3
chart:
height: 100px
grid:
show: false
legend:
show: false
graph_span: 45min
span:
start: minute
series:
- entity: sensor.openweather_all
type: column
name: Rainfall
float_precision: 3
color: '#CC630F'
data_generator: |
var data = []
for (let i = 0; i < 59; i++) {
data.push([1000 * Object.values(entity.attributes.minutely[i])[0], Object.values(entity.attributes.minutely[i])[1]]);
}
console.log("testing from here");
console.log(data);
return data;
I was wondering about state-switch, which I already use. It has a template option for state, which uses jinja statements to define the state which you can then set a switch on. But can I make a call to a config-template-card variable from within in a jinja template - I suppose it probably just needs to be a simple bit of jinja that literally returns what the variable is?
Also, whilst the state-switch card responds to state changes in real time, how would that work with the config-template variable embedded - does that variable actually get refreshed by config-template-card at any point?
I would not recommend using CTC as a topmost card - i.e. ABOVE state-switch. Use CTC on the bottommost level.
In many cases CTC may be not used at all. In your case you are using CTC only to get a dynamic title - and a very complex & resource-wasting card is placed inside CTC. Use a simple Markdown to show a dynamic title (& remove a gap between apexcharts & markdown by cardmod - see details in corr. threads) or compose a dynamic title by card-mod & ā:afterā pseudoclass (ask details in card-mod thread).
You should avoid complexity since this is not a simple thing:
All fair points. I think that if I link state-switch card to the weather forecast entity then it will refresh as that is updated, and I could then just hide the graph if I always show the markdown above it with the title. I have made a template before that cycles through that forecast so I can just reuse that in the SS card template to return true (rain expected) or false (dry), with true being the CTC card plus chart, and false being blank
That might also mean the graph gets updated after every forecast refresh thanks to the SS link to the entityā¦otherwise might have to do something nasty like having two graphs and changing the state of the SS card thus flip flopping between them. if SS doesnāt otherwise refresh the cards when the linked entity refreshesā¦hope not!!
SS listens to the āstatesā object & is supposed to switch cards immediately.
Updating the inner cards - a different issue: it is a job to be done by these cards themselves.
When a card is placed inside CTC - it is a different story: the inner card will be updated (full redraw in fact - which is not desirable for graph cards, stock gauge card, ā¦) if some āmonitoredā entity (i.e. declared in āentitiesā option) is changed.
The forecast weather sensor attribute will change every couple of minutes, and for every change the graph will need to redraw as it shows the next hour of data, so I am ok with that.
Iām starting to come back to CTC being the master here, as it will refresh when the entity updates, when SS might refresh. As the CTC will always be shown (as the markup card at least is always shown) this way I have one CTC and not two (one per SS state). Performance wise itās for one dashboard and Iāll take the hit I think (itās not like Iām rolling this out in a mass consumed platform)
Within I will do the always visible markup card and the chart that Iāll hide. I guess I may as well do that then with a css visible settingā¦
Not the most elegant but functionalā¦.if it will work as planned!