Hi all
Very green newbie here. I’m getting on ok as far as my install, nabu casa, and using visuual editor
I have myenergi solar, BMW Connected Drive, Sonoff/eweLink, Tuya, Sonos integrations working
But there are a couple of things bugging me that I think can be solved by creating entities/sensors in the configuration.yaml file.
To this end I have installed the Studio Coder Server and can open and edit my configuration.yaml file…
Now to the problems:
I was messing around looking at samples of entities and sensors that folks had posted as solutions to other folks’ problems, amd I added a couple of chunks of code. I even made a ‘pressure sensor’ with a value of 5. Great I thought. Then I deleted that. But the entity is still there! How do I get rid of it? I searched this forum for that and I found folks writing about ‘lovelace’ and I’m totally lost. So if you can tell me how to get rid of enetities that I created and then deleted from my configuration.yaml file that would be great!
Secondly, I am trying to make sensor entities which are based on ones coming from the myenergi integration with my myenergi solar inverter control system.
The existing entity which measures powet to and from the electricity grid can be both positive and negative, positive indicating power drawn from the grid, and negaitive indicating export to the grid. I would like to have a dashboard which shows the export as a positive number. How do I do that? (The existing entity’s id is sensor.myenergi_home_solar_power_grid)
Lastly I’d like to be able to make a new entity which uses a formula acting on one or more entities - for example I’l like to be able to add two together and then divide by a third one to get a percentage value, and I’d like to be able to multiply the value of another by a constant value like 1.3.
“Lovelace” is an old name for the dashboards. It’s never quite gone away . You can use templates in some dashboard cards, but if you’re working on your configuration.yaml, posts about that are probably not relevant to what you’re doing.
If you’re trying to create a sensor entity, the best place to do it is in Developer Tools | Template, which is a sort of sandbox for experiments. When you’ve got it right you can copy it to configuration.yaml. The value of the sensor can then be displayed in a dashboard.
If you haven’t already, you’ll need to read up on templating.
Entities removed from configuration.yaml should disappear after a restart.
When you created the sensor entity’s configuration, did you configure it with the unique_id option?
If you did then the entity’s configuration is recorded in a hidden config.entity_registry file. Simply deleting its configuration from configuration.yaml will not eliminate it.
Go to Settings → Device and Services → Entities
Find the deleted “pressure sensor” entity in the list of all entities.
Check if it has an icon displayed in its Status column.
Click the icon and a popup should offer a means of deleting the entity (it will be removed from the entity registry).
You’re going to have to tell us a lot more about this sensor’s configuration. Either post its configuration or, if it’s no longer available, explain as much as possible about what you created.
As advised by @jackjourneyman I played with the template editor under developer tools.
I got {{states.sensor.myenergi_charger_grid_ct2.state|int|abs}} to output what I wanted… then I made a template Helper and put this in it and it works a treat!
Is that the best way to do it?
I note that I didn’t have to open and edit configuration.yaml, which is fine by me but maybe there’s a more efficient/elegant solution?
Template helpers are a fairly recent innovation to make templates accessible through the UI - you can do it either way, but complex templates still have to be done in configuration.yaml.
Refer to the warning at the bottom of the States section of the Templating documentation regarding the optimal way to reference an entity’s state value. HINT: It is not states.sensor.foo.state)
In addition, when you use a filter like int or float you should configure them with default values. If they are given a value they can’t convert to integer or floating point they will use the default value. Without a default in that situation, they generate an error (i.e. the template fails).
For future reference, you can test your template in the Template Editor (Developer Tools → Template).
It’s a great tool for experimenting with a template and confirming it works properly before you use it in Template Sensor or Template Condition or Template Trigger, etc.
NOTE
You may notice that if you post a template in the forum but don’t format it as being code, the forum’s software converts standard quotes into “fancy” quotes.
Compare the opening and closing quotes here:
{{ states(‘sensor.myenergi_charger_grid_ct2’)|int(0)|abs}}
Here’s one way to do it. It uses Jinja2 variables to help make the formula easier to read.
Change the entity_ids to match yours.
{% set g = states('sensor.grid_power') | float(0) %}
{% set p = states('sensor.panel_power') | float(0) %}
{% set b = states('sensor.battery_discharge_power') | float(0) %}
{{ 100 if g < 0 else (p+b)/(g+p+b) * 100 }}
EDIT 1
Correction. Added missing |
(See jackjourneyman’s post below).