Hi,
I want to show information from mqtt based on the plugin developed by @fvanroie. It works well but I would like to format a bit the provided infos. Based on the code below, it shows the current consumption with 1 decimal whilst I want to show no decimal. I tried to add "NumOfDecimals=0" but it does not change anything...
Any idea of my problem/mistake ?
Thanks for help.
[Rainmeter]
Update=10000
[Style1]
AntiAlias=1
FontColor=255,255,255
;FontColor=FFFFFF
FontFace=Segoe UI
FontSize=20
[mqttServer]
Measure=Plugin
Plugin=MqttClient
;Connection Details
Server=192.168.1.126
Port=1883
Username=MYUSERNAME
Password=MYPWD
;Update the meter when the client connects:
OnConnect=[!UpdateMeter mqttOutput][!Redraw]
;Update the meter as soon as a message arrives:
OnMessage=[!UpdateMeter mqttOutput][!Redraw]
;Subscribe to kostal/Grid_P
[mqttTopic1]
Measure=Plugin
Plugin=MqttClient
ParentName=mqttServer
Topic=kostal/Grid_P
;Show Server connection state and topics
[mqttOutput]
Meter=String
X=5
Y=5
W=350
H=150
MeterStyle=Style1
Text=Consommation: [mqttTopic1]W
DynamicVariables=1
NumOfDecimals=0
one1tick wrote: ↑March 19th, 2022, 8:01 pm
I want to show information from mqtt based on the plugin developed by @fvanroie. It works well but I would like to format a bit the provided infos. Based on the code below, it shows the current consumption with 1 decimal whilst I want to show no decimal. I tried to add "NumOfDecimals=0" but it does not change anything...
Any idea of my problem/mistake ?
I don't use the MqttClient plugin, so can't test, however I believe you should either add a MeasureName=mqttTopic1 option to the [mqttOutput] meter and replace the existing Text option with Text=Consommation: %1W, in which case the NumOfDecimals option will work, or to replace the Text option of the same [mqttOutput] meter with Text=Consommation: [mqttTopic1:0]W.
balala wrote: ↑March 19th, 2022, 8:12 pm
I don't use the MqttClient plugin, so can't test, however I believe you should either add a MeasureName=mqttTopic1 option to the [mqttOutput] meter and replace the existing Text option with Text=Consommation: %1W, in which case the NumOfDecimals option will work, or to replace the Text option of the same [mqttOutput] meter with Text=Consommation: [mqttTopic1:0]W.
Thanks for your help but none of your proposals work.
one1tick wrote: ↑March 19th, 2022, 9:08 pm
Thanks for your help but none of your proposals work.
Ok, but what the [mqttTopic1] measure is returning? I mean what exactly is it returning?
You also could try adding the following options to the [mqttTopic1] measure:
balala wrote: ↑March 19th, 2022, 9:19 pm
Ok, but what the [mqttTopic1] measure is returning? I mean what exactly is it returning?
Thanks again for your apprecited help. The MQTT topic is returning the current consumption of my house in W, ie 1200.4 but I guess it is a string not numeric (float). Is there any way to convert string to float ?
It works with the regex trick, thanks for this.
If I want to go one step further and show consumption in kW (not in W), I have to divide by 1000. I tried to add this and use [Convert_kW] instead of
[mqttTopic1] in [mqttOutput]:
one1tick wrote: ↑March 20th, 2022, 7:33 am
But it does not work... May because this is string not numeric. Thanks
Theoretically even if the [mqttTopic1] measure is returning a string which is a number, there is no need to use it as a section variable in the Formula option of a Calc measure, but from my experience I can say that sometimes it is. Don't know if it's the case this time, but might be. So you could try either to replace the Formula option with Formula=mqttTopic1/1000, or if it doesn't work, to add a DynamicVariables=1 option to the [Convert_kW] measure.
EDIT: the red 0 in the above formula is a fix of an error I made when posted my reply.
balala wrote: ↑March 20th, 2022, 9:54 am
Theoretically even if the [mqttTopic1] measure is returning a string which is a number, there is no need to use it as a section variable in the Formula option of a Calc measure, but from my experience I can say that sometimes it is. Don't know if it's the case this time, but might be. So you could try either to replace the Formula option with Formula=mqttTopic1/100, or if it doesn1t work, to add a DynamicVariables=1 option to the [Convert_kW] measure.
Thanks again, it works perfectly but not sure I understand everything... the logic of rainmeter looks weird to me.
I have added another regex found on the forum to better format the consumption in W. I added to your regex to remove the decimals.
It gives Consumption : 1'234 W instead of raw Consumption : 1234.0 W
one1tick wrote: ↑March 20th, 2022, 11:25 am
Thanks again, it works perfectly but not sure I understand everything... the logic of rainmeter looks weird to me.
I have added another regex found on the forum to better format the consumption in W. I added to your regex to remove the decimals.
It gives Consumption : 1'234 W instead of raw Consumption : 1234.0 W
Next step is to show text based on condition but I will open a new thread if I am not able to find how to do it.
Thanks again @balala
You can't just add regexes found on the forum for probably different purposes and expect them to work in some random combination. The "\d{1,3}(?=(\d{3})+\.)":"\0'", makes no sense in your case. Just stick to balala's regex, or explain how you want to "better format the consumption in W", so we can help. All those characters in regex have a meaning, and while they do exactly what they're suppose to do, what they do might not be what you actually want.
one1tick wrote: ↑March 20th, 2022, 11:25 am
I have added another regex found on the forum to better format the consumption in W. I added to your regex to remove the decimals.
It gives Consumption : 1'234 W instead of raw Consumption : 1234.0 W
See Yincognito's reply and explain us please what the "better format the consumption in W" does mean, however in meantime there might be another approach as well.
Instead of using a Calc measure to convert the consumption to kW, I probably would try to ask the String meter to do this conversion. This can be done by adding an AutoScale=2 option. Here is my example:
[mqttServer]
Measure=Plugin
Plugin=MqttClient
;Connection Details
Server=192.168.1.126
Port=1883
Username=MYUSERNAME
Password=MYPWD
;Update the meter when the client connects:
OnConnect=[!UpdateMeter mqttOutput][!Redraw]
;Update the meter as soon as a message arrives:
OnMessage=[!UpdateMeter mqttOutput][!Redraw]
;Subscribe to kostal/Grid_P
[mqttTopic1]
Measure=Plugin
Plugin=MqttClient
ParentName=mqttServer
Topic=kostal/Grid_P
;Show Server connection state and topics
[mqttOutput]
Meter=String
MeasureName=mqttTopic1
X=5
Y=5
W=350
H=150
MeterStyle=Style1
AutoScale=2
Text=Consommation: %1W
DynamicVariables=1
NumOfDecimals=0
See the added MeasureName and AutoScale options as well as the replaced Text option of the [mqttOutput] meter.
With the AutoScale=2 option, the meter will show the consumption into W if it is below 1000 W = 1 kW, or in kW, if it is above.
Additional note:Update=10000 in the [Rainmeter] section is definitely not a good approach. It means you get the skin updated once on every 10 seconds. To can use the skin to see the real consumption, I'd tend to recommend to use the default Update=1000.
Yincognito wrote: ↑March 20th, 2022, 2:12 pm
You can't just add regexes found on the forum for probably different purposes and expect them to work in some random combination. The "\d{1,3}(?=(\d{3})+\.)":"\0'", makes no sense in your case. Just stick to balala's regex, or explain how you want to "better format the consumption in W", so we can help. All those characters in regex have a meaning, and while they do exactly what they're suppose to do, what they do might not be what you actually want.
Thanks @Yincognito appreciate your comment. However the regex I have found is not a "random" one found on the forum and I don't think it makes no sense in my case. Maybe there is a more efficient one and I would be happy if you have a better way to convert the raw data coming from mqtt.
I want to show the the consumption of my home and the power I buy from the grid (or the power I sell from my pv production) without decimals and with thousand separators.
Examples:
10234.6 => 10'234W
-1234.7 => -1'234W
Substitute="\d{1,3}(?=(\d{3})+\.)":"\0'","(\d*)\.(\d*)":"\1" is doing what I want but again I would be happy if there is a better way to achieve my need.