Writing New smartapp

hi
I am new to Smartthings, i tried to write a simple smatapp from


it was simulated but the play button is not working.
also, I tried customer example from IDE and from Github but it gave errors then I tried to solve from

again it was not working.
when I published on my marketplaces( phone app) it gave me errors for inputs.
could someone help me?

Welcome @shabnam!
I can take a look. Can you share the code of your SmartApp, please?
I see that you are working with our Classic platform, let me share with you a simple tutorial to build a simple SmartApp using the current development tools.

Thank you.
this is my code:
/**

  • Energy Saver
  • Copyright 2014 SmartThings
  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.

*/
definition(
name: “Energy Saver”,
namespace: “smartthings”,
author: “SmartThings”,
description: “Turn things off if you’re using too much energy”,
category: “Green Living”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png”,
pausable: true
)

preferences {
section {
input(name: “meter”, type: “capability.powerMeter”, title: “When This Power Meter…”, required: true, multiple: false, description: null)
input(name: “threshold”, type: “number”, title: “Reports Above…”, required: true, description: “in either watts or kw.”)
}
section {
input(name: “switches”, type: “capability.switch”, title: “Turn Off These Switches”, required: true, multiple: true, description: null)
}

}

def installed() {
log.debug “Installed with settings: ${settings}”
initialize()
}

def updated() {
log.debug “Updated with settings: ${settings}”
unsubscribe()
initialize()
}

def initialize() {
subscribe(meter, “power”, meterHandler)
}

def meterHandler(evt) {
def meterValue = evt.value as double
def thresholdValue = threshold as int
if (meterValue > thresholdValue) {
log.debug “{meter} reported energy consumption above {threshold}. Turning of switches.”
switches.off()
}
}
I made app and virtual device in phone app. it is working on simulator but it is not working well, switch just is on. when I wanted to set input in smartapp from phone, I could not make input. it gave errors.
if I do not work with classic platform which platform do you suggest me?

Have you downloaded the latest version of the app?
I published your SmartApp in the IDE and I could install it without errors. The events are also working well for me.

The tools I use are Developer Workspace and Smartapp Node JS SDK, they are included in the tutorial and have their own documentation.
Here’s a sample I made that does something similar:

app.enableEventLogging()  // Log and pretty-print all lifecycle events and responses
    .configureI18n()      // Use files from locales directory for configuration page localization
    .page('mainPage', (context, page, configData) => {
        page.section('sensors', section => {
           section.deviceSetting('sensor').capabilities(['powerMeter']).required(true);
        });
        page.section('preferences', (section) => {
            section.numberSetting('thresholdValue').defaultValue("0");
        });
        page.section('lights', section => {
            section.deviceSetting('lights').capabilities(['switch']).multiple(true).permissions('rx');
        });
    })
    .updated(async (context, updateData) => {
        await context.api.subscriptions.unsubscribeAll();
        return Promise.all([
            context.api.subscriptions.subscribeToDevices(context.config.sensor, 'powerMeter', 'power', 'meterDeviceEventHandler')
        ])
    })
    .subscribedEventHandler('meterDeviceEventHandler', (context, deviceEvent) => {
        let energy = deviceEvent.value;
        let thresholdValue = context.configNumberValue('thresholdValue');
        if(energy>thresholdValue){
            return context.api.devices.sendCommands(context.config.lights, 'switch', 'off');
        }
    })

yes , i downloaded the latest version of app. can you tell me how can make events? i tried some examples but events are not working in all of them.

I created the virtual switch here. It works fine with your SmartApp and receives the ‘off’ event too.
The other option I can think of, is the creation of the device with the powerMeter capability, in my case I use a device handler and update the power attribute manually using the simulator to send this event when I update the device:
sendEvent(name:"power", value:"162", unit:"W")

Check this out, this is my configuration:

metadata {
   definition (name: "powerMeterDevice", author: "nayely") {
   	capability "Power Meter"
   	capability "Refresh"
   }
}

def refresh() {
sendEvent(name:"power", value:"172", unit:"W")
}

def installed() {
   log.trace "Executing 'installed'"
   initialize()
}

def updated() {
   log.trace "Executing 'updated'"
   initialize()
}

private initialize() {
   log.trace "Executing 'initialize'"
   sendEvent(name:"power", value:"172", unit:"W")
}

thanks, I created virtual SW as you and It works , but I have other virtual devices as meter( from its definition in preference section) that its status is unknown. ( it is not working).so, events are not actual value. let me tell you my steps:
1-add new Smartapp( copy and paste code)
2- publish for me
3-check in the phone app
4- creat virtual device in phone app
5-simulate in IDE

My PowerMeter is also a virtual device. The steps I followed are:

  1. Create and publish a device handler using the code I shared
  2. Create the PowerMeter device using that handler.
  3. Install your SmartApp in the mobile app after I self-published it
  4. Open the simulator of the device handler, change the values of the events, and choose to test it on the device I created

thank you so much, I follow your steps.