#Custom toggle buttons in a custom:button-card
1 messages ยท Page 1 of 1 (latest)
I have come up with two options for you. One is an entities card that has been modded to hide the icon and name. The second is a custom:button-card that essentially mimics a toggle switch with corresponding icons and colors. Here is the full code in implement usage of both in a custom:button-card. Each one has two elements: defining the custom_field (the card) and its style (where and how it is placed on the card). I did not try to use a grid template and define the layout. It was just easier to say where I wanted it to show.
type: custom:button-card
entity: light.living_room_lights
styles:
card:
- width: 250px
- height: 200px
custom_fields:
entities_card:
- position: absolute
- left: 0%
- top: 0%
- transform: rotate(270deg)
- opacity: 75%
custom_button_card:
- position: absolute
- right: 2%
- top: 5%
- transform: rotate(270deg)
- opacity: 75%
custom_fields:
entities_card:
card:
type: entities
entities:
- entity: input_boolean.tester
card_mod:
style:
hui-generic-entity-row:
$: |
state-badge {
display: none;
}
.info {
display: none;
}
ha-entity-toggle:
$: |
ha-switch {
--switch-unchecked-button-color: red;
--switch-checked-button-color: green;
--switch-unchecked-track-color: red;
--switch-checked-track-color: green;
}
card_mod:
style: |
ha-card {
border: none;
background: transparent;
}
custom_button_card:
card:
type: custom:button-card
entity: input_boolean.tester
show_name: false
state:
- icon: mdi:toggle-switch
value: 'on'
color: green
- icon: mdi:toggle-switch-off
value: 'off'
color: red
size: 50px
tap_action:
action: toggle
styles:
card:
- height: 50px
- width: 50px
- background-color: transparent
- border: none```
In the screenshot, both toggle buttons use the same entity. That's why the operate at the same time. I also rotated the toggle switches 270 degrees, because, why not? Just remove that line in the styles if you don't like it.
Custom toggle buttons in a custom:button-card
@orchid yacht tagging you since I think you might like the outcome.
I do indeed
that's the mdi trick?
wait I just read that it is
I should really read first, then ask
I really gotta organize my life
I think they both turned out pretty good. The entities option is a bit more complicated but it looks better and has a bit more customization available to it (requiring more card_mod). The custom:button-card is simplier but gets the job done.
I get a really weird outcome LOL
so I realized I needed the input_boolean, so I created one now I get this
ok so progress, I reloaded my browser
Yeah. Card mod can be a bit finicky sometimes. But you can see they both work reasonably well.
I'm going to post an alternative example. (I meant to do it last night but forgot.) Instead of using a toggle switch, I used the double tap action to toggle the input Boolean. Then, an indicator lights up to show that it is true. To me, it has a cleaner look.
post your yaml for the whole card. There shouldn't be much to have it work. Most of the code is just for the customization.
sec
type: custom:button-card
entity: switch.studydesk_2
styles:
card:
- width: 250px
- height: 200px
custom_fields:
entities_card:
- position: absolute
- left: 0%
- top: 0%
- transform: rotate(270deg)
- opacity: 75%
custom_button_card:
- position: absolute
- right: 2%
- top: 5%
- transform: rotate(270deg)
- opacity: 75%
custom_fields:
entities_card:
card:
type: entities
entities:
- entity: input_boolean.tester
card_mod:
style:
hui-generic-entity-row:
$: |
state-badge {
display: none;
}
.info {
display: none;
}
ha-entity-toggle:
$: |
ha-switch {
--switch-unchecked-button-color: red;
--switch-checked-button-color: green;
--switch-unchecked-track-color: red;
--switch-checked-track-color: green;
}
card_mod:
style: |
ha-card {
border: none;
background: transparent;
}
custom_button_card:
card:
type: custom:button-card
entity: input_boolean.tester
show_name: false
state:
- icon: mdi:toggle-switch
value: 'on'
color: green
- icon: mdi:toggle-switch-off
value: 'off'
color: red
size: 50px
tap_action:
action: toggle
styles:
card:
- height: 50px
- width: 50px
- background-color: transparent
- border: none
haven't changed much but the entity name LOL
I even made my input_boolean the same name
works just fine for me. (Changed your switch entity in the button-card to one of my lights.) Also, tried with a switch entity.
Tested in Firefox, Chrome, and Edge on PC. HA app on Andriod.
maybe i borked the input_boolean somehow?
power just went out at home so waiting on everything to come back up
well fuck me, power went down again
ok apparently power came back up but my LTE modem wasn't recognized by my router all of a sudden, heh
so I restarted and the toggles still don't work
I think I dumbed something up
is this right
custom_fields:
entities_card:
- position: absolute
- left: 0%
- top: 0%
- transform: rotate(270deg)
- opacity: 75%
custom_button_card:
- position: absolute
- right: 2%
- top: 5%
- transform: rotate(270deg)
- opacity: 75%
custom_fields:
the indent on the custom_fields: at the bottom
It is right. The top section defines the styles for the custom_fields. the bottom actually defines what the custom_fields are.
then I dunno what I did wrong LOL
what happens if you try just the entities card without any extras?```yaml
type: entities
entities:
- entity: input_boolean.tester```
dunno didn't think of that
maybe I made the input_boolean wrong
is it supposed to be toggle type?
Yup. That's all it needs. Settings > Devices & Services > Helpers tab > + Create Helper in bottom right > Toggle
it toggles the switches on the card in sync but does not toggle the light
Well there is no light attached to it. It is just an entity.
Try yaml type: custom:button-card entity: input_boolean.tester
Okay. So both cards can "see" and use the input boolean. I don't understand when the full code caused problems. Try type: custom:button-card entity: switch.studydesk_2 styles: card: - width: 250px - height: 200px custom_fields: entities_card: - position: absolute - left: 0% - top: 0% - transform: rotate(270deg) - opacity: 75% custom_fields: entities_card: card: type: entities entities: - entity: input_boolean.tester card_mod: style: hui-generic-entity-row: $: | state-badge { display: none; } .info { display: none; } ha-entity-toggle: $: | ha-switch { --switch-unchecked-button-color: red; --switch-checked-button-color: green; --switch-unchecked-track-color: red; --switch-checked-track-color: green; } card_mod: style: | ha-card { border: none; background: transparent; }basically just removing the custom:button-card toggle
tapping the light works, but the toggles don't, and there's only one now
the card there for studychair is using input_boolean.tester2.... so it's weird AF
So no change from green to red?
tester seems to activate one of the toggles on the card that tester2 is supposed to be on
wait im an idiot
I only changed one of the input_boolean.tester lines and there were 2, FML
ok that part is fixed
so now tester2 does what I expect it to LOL
what happens when you click tester in the top right corner?
this one ?
type: entities
entities:
- entity: input_boolean.tester
yeah. try toggling that one. the rest of the cards that correspond to the original tester entity should toggle too.
this is what happens when I hit just that one
all the toggles go green but do nothing for the switch
they're not going to do anything to the switch. that is is whole separate entity.
but it shows that everything is working except for being able to tap the toggle buttons in the cards.
ahh yeah
I can tap the icons and they work but not the toggles
well let me rephrase that
I can tap the toggles as well, they just do nothing but go green/red
umm... that's exactly what it is supposed to be doing... you're literally just toggling the state of the tester entity.
Now, the OP did not mention what his usage what for wanting something like this. Howegver, my usage would be to enable/disable an automation. Basically, add a state check of the toggle switch to the first line of the automation. If it is enabled, it continues; if not, it stops.
oh I dunno why I thought that the toggles were to turn the light on and off as well
bangs head against wall
For me, in Node-RED, this is what I have in a function javascript if (ha.states["input_boolean.automation_auto_office_lights"].state === "off") { node.status({ fill: "red", shape: "dot", text: "Automation disabled" }); return }
With this concept, you can easily turn it into a light switch within a light switch.
My method in the frontend is a bit different. Instead of a toggle switch, I have a label that appears. I toggle the input_boolean with a double tap.
Here is off
so the automatic is the boolean?
This is the template that I use for that button. Note that this template references another template (oversized_custom_button) so here, I'm just adding the "Automatic" feature yaml oversized_custom_button_with_auto: template: oversized_custom_button variables: var_auto_entity: input_boolean.automation_auto_kitchen_lights custom_fields: auto: > [[[ if ((states[variables.var_auto_entity].state === 'on')) return "Automatic"; ]]] styles: custom_fields: auto: - align-self: middle - justify-self: left - position: absolute - left: 3% - top: 3% - font-size: 24px - color: yellow - transform: rotate(0deg) - opacity: 33% double_tap_action: action: call-service service: input_boolean.toggle service_data: entity_id: '[[[ return variables.var_auto_entity; ]]]
The "Automatic" itself is simply a custom_field.
It essentially functions just like the toggle switch. Automatic = on; blank = off.
then the code for the card on the dashboard is yaml - type: custom:button-card template: oversized_custom_button_with_auto entity: light.kitchen_lights hold_action: action: navigate navigation_path: /fire-main/room variables: var_auto_entity: '[[[ return ''input_boolean.automation_auto_kitchen_lights''; ]]]'
I'm gonna try this out
but I don't have any automations really to turn on my lights yet
because I don't have any sensors
you have a phone with the HA app, right? an easy automation is turning lights off when you leave; on when you get home.
without sensors, you can "simulated" a sensor by making another input boolean: input_boolean:fake_motion_detecter_has_detected_motion ๐
but my outside lights will be on because they come on at dusk
if you wanted me to drink tonite you could have just said that
My coming/going automation:
yeah I need like 3 days to lock myself in my office and do all the things I need to do
hey you about man?
yup. I'm here. what's up?
sorry, power went out again only to find out it was the electrician testing and no one bothered to tell me
I have a question about your "coming home" in node-red
I have some zones I setup on the intersections on the way to my house but was trying to figure out the best way to use them to trigger "on the way home" "leaving home"
Well, that is kind of an issue with my automations. The way they're set up, they're basically
if state changes from Home to anything else = leaving home
if state changes from anything else to Home = arriving home
Sometimes the arriving home has fired before I get inside and sometimes not. I should tweak the automation so it also watches leaving from the Work zone and tie that in somehow.
well that's what I'm basically trying to do now, leave intersection 1 / enter my street/ home is arriving and home, end of my street, intersection 1 is leaving
actually I can use some math to do that I think
well there is a distance function that can be applied to a template in HA... that's what I started looking at. #templates-archived message
{% set home_lat = state_attr('zone.home', 'latitude') %}
{% set home_lon = state_attr("zone.home", "longitude") %}
{% set current_lat = state_attr('person.derek', 'latitude') %}
{% set current_lon = state_attr('person.derek', 'longitude') %}
{{ home_lat }} {{ home_lon }} {{ current_lat }} {{ current_lon }}
{% set dist = 6371.01 * acos(sin(home_lat)*sin(current_lat) + cos(home_lat)*cos(current_lat)*cos(home_lon - current_lon)) %}
6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
{{dist}} km
{{ distance(states.person.derek) | round(2) }}```
returns 1.1885028418603205 km 0.01This was the issue I was mentioning about the precision.
ok I just got a headache
LOL I haven't done cosines since highschool LOL
my math was just gonna be like "how many zones you pass thru before home or after home"
wtf did 6371.01 come from
what's that a measure of
distance between two latitutde and longitude cordinates in km
ahhhhhhhhh
ok makes sense
in km ? that's kinda like 1/3 the earths diameter
lol
I don't know how well "passing through" zones will work. Sometimes I don't think it updates quick enough and you might miss a zone. You might consider a larger "outer" zone around your house to catch as you're getting closer. But then you have to account for GPS accuracy and how big do you make the zone around your house.
also overlapping zones are an issue
I have to revisit how it gets handled a bit better. I was thinking about
when leaving work, check the distance
a couple minutes later, check distance: are you closer.
yeah. I think that is what I was noticing when I was trying to overlap the zone. sometimes would jump between home and Home...
basically I wanna do like "if leaves home, goes thru zone 1 and then zone 2 in 5 mins, considering me leaving"
but if something happens and HA doesn't get updated while you're in Zone 1, when you get to Zone 2, HA won't care.
this is true
this is gonna take a few beers to figure out and prolly me walking up and down the neighborhood tonite
but then again, I have a 4-6 minute commute to work; 4-20 minute commute back.
mine is 3 mins if im driving, 10-14 mins if I'm walking
nice.
I noticed an issue at one point where my location kept jumping between Home and Work. device tracker via my tablet was messing with it.
no. I have the app installed on the tablet too.
yeah but are you logged in to it? or a tabletuser
I'm logged into it. My Fire tablets have their own tabletuser.
I just took the tablet off from the device tracker for my user.
good idea
I did the same thing on all my other phones and tablets, they have their own user to login as
@royal bloom Here's another example of my hacky-ness. It fulfilled the request. ๐
@delicate patio nice ๐
@delicate patio btw, what is that automation diagram-tingy?
That's Node-RED. Another add-on that can be incorporated into HA via the Add-on store. It can access HA's entities and whatnot. It is a visual respresntation of automations put together with nodes. A node does a thing and then it continues to the next node to do another thing. Plus, there's a #node-red-archived channel.
It has a kind of step learning curve but once you start to get the hang of it things come together pretty easily. There's several good videos on YouTube that helped me out. I started automating with NR several years ago when HA's automations were strictly yaml (text) based. Let's just say things have improved since then.
TheHookUp's Node-RED video series is a good start: https://www.youtube.com/playlist?list=PL-51DG-VULPqeoYGyIrainyWc-_MnFb-y
Not afraid of a bit of yaml, but yes, things has become much easier ๐
agreed. I, too, am more comfortable with yaml now. Considering moving some automations from NR into HA but that involves doing work.
yes, much easer to leave stuff that work alone ๐