Setting a variable in an expression depending on current thermostat mode?


#1

1) Give a description of the problem
I’m trying to set a variable depending on the current thermostat mode, but the expression is not showing anything in the evaluation screen so I’m not sure what I’m doing wrong?

2) What is the expected behaviour?
If thermostat mode == heat then set command to “x” if thermostat mode == cool then set command to “y”

3) What is happening/not happening?
the command variable is not setting to anything
Edit: trying to add photo, not sure this works?


#2

It would be much easier to review if you embedded your picture in your message rather than linking to it. Just use the 38%20PM icon in the edit bar.


#3

I suggest rather than just using it in the set heat point command, create integer variables and assign values using these expressions. Then you can see exactly what it is doing after it runs and just use the variables in your heat/cool commands. Will make debugging easier.


#4

I’m not sure I follow your last advice, its the last expression line in the piston I need help with, its not sure I’ll use it but atleast I want to learn if its possible. Best regards,
Dixon


#5

OK, I was looking at the beginning. Again, hard to review since you didn’t include the piston directly in your post. Looks like you are having trouble with this expression:

To start with, your first ‘test’ in the ternary operator is just a string so it will always be true. Then you have a logical test but no ‘?’ following so your syntax is all messed up. If you copy and paste the actual expression here I could look at it some more.


#6

The general syntax for Ternary operators is:

( c ? t : f )

This evaluates c as a boolean, then if that evaluation is true, returns t , otherwise returns f.


So, if you need to layer, IF A, then X, else if B then Y, else Z, try this:

((A) ? "X" : ((B) ? "Y" : "Z"))

(the final else is mandatory)


Note, I cannot see your external image in the first post, but from the image that @guxdude shared,

  • your “vardagsrum” strings should be X, Y & Z
  • your Thermostat computations should be A & B

#7

Hi, I’ve tried to add the photo as you said in your above post, hope this made it better.

The expression I tried to write up is as follow and I’m no programmer and I dont really understand the syntax but I’ve learnt by trial and error up till now and now I can’t figure this out, haha.

(“vardagsrum värme” ? ([Thermostat : thermostatMode] == “Heat”) : “vardagsrum kyla” ? ([Thermostat : thermostatMode] == “Cool”

Thank you kindly for helping me out!


#8

Hi, thank you for jumping in and helping out.
Would it be something like this?

(([Thermostat : thermostatMode] == “heat”) ? “X” : (([Thermostat : thermostatMode] == “cool”) ? “Y” : (([Thermostat : thermostatMode] == “auto”) ? “Z” : (([Thermostat : thermostatMode] == “off”) ? “C” : “C”))))


#9

You have the syntax backwards. Here is what I think you want:

( ([Thermostat : thermostatMode] == “Heat”)? “vardagsrum värme” : 
             ( ([Thermostat : thermostatMode] == “Cool”)? “vardagsrum kyla” : "vardagsrum okänd") )

this will result in:
Heat -> vardagsrum värme
Cool -> vardagsrum kyla
Neither -> vardagsrum okänd

You can replace “vardagsrum okänd” with additional options following the same pattern.

Hope this helps.


#10

This advice here is to essentially switch places with integer and the expression?

Sounds like a nice plan, thank you!


#11

thank you kindly for jumping in and helping out…

would you perhaps know of a good way of handling a thermostat mode change? like… I think I got the heating and cooling in a good spot but in between I want to add “ventilation” essentially just the fan of the heat pump but that conflicts with the off command… any ideas?


#12

Does the thermostat have a “Fan” mode? If there is no indication in the heat pump site, not sure how to indicate that unless it is a transition and occurs for a known period of time. Then maybe you could set a timer at the start of the mode transition.


#13

Hi, it does have a “Ventilation” mode, since I don’t like to use the “auto cool / heat” function I’ve put up the ventilation to the “auto” function instead in the virtual thermostat DH…

I’ve been wanting to try a timer alongside the off function but I have no clue how to trigger it to activate the ventilation function every 30mins for say 15mins when the thermostat is set to off or something similar… just a shame my heatpumps doesnt integrate at all into smartthings, I’m not good at this at all… haha…

If thermostat is off
if thermostat stays off for 30mins
then
set thermostat to auto…

Here, the thermostat would lose the timer for the off function and I don’t know how to set a timer for the auto mode and then go back to being off?


#14

You could create a separate piston with something like:

While [thermostat:thermostatMode]!="Heat" && [thermostat:thermostatMode]!="Cool"
   with thermostat
       set to ventilation
       wait 15 minutes
       set to off
       wait 15 minutes
   end with
end while

This would cycle 15 minutes ventilation then 15 minutes off until either heat or cool is commanded.


#15

Oh, this sounds like a great way to do it!
!= is this not equal to?

Is there a reason for this is on a separate piston? and could I use 3 of them in the same piston so I have one piston controlling this function for all my 3 heat pumps?

Thank you kindly for the information and taking your time to help out, I appreciate it!
Best regards,
d


#16

Generally speaking, it is wise to keep timers or loops separate from spam pistons like you have above. (which could easily trigger dozens of times each hour)

The temperature change (on line 69) creates endless triggers which can cause issues with loops.


Also, be aware that when temp changes, and the piston fires, it may change the thermostat mode, which will execute the piston again from the top. This would encourage me to combine those two clusters of commands into one. IE:

IF Thermostat temp changes
Then
    IF temp is less than X
    Then
        Set thermostat mode to whatever
        Set variable {command} to whatever
    END IF
    IF temp is greater than Y
    Then
        Set thermostat mode to whatever
        Set variable {command} to whatever
    END IF
    IF temp is inside of range X & Y
    Then
        Set thermostat mode to off
        Set variable {command} to whatever
    END IF
    Execute piston with arguments
END IF

Notice the “Execute piston” command is inside the top IF, but outside all of the others.
(since all scenarios send this command)

This reduces clutter, streamlines execution, and prevents double triggers back to back.


#17

Yes, and ‘&&’ is logical ‘and’.


#18

Hey, that was the original form of this piston but then I wanted to be able to change the thermostat mode manually with the virtual thermostat smartapp as I couldnt figure out how to plan the heating / cooling well enough and even now Im more or less changing mode manually once an hour because here we can have 20c indoors and super comfortable and at times 24c and cool its very odd, depends mostly on the outdoor temperature I believe and I dont know scripting or using webcore well enough to make it “manual free”.

And while I dont want endless triggering I cant think of a better way to do it, lack of experience and knowledge.

Thank you kindly for your advice and input, Ill try incooperate any advice I get that I can understand how to do, i appreciate it!


#19

Perhaps if you could adjust X & Y in @WCmore’s suggestion would be better than manually turning on/off the cooling/heating? Might be other ways but you could try this for controlling global variables:


#20

Hi, great suggestion! Ill look into it more tomorrow as with 3 kids I got more time to write / read here on thé fly than to actually sit down and try things :rofl:

I did try to adjust the X and Y but seeing as how the sensible? Heat feels different depending how the weather outside is I dont want to adjust too much and while I could adjust it better the delta would be less and instead of helping it becomes a auto mode, cooling and heating in cycles which sucks… sorru english isnt my native tongue itd not easy to form sentances… i dont want to give up manual mode, is there no different way to make it so its not triggering in a loop?

Best of both worlds?
Thank you for linking the DH, I saved it and will medd With it tomorrlw :grin: