11125
(Тони Станојоски)
November 18, 2022, 12:04am
1
Hello,
I am not really good with javascript so I need help. its about the Earthquake sensor in custom-button-card. The attributes are the earthquake at the specified distance.
platform: emscrss
name: Earthquakes
radius: 300
magnitude: 2.0
the attributes atm:
How to get the attributes for manipulation? this is what i have for now
[[[
// javascript
var quakes = Number((states['sensor.earthquakes'].state));
var closest_earthquake_distance = 0
var title = 0
quakes.forEach
return closest_earthquake_distance + title
]]]
nickrout
(Nick Rout)
November 18, 2022, 7:18am
2
Please read this, all the way through. Then at a minimum post your code properly.
11125
(Тони Станојоски)
November 18, 2022, 9:14pm
3
sorry, I thought the rest of the code was not relevant… here goes the full code:
the code in question is at the end.
type: custom:button-card
layout: icon_state_name
show_state: false
show_name: true
show_label: true
tap_action:
action: navigate
navigation_path: /lovelace-stanojoski/7
styles:
card:
- padding: 10px
- height: 60px
- border-radius: 10px
- font-weight: bold
- background-color: |
[[[
// javascript
var boja = "" ;
var maks = Number((states['sensor.earthquakes'].state));
if (maks == 0) {boja = 'lime';}
else {boja = 'red';}
return boja
]]]
grid:
- grid-template-areas: '"i n des" "i l des"'
- grid-template-columns: 30% 70%
name:
- justify-self: start
- font-weight: bold
- font-size: 18px
- color: |
[[[
// javascript
var boja = "" ;
var maks = Number((states['sensor.earthquakes'].state));
if (maks == 0) {boja = 'black';}
else {boja = 'white';}
return boja
]]]
label:
- justify-self: start
- font-size: 15px
- color: |
[[[
// javascript
var boja = "" ;
var maks = Number((states['sensor.earthquakes'].state));
if (maks == 0) {boja = 'black';}
else {boja = 'white';}
return boja
]]]
icon:
- color: |
[[[
// javascript
var boja = "" ;
var maks = Number((states['sensor.earthquakes'].state));
if (maks == 0) {boja = 'black';}
else {boja = 'white';}
return boja
]]]
icon: mdi:earth
label: |
[[[
// javascript
var quakes = Number((states['sensor.earthquakes'].state));
var closest_earthquake_distance = 0
var title = 0
quakes.forEach
return closest_earthquake_distance + title
]]]
name: Earhquakes
11125
(Тони Станојоски)
November 27, 2022, 1:13pm
4
workaround… I built a few automations to give me all the needed data.