How can i update a setpoint with mqtt switch?

I’m still working on my fun vent control stuff and am working toward having little thermostat setups in each room with a display and buttons for changing some things including a setpoint.

The setpoint is changeable in the GUI via the sitemap

Setpoint item=VT_Heating_Setpoint_Nursery label="Target Temperature [%.1f °F]" minValue=65 maxValue=85 step=0.5 visibility=[VT_Heating_Mode_Nursery==2]

item

Number VT_Heating_Setpoint_Nursery "Nursery Setpoint [%.1f °F]"    <degreesf>

How can I modify the setpoint via a MQTT switch?

Switch Nursery_Temp_Up      "Corner A"	{mqtt="<[oh2:/Corner/A/A:state:MAP(up.map)]"}

A/A whatever, i just made it short. Proper names would come when i got it right. currently when i press this button it shows up fine in the events log, im just not sure how to make it modify the setpoint

You will have to use a rule:

rule "received Nursery_Temp _Up"
when
    Item Nursery_Temp _Up received command
then
    if(!VT_Heating_Setpoint_Nursery.state instanceof DecimalType) //if Setpoint Item is uninitialized
        VT_Heating_Setpoint_Nursery.postUpdate(70)  //make a default value
    if (receivedCommand == ON && (VT_Heating_Setpoint_Nursery.state as DecimalType) < 85)
        VT_Heating_Setpoint_Nursery.sendCommand((VT_Heating_Setpoint_Nursery.state as DecimalType) + 0.5)
    else if (receivedCommand == OFF && (VT_Heating_Setpoint_Nursery.state as DecimalType) > 65)
        VT_Heating_Setpoint_Nursery.sendCommand((VT_Heating_Setpoint_Nursery.state as DecimalType) - 0.5)
end
  1. The rule will fire whenever a command is received from the switch.
  2. The rule checks, whether the setpoint item is initialized yet, if not, a default is set,
  3. if the received command is ON and the upper limit is not reached, the setpoint state is increased and sent to the bus.
  4. if the received command is OFF and the lower limit is not reached, the setpoint state is decreased and sent to the bus.

EDIT: added missing opening bracket in code (line 7, right after &&)

wow, thank you for the excellent explanation! i will give this a go soon and report back :smiley:

it’s not working just yet. i think the problem is based around the trigger. i see the item change state in the logs but the rule trigger is based on a command?

2017-03-21 05:22:43.552 [ItemStateChangedEvent     ] - Nursery_Temp_Up changed from OFF to ON
2017-03-21 05:22:45.368 [ItemStateChangedEvent     ] - Nursery_Temp_Up changed from ON to OFF

so i never see the rule fire. does something about the mqtt/item need to be different?

Switch Nursery_Temp_Up      "Corner A"	{mqtt="<[oh2:/Corner/A/A:state:MAP(up.map)]"}

edit changed item from state to command. still having another issue. trying to fix it myself first.

it doesn’t like something about this part

    if(!VT_Heating_Setpoint_Nursery.state instanceof DecimalType) //if Setpoint Item is uninitialized
        VT_Heating_Setpoint_Nursery.postUpdate(70)  //make a default value

if commented out and i set that setpoint via the UI i can then adjust it via the hardware button.

2017-03-21 05:44:43.617 [ItemCommandEvent          ] - Item 'Nursery_Temp_Up' received command ON
2017-03-21 05:44:43.620 [ItemCommandEvent          ] - Item 'VT_Heating_Setpoint_Nursery' received command 74.5
2017-03-21 05:44:43.623 [ItemStateChangedEvent     ] - VT_Heating_Setpoint_Nursery changed from 74.0 to 74.5
2017-03-21 05:44:43.626 [ItemCommandEvent          ] - Item 'FF_Nursery_Heater' received command ON