WebCore Syntax for json Command


#1

1) Give a description of the problem
My piston announces on Google Home that the garage light is on (via Assistant Relay on a Raspberry Pi.) The piston works fine but the json post requires a ‘command, user, and broadcast’. I can define the command text for the ON (The Garage Light is On) but how do you define a second “command” variable for the OFF (The Garage Light is Off)? I’ve tried “command 2” or similar but json doesn’t understand anything but “command”, however I don’t think you can have two variables named the same thing.

2) What is the expected behaviour?
The piston should have a second command that sends the OFF command text (ie what Google Assistant should say when the action happens…The Garage Light is Off)

3) What is happening/not happening?
The ON command works perfectly for the ON but I need help with the second part for the OFF command text. How do you define a second command variable?

4) Post a Green Snapshot of the piston!

Summary

This text will be hidden

5) Attach logs after turning logging level to Full

+0ms ╔Starting piston… (v0.3.110.20191009)
+225ms ║╔Subscribing to devices…
+265ms ║║Subscribing to Garage Light Switch.switch…
+336ms ║╚Finished subscribing (114ms)
+360ms ║Cancelling condition #4’s schedules…
+361ms ║Cancelling condition #1’s schedules…
+371ms ║Comparison (enum) on is (string) on = true (2ms)
+385ms ║Comparison (enum) on is (string) off = false (2ms)
+398ms ╚Piston successfully started (397ms)

#2

I believe your block “IF Switch is off” needs to be moved down a tad…
(Right below “END IF”)

IF Switch is on
    Then Post X
END IF

IF Switch is off
    Then Post Y
END IF

Generally speaking, you want the two IFs independent.


#3

Can you have two variables?

string CommandON = ‘The garage light is on’
string CommandOFF = ‘The garage light is off’

And use two IF’s as @WCmore has suggested.

If you cannot use two variables, then maybe

IF Switch 4 changes to on
Then
  Set variable Command = 'The garage light is ON'
END IF

IF Switch 4 changes to off
Then
  Set variable Command = 'The garage light is OFF'
END IF

#4

Thanks @WCmore and @Pantheon! That did it and it’s working now! Both of your hints put me on the right track. Really appreciate it! Here’s where I ended up:


#5

My apologies… It just dawned on me that your original question was:
“How do you define a second “command” variable?”

I guess I fell down the rabbit hole on that one… :rabbit2:

Thanks @Pantheon for keeping on track! :+1: