Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Possibility to add sensorname prefix #3

Open
dflvunoooooo opened this issue May 30, 2023 · 7 comments
Open

[Feature Request] Possibility to add sensorname prefix #3

dflvunoooooo opened this issue May 30, 2023 · 7 comments

Comments

@dflvunoooooo
Copy link

dflvunoooooo commented May 30, 2023

It would be great to add the possibility to add a prefix to the entity names of the sensors. I will install this on more than one machine and it would be terrible if I had to change every single sensor in home assistant. Here is a config option which lets one choose to set a prefix:

# Define sensor prefix. Options: 0 = none (default and if not 1 or string), 1 = hostname, custom if string
SENSOR_PREFIX_OPTION=0

And here is a function which checks if the option is set and runs itself:

sensor_prefix_generator() {
    if [ $SENSOR_PREFIX_OPTION == "0" ]; then
        SENSOR_PREFIX=""
    elif [ $SENSOR_PREFIX_OPTION == "1" ]; then
        SENSOR_PREFIX=$(cat /proc/sys/kernel/hostname)
    else 
        SENSOR_PREFIX=$SENSOR_PREFIX_OPTION
    fi
    
}
sensor_prefix_generator

The variable SENSOR_PREFIX would have to be added to the sensor names.

I am not good at programming, and I am not yet very familiarly with this awesome program, that is why I didn't create a pull request. For example, I don't know if it is common to define a function and then run it immediately afterwards. If I can help in anyway, please say so.

@roger-
Copy link
Owner

roger- commented May 30, 2023

I use this to monitor multiple machines myself and it organizes sensors into devices, not just entities. When you create automations you can select the appropriate machine device name then select the sensor (assuming you use the GUI).

Does that work for you?

@dflvunoooooo
Copy link
Author

Ah great. I would still prefer to reflect the machine name in the entity name, but I would be fine with the devices. Where are they organised as devices? In MQTT there is a device with the host name, but it there are no entities associated with that device.

@roger-
Copy link
Owner

roger- commented May 30, 2023

Go to the Devices tab and you should see a unique device for each machine.

@dflvunoooooo
Copy link
Author

dflvunoooooo commented May 30, 2023

I found it, thank you very much.

@dflvunoooooo
Copy link
Author

dflvunoooooo commented May 30, 2023

I successfully adapted your code to include sensor name prefixes. Are you open to pull requests or should I keep the code for myself?

@roger-
Copy link
Owner

roger- commented May 30, 2023

Sure, please do and I'll review. I may want to do it a little different though

@dflvunoooooo
Copy link
Author

dflvunoooooo commented May 30, 2023

#5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants