When I transfer the following data (batt,p=50) with the MQTT API to cayenne , a battery widget automatically appears, but the data is not displayed correctly. I found out that the display of the charge state in % is converted according to the following function: [displayed_value = -3.14… * given_value + 164,…].
In order to display the desired value of 50%, it is necessary to transmit (50.0-164) / - 3.14 = 36.3.
I have to tell you, it looks like a bug to me. I expect the intent was to allow you to pass the battery level as a simple number and not have to do any conversion on it. I will write this up to get it fixed.
By default the Raspberry Pi does not have a battery management. So, at first you need a battery fuel gauge connected to your RasPi (e.g. over I2C). Here is an example of such a module: LiPo fuel gauge. In the next step you have to determine the charge level with your application via I2C and transfer it to cayenne.
You can use the MQTT-API to transfer the charge level to cayenne. Please read the following doc how to do it: Manually Publishing / Subscribing.