you’re putting sensor config code in your front end lovelace dashboard ui.
sensors should be defined in your configuration.yaml. then you might refer to it in your front end.
give this a good read:
define your sensor and make sure it shows up in your entities list and has the state values correct. then go build the front end card.
What @armedad said. Here’s the template sensor you want, in modern format. You cannot do this via the UI: you need to put it into your configuration.yaml (docs).
If you already have a line in configuration.yaml like:
template: !include templates.yaml
put the config below into that file (templates.yaml) without including the template: first line and moving the rest two spaces left.
If you already have a template: header in that file with configurations under it, put it underneath that, without repeating the first line header.
Restart HA to pick up the new sensor. In future, you can do Developer Tools / YAML / Template entities to reload without restart, but you must restart for the first one.
The two templates assumes the possible states you list are the correct ones: they then convert that state into the MDI icon name and filename; and the filename one assumes that the capital Q in xfirst_Quarter.png is correct.
In English, by the way, it’s “phase”. Doesn’t matter here though.
It should not: I supplied the picture template that replaced it in modern template sensors. Remove the entity_picture_template completely — I know it looks much smaller without it, but all of the logic is there: your original was very inefficient.
You can paste it into Developer Tools / Template to see it resolve the icon and picture filenames.
Also, read what I wrote:
That file should start with
- sensor:
HOWEVER — I think this could be more easily achieved just by using the Picture Entity Card correctly. See the second example here:
So you’d have this as the card code:
type: picture-entity
entity: sensor.moon_fase
state_image:
"New moon": /images/moonphases/xnew_moon.png
"Waxing crescent": /images/moonphases/xwaxing_crescent.png
[and so on]
with no need for a template sensor. Just need to make sure those images are accessible, with the URL probably under /local/. See here:
Read the link in my last post. These are URLs under state_image. Does this work for you if you fill in the IP address and paste into your browser?
http://[YOUR HA IP]:8123/images/moonphases/xnew_moon.png
If it doesn’t display the image, then it won’t work in the picture card either. Read the link and work out how to display stored images via your browser.
Also, what is the actual state of the sensor? Is it “Waning crescent” or “Afnemende, sikkelvormige maan”? Go to Developer Tool / States and see what the result is for:
That doesn’t work: I have to put my ip adres in front of the local/… so: my-ip/local/…
then it shows up in my browser
I removed the x in the names
still no moon picture
my sensor moon_fase says: see below (waning_cresent)
I made a typo error: Not a capital in the name.
I have a picture now of the waning_crescent
Only it’s to big!
Is there a way of down sizing it (with HA code) other than use photoshop and resize it to a smaller picture (100x100 px)?
I did know that (picture-element)
But why doesn’t it show in picture-entity
somewhere i am making a stupid mistake but where???
i am just messing around because i don’t see / know it what to do.
sorry for that
this is what i got now
The moon is too big and the bg-moon (api/…) is gone
I tried style: nothing what the heck …
I am confused
How to get this super imposed on the bg-moon image including the state
or i get the state without the moon, or i get the moon without te state
i would like to have both