This project is a library for remote controlling Samsung televisions via a TCP/IP connection.
It currently supports modern (post-2016) TVs with Ethernet or Wi-Fi connectivity. They should be all models with TizenOs.
go get github.com/stephensli/samsung-tv-api@v0.2.1
config := helpers.LoadConfiguration()
c := samsung_tv_api.NewSamsungTvWebSocket(
"IP_ADDRESS_OF_TV",
// configuration token used to authorise with the
// TV. If not set the device will need to be allowed
// via the TV and the token stored for later.
config.Token,
// TLS Port
8002,
// Number of milliseconds between each key press
// when sending large amounts of keys at once.
2,
"REGISTERED_DEVICE_NAME",
// automatically attempt to connect to the TV via
// the rest and websocket api's to set the token.
true)
deviceInfo, deviceInfoErr := c.Rest.GetDeviceInfo()
if deviceInfoErr != nil {
log.Fatal(deviceInfoErr)
}
updatedToken := c.GetToken()
// Use your own provided implementation to store the auth
// token for later use, this stops the TV asking the user
// to confirm the device.
if updatedToken != "" && updatedToken != config.Token {
config.Mac = device.Device.WifiMac
config.Token = c.GetToken()
_ = helpers.SaveConfiguration(&config)
}
if err := c.Websocket.Power(); err != nil {
log.Fatalln(err)
}
if err := c.Websocket.OpenBrowser("https://www.google.com"); err != nil {
log.Fatalln(err)
}
if apps, err := c.Websocket.GetApplicationsList(); err == nil {
firstApp := apps.Data.Applications[0]
fmt.Println(fmt.Sprintf("application name: %s", firstApp.Name))
}
if apps, err := c.Websocket.GetApplicationsList(); err == nil {
firstApp := apps.Data.Applications[0]
appDetails, _ := c.Rest.GetApplicationStatus(firstApp.AppID)
byteData, _ := json.MarshalIndent(appDetails, " ", "\t")
fmt.Println(string(byteData))
}
if _, err := c.Rest.CloseApplication(AppID); err != nil {
fmt.Println(err)
}
if _, err := c.Rest.InstallApplication(AppID); err != nil {
fmt.Println(err)
}
if deviceDetails, err := c.Rest.GetDeviceInfo(); err == nil {
byteData, _ := json.MarshalIndent(deviceDetails, "", "\t")
fmt.Println(string(byteData))
}
if err := samsung_tv_api.WakeOnLan(config.Mac); err == nil {
c.Websocket.Power()
}
* GetDeviceInfo() (DeviceResponse, error)
* GetApplicationStatus(appId string) (ApplicationResponse, error)
* RunApplication(appId string) (interface{}, error)
* CloseApplication(appId string) (interface{}, error)
* InstallApplication(appId string) (interface{}, error)
* GetApplicationList() (ApplicationResopnse, error)
* RunApplication(appId, appType, metaTag string) error
* SendClick(key string) error
* SendKey(key string, times int, cmd string) error
* HoldKey(key string, seconds int) error
* ChangeChannel(channel string) error
* MoveCursor(x, y, duration int) error
* OpenBrowser(url string) error
* Power() error
* PowerOff() error
* PowerOn() error
* Disconnect() error
* GetCurrentVolume() (int, error)
* SetVolume(volume int) error
* GetCurrentMuteStatus() (bool, error)
* SetCurrentMedia(url string) error
* PlayCurrentMedia() error
* WakeOnLan(mac string) error
List of support TV models. https://developer.samsung.com/smarttv/develop/extension-libraries/smart-view-sdk/supported-device/supported-tvs.html
2017 : M5500 and above
2016 : K4300, K5300 and above
2015 : J5500 and above (except J6203)
2014 : H4500, H5500 and above (except H6003/H6103/H6153/H6201/H6203)
Supported TV models may vary by region.
For complete list https://developer.samsung.com/smarttv/develop/specifications/tv-model-groups.html