Hello,
if it is 0:00 I want to set the correct month number to $variable_number_month_actual how can I perform this by rule?
-
some help for setting variable
-
@temp create a new shell device. As command do:
date +"%m"
Then as rule
WHEN its 00:00 THEN set $yourvariable to $your-shell-sensor.attributename
-
@Gleno0h I have done it via a shell device but is it possible without?( only with a rule and a variable) only to handle it with minimal effort (and for my interest). As a hint: I have a shell device with the system date which display by %d-%m-%Y, is it possible to set a variable by rule with some regular expressions?
I think sth about
.... Set $variable to execute "echo date +\"%m\" "
Some more background I want tfor my energy and gas calculation define the day/month/year change and execute the calculation at 0:00 directly
-
@temp yeah it would be kinda like that. What you are looking for is:
curl --silent -X POST --header "Content-Type:application/json" --user "xxxx:xxxx" --data '{"type": "value", "valueOrExpression": MONTH}' http://localhost/api/variables/YourVariable
If you dont mind to use a script i can help you out.
Then it would just be
WHEN it is 00:00 THEN execute " yourscript.sh"
-
when its 0:00 then set $variable_number_month_actual to date(\"M\")
If you edit the rule with the Rule Editor you don’t need to escape the quotes. See screenshot below.
See
date()
function at String Expressions and String Functions for Variables & Rules"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
@mwittig Jeez. I was using a system time to get the date and you gave a easy solutions lol thanks.
-
@mwittig Thanks that’s the best and easiest solution
-
Hi,
you can also use a variable itself to get the actual month or date. I didn’t know that for a long time…
Perhaps this can also be an option for you.@sirhc said in Date expression in VariableDevice:
Hey, i’m using a Variable Device to get the current date:
{ "variables": [ { "name": "Heute", "expression": "\"{date(\"DD.MM.YYYY\")} \"", "type": "string" } ], "xAttributeOptions": [], "id": "datum", "name": "Datum", "class": "VariablesDevice" }
What are the possible options for formatting date? I’d like to get the name of the day (Mon / Montag / Monday, would be ok…). I tried “E” and “EE”, but that didn’t work…
Any solution for this?Thanks a lot
Greetings -
@Fabian said in some help for setting variable:
you can also use a variable itself to get the actual month or date
But as far as I know this variable is not automatically updated.
-
@Fabian said in some help for setting variable:
What are the possible options for formatting date? I’d like to get the name of the day (Mon / Montag / Monday, would be ok…). I tried “E” and “EE”, but that didn’t work…
Any solution for this?See https://forum.pimatic.org/topic/2958/string-expressions-and-string-functions-for-variables-rules
@Heizelmann is right, btw: If you you use the date function as part of a variable it will only be updated on pimatic restart. It would make perfectly sense to me to evaluate the expression each time the variable is read, but it is not implemented this way"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
Okay, I didn’t know that also.
-
@mwittig said in some help for setting variable:
If you use the date function as part of a variable it will only be updated on pimatic restart.@mwittig Can you please add this hint to the how-to-thread. (It is also updated when saving the variable from the device editor.)