Create a new entity / sensor

Hi HA Commuinty

I’m new in HA so sorry if this is a stupied question.

According to this link: AUTOMATION - Gracefully Shutdown VM’s & ESXi Host via SSH - Community Guides - Home Assistant Community (home-assistant.io) I was able to configure HA and my EXSi so that I can now switch off or get the current power state from a VM.

For example:
To get current power state form am VM I added the fellow command to my configuration.yaml file:

In HA under settings → services I can run this shell command and receive the following response:

My goal is now something like this…
HA_3

…but instead of lamps, I want my VMs. This way I could see the current power state of all VMs and if necessary I could switch off a machine.

I start to tested it once with the following automation…
HA_4

…and it worked. I received a message with the answer from ESXi.

But now I don’t know how to store this information in HA so that I can display it on a lovelace card.

Is it possible to create own entities or sensors for this case? Or what ist best way to achieve this?

Thanks and best regards
Buhli

how does it show up on your entities list? it is a button? switch? or just a word. stating wether its on. lmk. or send a screenshot of what the entity gui looks like. i might be able to help then.

Hi hbhostetler5

Thank you very much for your quick reply.

Unfortunately I have nothing. No entities, sensors, etc… As described, I have only this command - sorry.

Can you maybe still help me in some way?

Thanks and best regards
Buhli

you can make an automation to check for it at intervals and have it tell a helper weather its on or off. can you try that?

also, no problem for the quick reply

im headed to bed because its 12 here but lmk if that works. if not ill respond when i can. good luck :slight_smile:

Thank you very much.

I will try it yes. But honestly, I am a little overwhelmed right now

What kind of helper would you use? A text?

In my test automation, the response is temporarily stored in this “todo_response” variable.

Would you store the whole answer in a helper variable? Or can I already check during the automation if the status is On or Off?

Thank you very much and have a good night :slight_smile:

Best regards
Buhli

Create a template switch.

1 Like

Hi tom_l

Thank you very much for your answer.

I have also looked at this template, but I didn’t know how to apply it to my case.

For example, what exactly is “garage:” Is it just a name that I can assign myself? Or is there something behind this name?

Or by target and entity_id. In my case I don’t have an entity. What can I enter there? Or can I just leave it out.

Thanks and best regards
Buhli

Yes you can put any lower case name in place of “garage”.

You want to call the shell command that turns your VM on in the turn_on script. Likewise for turn_off.

Thank you very much.

Sorry again for my stupied questions. But still I have not fully understood the principle of this template.

I have 5 VMs. That means I have to create 5 templates?

Something like this:

HA_7

And I am also not 100% sure what I have to use bei value_template

Thank you very much
Buhli

Yes , five template switches, one for each VM.

The value template gets feedback about your switch states in case you turn a VM on or off some other way than by using the controls in home assistant. It keeps the switch state shown in the dashboard synchronised with the actual VM state.

Do you have sensors to get the state of the VMs?

EDIT: also please don’t share pictures of text. Paste the text here and format it correctly, https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Perfect

No, unfortunately not. Until now I have only this shell command to turn off the machine and to get the current power state. Can you maybe tell me what I can put in the value_template? Or should I leave it out, since I don’t have any sensors?

Thank you for the hint and sorry.

Thank you very much and best regards
Buhli

If your VMs have individual IP address you could set up a ping sensor for each to determine their state:

These could then be used in the value_templates.

That’s great :slight_smile: I will test it with this sensor.

But this “value_template” still confuses me a bit.

Example from HA:

value_template: "{{ is_state('cover.garage_door', 'on') }}" 

For me it looks like an IF condition. If the state from the garage door is on, then something should happen. But what exactly?

Thanks and best regards
Buhli

If the template resolves to true or on the switch state shown will be changed to on. If the template resolves to false or off the switch state shown will change to off.

It works :slight_smile: thank you very much for the support.

Is it possible to change the icon color from this switch template?

Best regards
Buhli

No. That has to be done in either a theme or the frontend.

thanks again to all for the support

1 Like