Wrong port number
Sorry
The goal is to switch in a switch if a defined time and date is reached. I like to send the time and date info via curl to the variable and check that variable against current time. Which format do I need to send?
[Solved] Bash command to update a variable
Wrong port number
Sorry
The goal is to switch in a switch if a defined time and date is reached. I like to send the time and date info via curl to the variable and check that variable against current time. Which format do I need to send?
@temp this is already build in? WHEN its 22:00 THEN …?
And what do you mean by wrong port number? You have it fixed because you used the wrong port?
Also, what time do you want to send?
System time or just “17:00” ?
"valueOrExpression": "17:00"
Yes, i fixed it with the correct port number.
The variable has then the value 2.10.2017-17:00:00 and the rule shoud check if it is 2.10.2017-17:00:00 and switch on the wall plug.
@temp idk what you exactly want but ill give you a hint.
Lets define the time first:
systemtime=$(date '+%X')
You can now manipulate how you want to output the time. Experiment with it.
Then, to use it with curl:
curl --silent -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$systemtime'"}' --user "test:test" http://IPADDRESS/api/variables/your_variable > /dev/null
So, paste this in your bash:
systemtime=$(date '+%X')
curl --silent -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$systemtime'"}' --user "test:test" http://IPADDRESS/api/variables/your_variable > /dev/null
This will write 11:20:10 to your variable.
Want only the current day?
Use date '+%A'
want day and time?
Use ```date ‘+%A %X’``
Or simply use
systemtime="2.10.2017-17:00:00"
if you want to use a fixed time
Hello,
whats wrong?
stop_timestamp=1494910730
pi@smarthome:~ $ t=`date -d@$stop_timestamp
+%d-%m-%Y\ %H:%M`
pi@smarthome:~ $
curl -X PATCH --header "Content-
Type:application/json" --data '{"type": "value",
"valueOrExpression": "'$t'"}' --user "a:a"
http://smarthome:5001/api/variables/variable_string_today
curl: (3) [globbing] unmatched close brace/bracket in column 7
SyntaxError: Unexpected end of input
at Object.parse (native)
at parse (/home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/lib/types/json.js:88:17)
at /home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/lib/read.js:116:18
at invokeCallback (/home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/node_modules/raw-
body/index.js:262:16)
at done (/home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
at IncomingMessage.onEnd (/home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/node_modules/raw-
body/index.js:307:7)
at emitNone (events.js:67:13)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)pi@smarthome:~ $
@temp i dont know. Post your bash script?
I also see you have date in ’ ’ tags, thats wrong. I also see $ t. Why is there a space? Should be $t.
Post your bash pls
Hello,
t=`date -d@$timestamp +%d-%m-%Y\ %H:%M`
curl -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$t'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_today
@temp Looks like the command spans multiple lines including line breaks. Note, line breaks are not supported and need to be escaped with an \
at the end of the line, e.g.
curl -X PATCH --header "Content- \
Type:application/json" --data '{"type": "value",\
"valueOrExpression": "'$t'"}' --user "a:a" \
http://smarthome:5001/api/variables/variable_string_today
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
@temp what @mwittig said and following line doesnt make sense to me…
t=`date -d@$timestamp +%d-%m-%Y\ %H:%M`
t=date -d ‘+%d-%m-%Y\ %H:%M’ makes more sense to me, except for -d. Thats invalid… Why do you have @$timestamp?
Also why the \ ?
Please let me know what you want and ill post a bash code you can copy and use.
#!/bin/sh
#
echo z > /dev/serial/by-id/usb-Atric_Development_GbR_Atric_IR-Wakeup_USB-if00
# bootup system 60 sec. before timer
safe_margin=60
# modyfy if different location for tvheadend dvr/log path
cd /storage/.kodi/userdata/addon_data/service.tvheadend42/dvr/log/
start_timestamp=0
stop_timestamp=0
current_timestamp=`date +"%s"`
for i in $( ls ); do
tmp_start="$(grep -o '"start": [0-9]*' "$i" | head -n 1 | grep -o '[0-9]*')"
tmp_stop="$(grep -o '"stop": [0-9]*' "$i" | head -n 1 | grep -o '[0-9]*')"
if [ "$tmp_stop" -gt "$current_timestamp" -a "$tmp_start" -gt "$current_timestamp" ]; then
if [ "$start_timestamp" -eq 0 -o "$tmp_start" -lt "$start_timestamp" ]; then
start_timestamp=$tmp_start
stop_timestamp=$tmp_stop
fi
fi
done
wake_start_timestamp=$((start_timestamp-safe_margin))
if [ "$wake_start_timestamp" -gt 0 ]; then
wake_start_time=`date -d@$wake_start_timestamp +%y%m%d%H%M`
actual_date=`date +"%y%m%d%H%M%S"`
time_correction=0
time_command=TSACS
complete_command=$time_command$actual_date$time_correction
#echo $actual_date
echo $complete_command > /dev/serial/by-id/usb-Atric_Development_GbR_Atric_IR-Wakeup_USB-if00
#echo $wake_start_time
waketime_command=WSACS
complete_command=$waketime_command$wake_start_time
echo $complete_command > /dev/serial/by-id/usb-Atric_Development_GbR_Atric_IR-Wakeup_USB-if00
wake_start_timestamp=$((start_timestamp-safe_margin-safe_margin))
wake_start_time=`date -d@$wake_start_timestamp +%d-%m-%Y\ %H:%M`
curl -X PATCH --silent --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$wake_start'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_htpc_startrecordingtime >/dev/null
wake_stop_time=`date -d@$stop_timestamp +%d-%m-%Y\ %H:%M`
curl -X PATCH --silent --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$wake_stop'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_htpc_startrecordingtime >/dev/null
fi
echo z > /dev/serial/by-id/usb-Atric_Development_GbR_Atric_IR-Wakeup_USB-if00
and the files looks like:
{
"enabled": true,
"start": 1493842500,
"start_extra": 0,
"stop": 1493844300,
"stop_extra": 0,
"channel": "d3751afe7fb68fb4a19fb1d482b52787",
"channelname": "Das Erste HD",
"title": {
"ger": "Tagesthemen"
},
"subtitle": {
"ger": "mit Wetter"
},
"description": {
"ger": "Themen u.a.:\n* Vor der Wahl: TV-Duell in Frankreich\n* Unter Druck: Eingeschüchterte Journalisten\n* Auf der Hut: Cybercrime bedroht Deutschland\n* Kommentar von Thomas Baumann (MDR) zum Tag der Pressefreiheit\n\nModeration: Caren Miosga\nProduziert in H"
},
"pri": 2,
"retention": 2147483646,
"removal": 92,
"playposition": 0,
"playcount": 0,
"config_name": "8d0f5b7ae354d956d7fe5db25f5d0d24",
"owner": "kodi",
"creator": "kodi",
"errorcode": 103,
"errors": 1,
"data_errors": 0,
"dvb_eid": 22433,
"noresched": false,
"norerecord": false,
"fileremoved": 0,
"autorec": "",
"timerec": "",
"parent": "",
"child": "",
"content_type": 2,
"broadcast": 37561,
"files": [
{
"filename": "/storage/recordings/Tagesthemen/Tagesthemen-Das Erste HD2017-05-0322-15.ts",
"info": [
{
"type": "H264",
"width": 1280,
"height": 720,
"duration": 1800,
"aspect_num": 0,
"aspect_den": 0
},
{
"type": "MPEG2AUDIO",
"language": "ger",
"audio_type": 0
},
{
"type": "MPEG2AUDIO",
"language": "mis",
"audio_type": 0
},
{
"type": "AC3",
"language": "ger",
"audio_type": 0
},
{
"type": "TELETEXT"
},
{
"type": "DVBSUB",
"language": "ger",
"composition_id": 1,
"ancillary_id": 1
}
],
"start": 1493842500,
"stop": 1493844164
}
]
}
everything is fine if I use
wake_start_time=`date -d@$wake_start_timestamp +%d-%m-%Y/%H:%M`
instead of
wake_start_time=`date -d@$wake_start_timestamp +%d-%m-%Y\ %H:%M`
@temp im sorry i still dont know what you want. Did you solve it or not?
I get this error
SyntaxError: Unexpected end of input
at Object.parse (native)
at parse (/home/pi/pimatic- app/node_modules/pimatic/node_modules/body-parser/lib/types/json.js:88:17)
at /home/pi/pimatic- app/node_modules/pimatic/node_modules/body- parser/lib/read.js:116:18
at invokeCallback (/home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/node_modules/raw-
body/index.js:262:16)
at done (/home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
at IncomingMessage.onEnd (/home/pi/pimatic-app/node_modules/pimatic/node_modules/body-parser/node_modules/raw-
body/index.js:307:7)
at emitNone (events.js:67:13)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
If I am using this line for defining the Start time
wake_start_time=`date -d@$wake_start_timestamp +%d-%m-%Y\ %H:%M`
When I use this line
wake_start_time=`date -d@$wake_start_timestamp +%d-%m-%Y/%H:%M`
Everything is good
But i like to see in the pimatic GUI the format
16-05-2017 17:30
And not
16-05-2017/17:30
@temp well, you define it yourself in your date command…
wake_start_time=`date -d@$wake_start_timestamp +%d-%m-%Y/%H:%M`
But you want:
wake_start_time=`date -d@$wake_start_timestamp +%d-%m-%Y %H:%M`
As you can see, i only removed the /…
NSA@raspberrypi:~# date '+%d-%m-%Y/%H:%M'
16-05-2017/23:46
NSA@raspberrypi:~# date '+%d-%m-%Y %H:%M'
16-05-2017 23:46
@Gleno0h said in Bash command to update a variable:
@temp what @mwittig said and following line doesnt make sense to me…
My comment was referring to the following error and the command snippets @temp sent in post 11, but I have been misled by the strange formatting he used in his post.
curl: (3) [globbing] unmatched close brace/bracket in column 7
SyntaxError: Unexpected end of input
@temp Actually, I think the problem is bad quotation. The following modified command sequence based on post 11 works for me. See also 2nd post at https://superuser.com/questions/835587/how-to-include-environment-variable-in-bash-line-curl for details.
pi@raspi3:~ $ stop_timestamp=1494910730
# Space in the date format string below must be escaped
pi@raspi3:~ $ t=`date -d@$stop_timestamp +%d-%m-%Y\ %H:%M`
# Single quotes around shell variables must be quoted!
pi@raspi3:~ $ curl -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'"$t"'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_today
{"variable":{"name":"variable_string_today","readonly":false,"type":"value","value":"16-05-2017 06:58","unit":""},"success":true}
EDIT: @temp In your example the inner double quotes for the variable are missing which expands to the following as the shell with quote the space character for you.... "valueOrExpression": "16-05-2017' '06:58"
. That’s causing the syntax error. You can easily trace that yourself by setting set -x
in your shell.
pi@raspi3:~ $ set -x
pi@raspi3:~ $ curl -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'"$t"'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_today
+ curl -X PATCH --header Content-Type:application/json --data '{"type": "value", "valueOrExpression": "16-05-2017 06:58"}' --user a:a http://smarthome:5001/api/variables/variable_string_today
{"variable":{"name":"variable_string_today","readonly":false,"type":"value","value":"16-05-2017 06:58","unit":""},"success":true}pi@raspi3:~ $
pi@raspi3:~ $
pi@raspi3:~ $ curl -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$t'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_today
+ curl -X PATCH --header Content-Type:application/json --data '{"type": "value", "valueOrExpression": "16-05-2017' '06:58"}' --user a:a http://smarthome:5001/api/variables/variable_string_today
curl: (3) [globbing] unmatched close brace/bracket in column 7
SyntaxError: Unexpected end of input
at Object.parse (native)
at parse (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/lib/types/json.js:88:17)
at /home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/lib/read.js:116:18
at invokeCallback (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:262:16)
at done (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
at IncomingMessage.onEnd (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:307:7)
at emitNone (events.js:67:13)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:923:12)
at nextTickCallbackWith2Args (node.js:458:9)
at process._tickDomainCallback (node.js:413:17)pi@raspi3:~ $
Use set +x
to switch off the trace
Hope, this helps
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
@Gleno0h said in Bash command to update a variable:
wake_start_time=
date -d@$wake_start_timestamp +%d-%m-%Y %H:%M
This wont’t work. The space must be escaped with a backslash \
. Otherwise you will get the syntax error in the curl command. It won’t work from the command line, either.
pi@raspi3:~ $ wake_start_timestamp=1494910730
pi@raspi3:~ $ date -d@$wake_start_timestamp +%d-%m-%Y %H:%M
date: zusätzlicher Operand „%H:%M“
„date --help“ liefert weitere Informationen.
pi@raspi3:~ $ date -d@$wake_start_timestamp +%d-%m-%Y\ %H:%M
16-05-2017 06:58
EDIT: Alternatively, you can do the following which is more or less what you suggested
pi@raspi3:~ $ date -d@$wake_start_timestamp '+%d-%m-%Y %H:%M'
16-05-2017 06:58
As you can see, i only removed the /…
No, you also added single quotes around the format string.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
@temp Any progress on this?
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
@mwittig said in Bash command to update a variable:
@Gleno0h said in Bash command to update a variable:
@temp what @mwittig said and following line doesnt make sense to me…
My comment was referring to the following error and the command snippets @temp sent in post 11, but I have been misled by the strange formatting he used in his post.
curl: (3) [globbing] unmatched close brace/bracket in column 7 SyntaxError: Unexpected end of input
@temp Actually, I think the problem is bad quotation. The following modified command sequence based on post 11 works for me. See also 2nd post at https://superuser.com/questions/835587/how-to-include-environment-variable-in-bash-line-curl for details.
pi@raspi3:~ $ stop_timestamp=1494910730 # Space in the date format string below must be escaped pi@raspi3:~ $ t=`date -d@$stop_timestamp +%d-%m-%Y\ %H:%M` # Single quotes around shell variables must be quoted! pi@raspi3:~ $ curl -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'"$t"'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_today {"variable":{"name":"variable_string_today","readonly":false,"type":"value","value":"16-05-2017 06:58","unit":""},"success":true}
EDIT: @temp In your example the inner double quotes for the variable are missing which expands to the following as the shell with quote the space character for you
.... "valueOrExpression": "16-05-2017' '06:58"
. That’s causing the syntax error. You can easily trace that yourself by settingset -x
in your shell.pi@raspi3:~ $ set -x pi@raspi3:~ $ curl -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'"$t"'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_today + curl -X PATCH --header Content-Type:application/json --data '{"type": "value", "valueOrExpression": "16-05-2017 06:58"}' --user a:a http://smarthome:5001/api/variables/variable_string_today {"variable":{"name":"variable_string_today","readonly":false,"type":"value","value":"16-05-2017 06:58","unit":""},"success":true}pi@raspi3:~ $ pi@raspi3:~ $ pi@raspi3:~ $ curl -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$t'"}' --user "a:a" http://smarthome:5001/api/variables/variable_string_today + curl -X PATCH --header Content-Type:application/json --data '{"type": "value", "valueOrExpression": "16-05-2017' '06:58"}' --user a:a http://smarthome:5001/api/variables/variable_string_today curl: (3) [globbing] unmatched close brace/bracket in column 7 SyntaxError: Unexpected end of input at Object.parse (native) at parse (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/lib/types/json.js:88:17) at /home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/lib/read.js:116:18 at invokeCallback (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:262:16) at done (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:251:7) at IncomingMessage.onEnd (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/body-parser/node_modules/raw-body/index.js:307:7) at emitNone (events.js:67:13) at IncomingMessage.emit (events.js:166:7) at endReadableNT (_stream_readable.js:923:12) at nextTickCallbackWith2Args (node.js:458:9) at process._tickDomainCallback (node.js:413:17)pi@raspi3:~ $
Use
set +x
to switch off the trace
Hope, this helps
–>Solved Thanks to everyone
–>Next topic/question to solve everything https://forum.pimatic.org/topic/3047/kodi-shutdown-command