-
Hey Team, Like to get some assistance making my yaml/code a bit more efficient/clean... The following snipet is for a ceiling light/fan, of which I have many. It works (I might tweak colors and size later - but for now it's good).
However, the downside to that code is that I have to copy it for each ceiling fan/light (of which I have many). So, I was hoping to make the code a bit more adaptive. My naming convention for these entities is "fan."room"_ceiling" and light."room"_ceiling". Along with an element that has the same name as the fan."room"_ceiling. What I would like to accomplish is to monitor the element, which drives one of the entities and use javascript to create the light name (by switching fan with light). Here's what my current iteration of that looks like (and no it doesn't work). One issue I am having is that using the inspect feature of my web browser doesn't show this section being executed - so I don't see what is going wrong (other than nothing happening with the ceiling fan/light). And obviously, I'm not totally sure I have this even formatted correctly (assuming this can work at all). Definitely appreciate any thoughts.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
What about a function? https://experiencelovelace.github.io/ha-floorplan/docs/usage/#custom-functions |
Beta Was this translation helpful? Give feedback.
-
And do you even need that. Here is a snippet from my floorplan when many entity/element combinations requires the same action:
|
Beta Was this translation helpful? Give feedback.
-
I can see OzGav did provide some great inputs here. Did you manage to get things under control? If so, consider sharing the solution here, as part of a follow-up comment :) |
Beta Was this translation helpful? Give feedback.
OK I think the main problem is using element.replace. I don't think element is exposed? Use
entity.entity_id
instead? Since you have named the element the same as the entity also change your first line toentity: fan.spare_ceiling
This worked on my test page:
console.log('entity', entity.entity_id.replace('input_number','fan'));